Files
SetParams
app
configs
controller
core
models
schemas
services
utils
yolov5
.github
classify
data
models
utils
aws
docker
flask_rest_api
README.md
example_request.py
restapi.py
google_app_engine
loggers
__init__.py
activations.py
augmentations.py
autoanchor.py
autobatch.py
benchmarks.py
callbacks.py
dataloaders.py
downloads.py
general.py
loss.py
metrics.py
plots.py
torch_utils.py
.dockerignore
.gitattributes
.gitignore
.pre-commit-config.yaml
CONTRIBUTING.md
LICENSE
README.md
detect_server.py
export.py
hubconf.py
train_server.py
tutorial.ipynb
val.py
validate_server.py
zdp_R-ODYv1.pt
__init__.py
exts.py
file_tool.py
json_util.py
run.py
docs
tests
.gitignore
SetParams_Demo.py
__init__.py
deploy.sh
docker-compose.yml
nohup.out
pytest.ini
requirements.txt
requirements_p37.txt
setparams.py
RODY/app/yolov5/utils/flask_rest_api
552068321@qq.com 6f7de660aa first commit
2022-11-04 17:37:08 +08:00
..
2022-11-04 17:37:08 +08:00
2022-11-04 17:37:08 +08:00
2022-11-04 17:37:08 +08:00

Flask REST API

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.

Requirements

Flask is required. Install with:

$ pip install Flask

Run

After Flask installation run:

$ python3 restapi.py --port 5000

Then use curl to perform a request:

$ curl -X POST -F image=@zidane.jpg 'http://localhost:5000/v1/object-detection/yolov5s'

The model inference results are returned as a JSON response:

[
  {
    "class": 0,
    "confidence": 0.8900438547,
    "height": 0.9318675399,
    "name": "person",
    "width": 0.3264600933,
    "xcenter": 0.7438579798,
    "ycenter": 0.5207948685
  },
  {
    "class": 0,
    "confidence": 0.8440024257,
    "height": 0.7155083418,
    "name": "person",
    "width": 0.6546785235,
    "xcenter": 0.427829951,
    "ycenter": 0.6334488392
  },
  {
    "class": 27,
    "confidence": 0.3771208823,
    "height": 0.3902671337,
    "name": "tie",
    "width": 0.0696444362,
    "xcenter": 0.3675483763,
    "ycenter": 0.7991207838
  },
  {
    "class": 27,
    "confidence": 0.3527112305,
    "height": 0.1540903747,
    "name": "tie",
    "width": 0.0336618312,
    "xcenter": 0.7814827561,
    "ycenter": 0.5065554976
  }
]

An example python script to perform inference using requests is given in example_request.py