REST APIs are commonly used to expose Machine Learning (ML) models to other services. This folder contains an example REST API created using Flask to expose the YOLOv5s model from PyTorch Hub.
Install requirements.txt in a Python>=3.7.0 environment, including PyTorch>=1.7.
$ pip install -r requirements.txt
After Flask installation run:
$ export FLASK_ENV=development && flask run
or
$ python app.py
To use custom model:
$ python app.py --model best.pt
Use GUI to upload and view resut: Go to http://localhost:5000
Use curl to perform a request (Recommended: Git Bash):
$ curl -X POST -F image=@images/cat.jpg 'http://localhost:5000/v1/object-detection/yolov5s'
The model inference results are returned as a JSON response:
[{"xmin":384.2033081055,"ymin":35.8358840942,"xmax":823.404296875,"ymax":409.2363891602,"confidence":0.8502380848,"class":0,"name":"cat"}]
- YOLOv5 Flask REST API
- Yolov5 Flask @jzhang533
- Load YOLOv5 from PyTorch Hub
- Pytorch Flask API Heroku @avinassh
Note: The best.pt provided is self-trained yolov5 model on cats and dogs dataset.