This is a repository for an object detection inference API using the Tensorflow framework.
This repo is based on Tensorflow Object Detection API.
The Tensorflow version used is 2.2.0. The inference REST API works on GPU. It's only supported on Linux Operating systems.
Models trained using our training tensorflow repository can be deployed in this API. Several object detection models can be loaded and used at the same time.
This repo can be deployed using either docker or docker swarm.
Please use docker swarm only if you need to:
-
Provide redundancy in terms of API containers: In case a container went down, the incoming requests will be redirected to another running instance.
-
Coordinate between the containers: Swarm will orchestrate between the APIs and choose one of them to listen to the incoming request.
-
Scale up the Inference service in order to get a faster prediction especially if there's traffic on the service.
If none of the aforementioned requirements are needed, simply use docker.
- Ubuntu 18.04
- NVIDIA Drivers (410.x or higher)
- Docker CE latest stable release
- NVIDIA Docker 2
To check if you have docker-ce installed:
docker --version
To check if you have nvidia-docker installed:
nvidia-docker --version
To check your nvidia drivers version, open your terminal and type the command nvidia-smi
Use the following command to install docker on Ubuntu:
chmod +x install_prerequisites.sh && source install_prerequisites.sh
Install NVIDIA Drivers (410.x or higher) and NVIDIA Docker for GPU by following the official docs
In order to build the project run the following command from the project's root directory:
- For GPU Build:
docker build -t tf2_inference_api_gpu -f docker/dockerfile-gpu .
- For CPU Build:
docker build -t tf2_inference_api_cpu -f docker/dockerfile .
- For GPU Build:
docker build --build-arg http_proxy='' --build-arg https_proxy='' -t tf2_inference_api_gpu -f docker/dockerfile-gpu .
- For CPU Build:
docker build --build-arg http_proxy='' --build-arg https_proxy='' -t tf2_inference_api_cpu -f docker/dockerfile .
As mentioned before, this container can be deployed using either docker or docker swarm.
If you wish to deploy this API using docker, please issue the following run command.
If you wish to deploy this API using docker swarm, please refer to following link docker swarm documentation. After deploying the API with docker swarm, please consider returning to this documentation for further information about the API endpoints as well as the model structure sections.
To run the API, go the to the API's directory and run the following:
- For GPU:
docker run --gpus '"device=<- gpu numbers seperated by commas ex:"0,1,2" ->"' -itv $(pwd)/models:/models -v $(pwd)/models_hash:/models_hash -p <port-of-your-choice>:4343 tf2_inference_api_gpu
- For CPU:
docker run -itv $(pwd)/models:/models -v $(pwd)/models_hash:/models_hash -p <port-of-your-choice>:4343 tf2_inference_api_cpu
The <docker_host_port> can be any unique port of your choice.
The API file will be run automatically, and the service will listen to http requests on the chosen port.
To see all available endpoints, open your favorite browser and navigate to:
http://<machine_IP>:<docker_host_port>/docs
The 'predict_batch' endpoint is not shown on swagger. The list of files input is not yet supported.
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
Loads all available models and returns every model with it's hashed value. Loaded models are stored and aren't loaded again
Performs inference on specified model, image, and returns bounding-boxes
Returns all of the specified model labels with their hashed values
Performs inference on specified model, image, draws bounding boxes on the image, and returns the actual image as response
Lists all available models
Loads the specified model. Loaded models are stored and aren't loaded again
Performs inference on specified model, image, and returns bounding boxes.
Returns all of the specified model labels
Returns the specified model's configuration
Performs inference on specified model and a list of images, and returns bounding boxes
P.S: Custom endpoints like /load, /detect, and /get_labels should be used in a chronological order. First you have to call /load, and then call /detect or /get_labels
The folder "models" contains subfolders of all the models to be loaded. Inside each subfolder there should be a:
-
pb file (frozen_inference_graph.pb): contains the model weights
-
pbtxt file (object-detection.pbtxt): contains model classes
-
Config.json (This is a json file containing information about the model)
{ "inference_engine_name": "tensorflow2_detection",//for tf2 models or "tensorflow_detection for tf1 models" "confidence": 60, "predictions": 15, "number_of_classes": 2, "framework": "tensorflow", "type": "detection", "network": "inception" }
P.S:
- You can change confidence and predictions values while running the API
- The API will return bounding boxes with a confidence higher than the "confidence" value. A high "confidence" can show you only accurate predictions
- The "predictions" value specifies the maximum number of bounding boxes in the API response
Windows | Ubuntu | |||
---|---|---|---|---|
Network\Hardware | Intel Xeon CPU 2.3 GHz | Intel Xeon CPU 2.3 GHz | Intel Xeon CPU 3.60 GHz | GeForce GTX 1080 |
ssd_fpn | 0.867 seconds/image | 1.016 seconds/image | 0.434 seconds/image | 0.0658 seconds/image |
frcnn_resnet_50 | 4.029 seconds/image | 4.219 seconds/image | 1.994 seconds/image | 0.148 seconds/image |
ssd_mobilenet | 0.055 seconds/image | 0.106 seconds/image | 0.051 seconds/image | 0.052 seconds/image |
frcnn_resnet_101 | 4.469 seconds/image | 4.985 seconds/image | 2.254 seconds/image | 0.364 seconds/image |
ssd_resnet_50 | 1.34 seconds/image | 1.462 seconds/image | 0.668 seconds/image | 0.091 seconds/image |
ssd_inception | 0.094 seconds/image | 0.15 seconds/image | 0.074 seconds/image | 0.0513 seconds/image |
Joe Sleiman, inmind.ai , Beirut, Lebanon
Antoine Charbel, inmind.ai, Beirut, Lebanon
Hadi koubeissy, inmind.ai,Beirut,Lebanon