Skip to content

Commit c3e19df

Browse files
committed
init
1 parent bbcc115 commit c3e19df

29 files changed

+1275
-0
lines changed

LICENSE

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2019, BMW Group
4+
Copyright (C) 2000-2019, Intel Corporation, all rights reserved.
5+
Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
6+
Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
7+
Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
8+
Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
9+
Copyright (C) 2015-2016, Itseez Inc., all rights reserved.
10+
Third party copyrights are property of their respective owners.
11+
12+
Redistribution and use in source and binary forms, with or without
13+
modification, are permitted provided that the following conditions are met:
14+
15+
1. Redistributions of source code must retain the above copyright notice, this
16+
list of conditions and the following disclaimer.
17+
18+
2. Redistributions in binary form must reproduce the above copyright notice,
19+
this list of conditions and the following disclaimer in the documentation
20+
and/or other materials provided with the distribution.
21+
22+
3. Neither the name of the copyright holder nor the names of its
23+
contributors may be used to endorse or promote products derived from
24+
this software without specific prior written permission.
25+
26+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# YOLO v3 CPU Inference API for Windows and Linux
2+
3+
This is a repository for an object detection inference API using the Yolov3 Opencv.
4+
5+
The inference REST API works on CPU and doesn't require any GPU usage. It's supported on both Windows and Linux Operating systems.
6+
7+
Models trained using our training Yolov3 repository can be deployed in this API. Several object detection models can be loaded and used at the same time.
8+
9+
![predict image](./docs/4.gif)
10+
11+
## Prerequisites
12+
13+
- OS:
14+
- Ubuntu 16.04/18.04
15+
- Windows 10 pro/enterprise
16+
- Docker
17+
18+
### Check for prerequisites
19+
20+
To check if you have docker-ce installed:
21+
22+
```sh
23+
docker --version
24+
```
25+
26+
### Install prerequisites
27+
28+
#### Ubuntu
29+
30+
Use the following command to install docker on Ubuntu:
31+
32+
```sh
33+
chmod +x install_prerequisites.sh && source install_prerequisites.sh
34+
```
35+
36+
#### Windows 10
37+
38+
To [install Docker on Windows](https://docs.docker.com/docker-for-windows/install/), please follow the link.
39+
40+
**P.S: For Windows users, open the Docker Desktop menu by clicking the Docker Icon in the Notifications area. Select Settings, and then Advanced tab to adjust the resources available to Docker Engine.**
41+
42+
## Build The Docker Image
43+
44+
In order to build the project run the following command from the project's root directory:
45+
46+
```sh
47+
sudo docker build -t yolov3_inference_api_cpu -f ./docker/dockerfile .
48+
```
49+
### Behind a proxy
50+
51+
```sh
52+
sudo docker build --build-arg http_proxy='' --build-arg https_proxy='' -t yolov3_inference_api_cpu -f ./docker/dockerfile .
53+
54+
```
55+
56+
## Run The Docker Container
57+
58+
To run the API, go to the project's root directory and run the following:
59+
60+
#### Using Linux based docker:
61+
62+
```sh
63+
sudo docker run -itv $(pwd)/models:/models -p <docker_host_port>:7770 yolov3_inference_api_cpu
64+
```
65+
#### Using Windows based docker:
66+
67+
```sh
68+
docker run -itv ${PWD}/models:/models -p <docker_host_port>:7770 yolov3_inference_api_cpu
69+
```
70+
71+
The <docker_host_port> can be any unique port of your choice.
72+
73+
The API file will be run automatically, and the service will listen to http requests on the chosen port.
74+
75+
## API Endpoints
76+
77+
To see all available endpoints, open your favorite browser and navigate to:
78+
79+
```
80+
http://<machine_IP>:<docker_host_port>/docs
81+
```
82+
The 'predict_batch' endpoint is not shown on swagger.
83+
84+
**P.S: If you are using custom endpoints like /load, /detect, and /get_labels, you should always use the /load endpoint first and then use /detect or /get_labels**
85+
86+
### Endpoints summary
87+
88+
#### /load (GET)
89+
90+
Loads all available models and returns every model with it's hashed value. Loaded models are stored and aren't loaded again
91+
92+
![load model](./docs/1.gif)
93+
94+
#### /detect (POST)
95+
96+
Performs inference on specified model, image, and returns bounding-boxes
97+
98+
![detect image](./docs/3.gif)
99+
100+
#### /get_labels (POST)
101+
102+
Returns all of the specified model labels with their hashed values
103+
104+
![get model labels](./docs/2.gif)
105+
106+
#### /models/{model_name}/predict_image (POST)
107+
108+
Performs inference on specified model, image, draws bounding boxes on the image, and returns the actual image as response
109+
110+
![predict image](./docs/4.gif)
111+
112+
#### /models (GET)
113+
114+
Lists all available models
115+
116+
#### /models/{model_name}/load (GET)
117+
118+
Loads the specified model. Loaded models are stored and aren't loaded again
119+
120+
#### /models/{model_name}/predict (POST)
121+
122+
Performs inference on specified model, image, and returns bounding boxes.
123+
124+
#### /models/{model_name}/labels (GET)
125+
126+
Returns all of the specified model labels
127+
128+
#### /models/{model_name}/config (GET)
129+
130+
Returns the specified model's configuration
131+
132+
#### /models/{model_name}/predict_batch (POST)
133+
134+
Performs inference on specified model and a list of images, and returns bounding boxes
135+
136+
## Model structure
137+
138+
The folder "models" contains subfolders of all the models to be loaded.
139+
Inside each subfolder there should be a:
140+
141+
- Cfg file (ends with .cfg): contains the configuration of the model
142+
143+
- Weights file (ends with .weights)
144+
145+
- Names file (ends with .names) : contains the names of the classes
146+
147+
- Config.json (This is a json file containing information about the model)
148+
149+
```json
150+
{
151+
"inference_engine_name": "yolov3_opencv_cpu_detection",
152+
"confidence": 60,
153+
"nms_threshold": 0.6,
154+
"image": {
155+
"width": 416,
156+
"height": 416,
157+
"scale": 0.00392,
158+
"swapRB": true,
159+
"crop": false,
160+
"mean": {
161+
"R": 0,
162+
"G": 0,
163+
"B": 0
164+
}
165+
},
166+
"framework": "yolo",
167+
"type": "detection",
168+
"network": "network_name"
169+
}
170+
```
171+
P.S
172+
- confidence value should be between 0 and 100
173+
- nms_threshold value should be between 0 and 1
174+
- You can change confidence and nms_threshold values while running the API
175+
- The API will return bounding boxes with a confidence higher than the "confidence" value. A high "confidence" can show you only accurate predictions
176+
177+
## Benchmarking
178+
179+
<table>
180+
<thead align="center">
181+
<tr>
182+
<th></th>
183+
<th>Windows</th>
184+
<th colspan=3>Ubuntu</th>
185+
</tr>
186+
</thead>
187+
<thead align="center">
188+
<tr>
189+
<th>Network\Hardware</th>
190+
<th>Intel Xeon CPU 2.3 GHz</th>
191+
<th>Intel Xeon CPU 2.3 GHz</th>
192+
<th>Intel Core i9-7900 3.3 GHZ</th>
193+
<th>GeForce GTX 1080</th>
194+
</tr>
195+
</thead>
196+
<tbody align="center">
197+
<tr>
198+
<td>pascalvoc_dataset</td>
199+
<td>0.885 seconds/image</td>
200+
<td>0.793 seconds/image</td>
201+
<td>0.295 seconds/image</td>
202+
<td>0.0592 seconds/image</td>
203+
</tr>
204+
</tbody>
205+
</table>
206+
207+
## Acknowledgment
208+
209+
[inmind.ai](https://inmind.ai)
210+
211+
[robotron.de](https://robotron.de)
212+
213+
Antoine Charbel, inmind.ai , Beirut, Lebanon
214+
215+
Daniel Anani, inmind.ai, Beirut, Lebanon
216+

docker/dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.6
2+
3+
LABEL maintainer="[email protected]"
4+
5+
COPY docker/requirements.txt .
6+
7+
COPY src/main /main
8+
9+
RUN pip install -r requirements.txt
10+
11+
WORKDIR /main
12+
13+
CMD ["uvicorn", "start:app", "--host", "0.0.0.0", "--port", "7770"]

docker/requirements.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fastapi
2+
uvicorn
3+
numpy
4+
opencv-python
5+
python-multipart
6+
pillow
7+
python-socketio
8+
requests
9+
aiofiles
10+
jsonschema

docs/1.gif

1.21 MB
Loading

docs/2.gif

1.96 MB
Loading

docs/3.gif

1.05 MB
Loading

docs/4.gif

1.77 MB
Loading

docs/swagger_endpoints.png

56.1 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="www.draw.io" modified="2019-12-05T18:25:03.136Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/78.0.3904.108 Chrome/78.0.3904.108 Safari/537.36" etag="kdc3ZMaooM-ZAjUYGDE8" version="12.3.7" type="device" pages="1"><diagram name="Page-1" id="c4acf3e9-155e-7222-9cf6-157b1a14988f">7V1bk6O2Ev41rjp58BZ348fxXHZzMptsZU7tyebFJYNsk8WICDyeya+PBBIGJF8mHiObaGtrFzWSkLo/Wt2tFh7Yt6uXjxiky88ohPHAMsKXgX03sMgfwyX/UcprSTF9xyspCxyFjLYlPEV/QUY0GHUdhTBrVMwRivMobRIDlCQwyBs0gDHaNKvNUdx8agoWUCA8BSAWqf+PwnxZUn3X2NI/wWix5E82DXZnBoLvC4zWCXvewLLnxZ/y9grwvlj9bAlCtKmR7PuBfYsRysur1cstjClzOdvKdg877lbjxjDJj2owAsEMuCPHh6499mZD1sMziNeMFz8mc0i6CyAbcf7KuUQGn9LL9Sp+wGBFLiebZZTDpxQElL4h6CC0Zb6KSckklwVnIH22QUrV5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