選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

README.md 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 as a JSON response:
  18. ```json
  19. [
  20. {
  21. "class": 0,
  22. "confidence": 0.8900438547,
  23. "height": 0.9318675399,
  24. "name": "person",
  25. "width": 0.3264600933,
  26. "xcenter": 0.7438579798,
  27. "ycenter": 0.5207948685
  28. },
  29. {
  30. "class": 0,
  31. "confidence": 0.8440024257,
  32. "height": 0.7155083418,
  33. "name": "person",
  34. "width": 0.6546785235,
  35. "xcenter": 0.427829951,
  36. "ycenter": 0.6334488392
  37. },
  38. {
  39. "class": 27,
  40. "confidence": 0.3771208823,
  41. "height": 0.3902671337,
  42. "name": "tie",
  43. "width": 0.0696444362,
  44. "xcenter": 0.3675483763,
  45. "ycenter": 0.7991207838
  46. },
  47. {
  48. "class": 27,
  49. "confidence": 0.3527112305,
  50. "height": 0.1540903747,
  51. "name": "tie",
  52. "width": 0.0336618312,
  53. "xcenter": 0.7814827561,
  54. "ycenter": 0.5065554976
  55. }
  56. ]
  57. ```
  58. An example python script to perform inference using [requests](https://docs.python-requests.org/en/master/) is given in `example_request.py`