Skip to content

Commit f6b0263

Browse files
pderrengerglenn-jocherUltralyticsAssistant
authored
Ultralytics Refactor https://ultralytics.com/actions (#2323)
* Refactor code for speed and clarity * Auto-format by https://ultralytics.com/actions --------- Co-authored-by: Glenn Jocher <[email protected]> Co-authored-by: UltralyticsAssistant <[email protected]>
1 parent 1107102 commit f6b0263

File tree

10 files changed

+452
-366
lines changed

10 files changed

+452
-366
lines changed

README.md

+163-142
Large diffs are not rendered by default.

data/scripts/download_weights.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
2-
# YOLOv3 🚀 by Ultralytics, AGPL-3.0 license
2+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3+
34
# Download latest models from https://github.com/ultralytics/yolov5/releases
45
# Example usage: bash data/scripts/download_weights.sh
56
# parent

data/scripts/get_coco.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
2-
# YOLOv3 🚀 by Ultralytics, AGPL-3.0 license
2+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3+
34
# Download COCO 2017 dataset http://cocodataset.org
45
# Example usage: bash data/scripts/get_coco.sh
56
# parent

data/scripts/get_coco128.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
2-
# YOLOv3 🚀 by Ultralytics, AGPL-3.0 license
2+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3+
34
# Download COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017)
45
# Example usage: bash data/scripts/get_coco128.sh
56
# parent

data/scripts/get_imagenet.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
2-
# YOLOv3 🚀 by Ultralytics, AGPL-3.0 license
2+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3+
34
# Download ILSVRC2012 ImageNet dataset https://image-net.org
45
# Example usage: bash data/scripts/get_imagenet.sh
56
# parent

utils/aws/mime.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2+
13
# AWS EC2 instance startup 'MIME' script https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/
24
# This script will run on every instance restart, not only on first start
35
# --- DO NOT COPY ABOVE COMMENTS WHEN PASTING INTO USERDATA ---

utils/aws/userdata.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
2+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3+
24
# AWS EC2 instance startup script https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
35
# This script will run only once on first instance start (for a re-start script see mime.sh)
46
# /home/ubuntu (ubuntu) or /home/ec2-user (amazon-linux) is working dir

utils/flask_rest_api/README.md

+38-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
1-
# Flask REST API
1+
<a href="https://www.ultralytics.com/"><img src="https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg" width="320" alt="Ultralytics logo"></a>
22

3-
[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+
# Flask REST API Example for YOLO Models
44

5-
## Requirements
5+
[Representational State Transfer (REST)](https://en.wikipedia.org/wiki/Representational_state_transfer) [Application Programming Interfaces (APIs)](https://developer.mozilla.org/en-US/docs/Web/API) are a standard way to expose [Machine Learning (ML)](https://www.ultralytics.com/glossary/machine-learning-ml) models, allowing other services or applications to interact with them over a network. This directory provides an example REST API built using the [Flask](https://palletsprojects.com/projects/flask/) microframework to serve predictions from an [Ultralytics YOLOv5s](https://docs.ultralytics.com/models/yolov5/) model loaded via [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/).
66

7-
[Flask](https://palletsprojects.com/projects/flask/) is required. Install with:
7+
Deploying models via APIs is a crucial step in [MLOps](https://www.ultralytics.com/glossary/machine-learning-operations-mlops) and enables integration into larger systems. You can explore various [model deployment options](https://docs.ultralytics.com/guides/model-deployment-options/) for different scenarios.
8+
9+
## 🔧 Requirements
10+
11+
Ensure you have the necessary Python packages installed. The primary requirement is Flask.
12+
13+
Install Flask using pip:
814

915
```shell
10-
$ pip install Flask
16+
pip install Flask torch torchvision
1117
```
1218

13-
## Run
19+
_Note: `torch` and `torchvision` are required by the YOLOv5 model from PyTorch Hub._
20+
21+
## ▶️ Run the API
1422

15-
After Flask installation run:
23+
Once Flask and dependencies are installed, you can start the API server.
24+
25+
Execute the Python script:
1626

1727
```shell
18-
$ python3 restapi.py --port 5000
28+
python restapi.py --port 5000
1929
```
2030

21-
Then use [curl](https://curl.se/) to perform a request:
31+
The API server will start listening on the specified port (default is 5000).
32+
33+
## 🚀 Make a Prediction Request
34+
35+
You can send prediction requests to the running API using tools like [`curl`](https://curl.se/) or scripting languages.
36+
37+
Send a POST request with an image file (`zidane.jpg` in this example) to the `/v1/object-detection/yolov5s` endpoint:
2238

2339
```shell
24-
$ curl -X POST -F [email protected] 'http://localhost:5000/v1/object-detection/yolov5s'
40+
curl -X POST -F [email protected] 'http://localhost:5000/v1/object-detection/yolov5s'
2541
```
2642

27-
The model inference results are returned as a JSON response:
43+
_Ensure `zidane.jpg` (or your test image) is present in the directory where you run the `curl` command._
44+
45+
## 📄 Understand the Response
46+
47+
The API processes the image and returns the [object detection](https://www.ultralytics.com/glossary/object-detection) results in [JSON](https://www.ultralytics.com/glossary/json) format. Each object detected includes its class ID, confidence score, bounding box coordinates (normalized), and class name.
48+
49+
Example JSON response:
2850

2951
```json
3052
[
@@ -67,4 +89,8 @@ The model inference results are returned as a JSON response:
6789
]
6890
```
6991

70-
An example python script to perform inference using [requests](https://docs.python-requests.org/en/master/) is given in `example_request.py`
92+
An example Python script (`example_request.py`) demonstrating how to send requests using the popular [requests](https://requests.readthedocs.io/en/latest/) library is also included in this directory.
93+
94+
## 🤝 Contributing
95+
96+
Contributions to enhance this example or add support for other Ultralytics models are welcome! Please see the main Ultralytics [CONTRIBUTING](https://docs.ultralytics.com/help/contributing/) guide for more information on how to get involved.

0 commit comments

Comments
 (0)