Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Flask REST API
  2. [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) [API](https://en.wikipedia.org/wiki/API)s are
  3. commonly used to expose Machine Learning (ML) models to other services. This folder contains an example REST API
  4. created using Flask to expose the YOLOv5s model from [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/).
  5. ## Requirements
  6. [Flask](https://palletsprojects.com/p/flask/) is required. Install with:
  7. ```shell
  8. $ pip install Flask
  9. ```
  10. ## Run
  11. After Flask installation run:
  12. ```shell
  13. $ python3 restapi.py --port 5000
  14. ```
  15. Then use [curl](https://curl.se/) to perform a request:
  16. ```shell
  17. $ curl -X POST -F image=@zidane.jpg 'http://localhost:5000/v1/object-detection/yolov5s'
  18. ```
  19. The model inference results are returned as a JSON response:
  20. ```json
  21. [
  22. {
  23. "class": 0,
  24. "confidence": 0.8900438547,
  25. "height": 0.9318675399,
  26. "name": "person",
  27. "width": 0.3264600933,
  28. "xcenter": 0.7438579798,
  29. "ycenter": 0.5207948685
  30. },
  31. {
  32. "class": 0,
  33. "confidence": 0.8440024257,
  34. "height": 0.7155083418,
  35. "name": "person",
  36. "width": 0.6546785235,
  37. "xcenter": 0.427829951,
  38. "ycenter": 0.6334488392
  39. },
  40. {
  41. "class": 27,
  42. "confidence": 0.3771208823,
  43. "height": 0.3902671337,
  44. "name": "tie",
  45. "width": 0.0696444362,
  46. "xcenter": 0.3675483763,
  47. "ycenter": 0.7991207838
  48. },
  49. {
  50. "class": 27,
  51. "confidence": 0.3527112305,
  52. "height": 0.1540903747,
  53. "name": "tie",
  54. "width": 0.0336618312,
  55. "xcenter": 0.7814827561,
  56. "ycenter": 0.5065554976
  57. }
  58. ]
  59. ```
  60. An example python script to perform inference using [requests](https://docs.python-requests.org/en/master/) is given
  61. in `example_request.py`