You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 1 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Flask REST API
  2. [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) [API](https://en.wikipedia.org/wiki/API)s 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](https://pytorch.org/hub/ultralytics_yolov5/).
  3. ## Requirements
  4. [Flask](https://palletsprojects.com/p/flask/) is required. Install with:
  5. ```shell
  6. $ pip install Flask
  7. ```
  8. ## Run
  9. After Flask installation run:
  10. ```shell
  11. $ python3 restapi.py --port 5000
  12. ```
  13. Then use [curl](https://curl.se/) to perform a request:
  14. ```shell
  15. $ curl -X POST -F image=@zidane.jpg 'http://localhost:5000/v1/object-detection/yolov5s'`
  16. ```
  17. The model inference results are returned:
  18. ```shell
  19. [{'class': 0,
  20. 'confidence': 0.8197850585,
  21. 'name': 'person',
  22. 'xmax': 1159.1403808594,
  23. 'xmin': 750.912902832,
  24. 'ymax': 711.2583007812,
  25. 'ymin': 44.0350036621},
  26. {'class': 0,
  27. 'confidence': 0.5667674541,
  28. 'name': 'person',
  29. 'xmax': 1065.5523681641,
  30. 'xmin': 116.0448303223,
  31. 'ymax': 713.8904418945,
  32. 'ymin': 198.4603881836},
  33. {'class': 27,
  34. 'confidence': 0.5661227107,
  35. 'name': 'tie',
  36. 'xmax': 516.7975463867,
  37. 'xmin': 416.6880187988,
  38. 'ymax': 717.0524902344,
  39. 'ymin': 429.2020568848}]
  40. ```
  41. An example python script to perform inference using [requests](https://docs.python-requests.org/en/master/) is given in `example_request.py`