Manh Ho Dinh commited on
Commit
435ad8e
·
verified ·
1 Parent(s): f9c9c34

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +0 -173
README.md CHANGED
@@ -1,176 +1,3 @@
1
- [![Coverage Status](https://img.shields.io/badge/coverage-97%25-brightgreen.svg)](https://github.com/Alex-Lekov/yolov8-fastapi)
2
-
3
- # YOLOv8-FastAPI:
4
-
5
- This repository serves as a template for object detection using YOLOv8 and FastAPI. With YOLOv8, you get a popular real-time object detection model and with FastAPI, you get a modern, fast (high-performance) web framework for building APIs. The project also includes Docker, a platform for easily building, shipping, and running distributed applications.
6
-
7
- ### Sample
8
-
9
- Here's a sample of what you can expect to see with this project:
10
- <img width=600 src="./tests/res/fastapi_sample.png" alt="">
11
-
12
- # What's inside:
13
-
14
- - YOLOv8: A popular real-time object detection model
15
- - FastAPI: A modern, fast (high-performance) web framework for building APIs
16
- - Docker: A platform for easily building, shipping, and running distributed applications
17
-
18
- <img width="100%" src="https://raw.githubusercontent.com/ultralytics/assets/main/yolov8/yolo-comparison-plots.png"></a>
19
-
20
- ---
21
-
22
- # Getting Started
23
-
24
- You have two options to start the application: using Docker or locally on your machine.
25
-
26
- ## Using Docker
27
-
28
- Start the application with the following command:
29
-
30
- ```
31
- docker-compose up
32
- ```
33
-
34
- ## Locally
35
-
36
- To start the application locally, follow these steps:
37
-
38
- 1. Install the required packages:
39
-
40
- ```
41
- pip install -r requirements.txt
42
- ```
43
-
44
- 2. Start the application:
45
-
46
- ```
47
- uvicorn main:app --reload --host 0.0.0.0 --port 8001
48
- ```
49
-
50
- \*Note: You can change the address and port in the file **docker-compose.yaml\***
51
-
52
- ## FAST API Docs url:
53
-
54
- http://0.0.0.0:8001/docs#/
55
-
56
- <img width=600 src="./tests/res/fastapi.png" alt="FAST API">
57
-
58
- Ready to start your object detection journey with YOLOv8-FastAPI? 🚀
59
-
60
- ---
61
-
62
- # 🚀 Code Examples
63
-
64
- ### Example 1: Object Detection to JSON
65
-
66
- The following code demonstrates how to perform object detection and receive the results in JSON format:
67
-
68
- ```python
69
- import requests
70
-
71
- input_image_name = 'test_image.jpg'
72
- api_host = 'http://0.0.0.0:8001/'
73
- type_rq = 'img_object_detection_to_json'
74
-
75
- files = {'file': open(input_image_name, 'rb')}
76
-
77
- response = requests.post(api_host+type_rq, files=files)
78
-
79
- data = response.json()
80
- print(data)
81
- ```
82
-
83
- Output:
84
-
85
- ```
86
- {'detect_objects': [{'name': 'cat', 'confidence': 0.926225245}, {'name': 'dog', 'confidence': 0.9109069705}], 'detect_objects_names': 'cat, dog'}
87
- ```
88
-
89
- ### Example 2: Object Detection to Image
90
-
91
- The following code demonstrates how to perform object detection and receive the results in image format.
92
-
93
- ```python
94
- import requests
95
- from PIL import Image
96
- from io import BytesIO
97
- import matplotlib.pyplot as plt
98
-
99
- input_image_name = 'test_image.jpg'
100
- api_host = 'http://0.0.0.0:8001/'
101
- type_rq = 'img_object_detection_to_img'
102
-
103
- files = {'file': open(input_image_name, 'rb')}
104
-
105
- response = requests.post(api_host+type_rq, files=files)
106
-
107
- img = Image.open(BytesIO(response.content))
108
- plt.imshow(img)
109
- ```
110
-
111
- ---
112
-
113
- # Overview of the code
114
-
115
- - [main.py](./main.py) - Base FastAPI functions
116
- - [app.py](./app.py) - YoloV8 functions
117
- - [./models](./models) - YoloV8 models folder
118
-
119
- ---
120
-
121
- # Test
122
-
123
- This repository contains functional tests for a program to ensure the proper operation of the service.
124
-
125
- ## Getting Started Test
126
-
127
- To get started with the testing process, you first need to set up the necessary environment. This can be achieved by either installing the required packages or by running the Docker container.
128
-
129
- #### 1. Installing Required Packages:
130
-
131
- Run the following command to install the necessary packages:
132
-
133
- ```
134
- pip install -r requirements.txt
135
- ```
136
-
137
- Alternatively, you can also run the tests inside a Docker container. To do so, follow these steps:
138
- Start the Docker container:
139
-
140
- ```
141
- docker-compose up
142
- ```
143
-
144
- Find the container ID:
145
-
146
- ```
147
- docker ps
148
- ```
149
-
150
- Connect inside the container:
151
-
152
- ```
153
- docker exec -it {CONTAINER_ID}
154
- ```
155
-
156
- #### 2. Run the tests from the program directory:
157
-
158
- Once you have set up the environment, navigate to the program directory and run the tests using the following command:
159
-
160
- ```
161
- pytest -v --disable-warnings
162
- ```
163
-
164
- If all tests pass successfully, you will see the following result:
165
- <img width=600 src="./tests/res/tests.png" alt="">
166
-
167
- ---
168
-
169
- Manh Ho Dinh 1 2 3
170
-
171
- # Contact
172
-
173
- [Telegram Group](https://t.me/automlalex)
174
  ---
175
  title: Food Recognition
176
  emoji: 💻
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Food Recognition
3
  emoji: 💻