|
| 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 | + |
| 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 | + |
| 93 | + |
| 94 | +#### /detect (POST) |
| 95 | + |
| 96 | +Performs inference on specified model, image, and returns bounding-boxes |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +#### /get_labels (POST) |
| 101 | + |
| 102 | +Returns all of the specified model labels with their hashed values |
| 103 | + |
| 104 | + |
| 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 | + |
| 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 | + |
0 commit comments