Giter Club home page Giter Club logo

bmw-yolov4-inference-api-gpu's Introduction

YOLOv4-v3 Darknet GPU Inference API

This is a repository for an object detection inference API using the Yolov4 Darknet framework.

This Repository has also cross compatibility for Yolov3 darknet models.

This Repository has also support for state of the art Yolov4 models

This repo is based on AlexeyAB darknet repository.

The inference REST API works on GPU. It's supported only on Linux Operating systems.

Models trained using our training automation Yolov4 and Yolov3 repository can be deployed in this API. Several object detection models can be loaded and used at the same time.

To choose Yolov4 instead of Yolov3 training just change the inference engine name in the config.json inside your model folder.

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.

predict image

Prerequisites

  • Ubuntu 18.04
  • NVIDIA Drivers (410.x or higher)
  • Docker CE latest stable release
  • NVIDIA Docker 2

Check for prerequisites

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

img

Install prerequisites

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

Build The Docker Image

In order to build the project run the following command from the project's root directory:

sudo docker build -t yolov4_inference_api_gpu -f ./docker/dockerfile .

Behind a proxy

sudo docker build --build-arg http_proxy='' --build-arg https_proxy='' -t yolov4_inference_api_gpu -f ./docker/dockerfile .

Run The Docker Container

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:

Using Linux based docker:

sudo NV_GPU=0 nvidia-docker run -itv $(pwd)/models:/models -v $(pwd)/models_hash:/models_hash -p <docker_host_port>:1234 yolov4_inference_api_gpu

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.

NV_GPU defines on which GPU you want the API to run. If you want the API to run on multiple GPUs just enter multiple numbers seperated by a comma: (NV_GPU=0,1 for example)

API Endpoints

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

Endpoints summary

/load (GET)

Loads all available models and returns every model with it's hashed value. Loaded models are stored and aren't loaded again

load model

/detect (POST)

Performs inference on specified model, image, and returns bounding-boxes

detect image

/get_labels (POST)

Returns all of the specified model labels with their hashed values

get model labels

/models/{model_name}/predict_image (POST)

Performs inference on specified model, image, draws bounding boxes on the image, and returns the actual image as response

predict image

/models (GET)

Lists all available models

/models/{model_name}/load (GET)

Loads the specified model. Loaded models are stored and aren't loaded again

/models/{model_name}/predict (POST)

Performs inference on specified model, image, and returns bounding boxes.

/models/{model_name}/labels (GET)

Returns all of the specified model labels

/models/{model_name}/config (GET)

Returns the specified model's configuration

/models/{model_name}/predict_batch (POST)

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

Model structure

The folder "models" contains subfolders of all the models to be loaded. Inside each subfolder there should be a:

~/BMW-YOLOv4-Inference-API-GPU/models/<name-of-the-model>/config.json
~/BMW-YOLOv4-Inference-API-GPU/models/<name-of-the-model>/obj.data
~/BMW-YOLOv4-Inference-API-GPU/models/<name-of-the-model>/obj.names
~/BMW-YOLOv4-Inference-API-GPU/models/<name-of-the-model>/yolo-obj.cfg
~/BMW-YOLOv4-Inference-API-GPU/models/<name-of-the-model>/yolo-obj.weights
  • Cfg file (yolo-obj.cfg): contains the configuration of the model

  • data file (obj.data): contains number of classes and names file path

    classes=<number_of_classes>
    names=/models/<model_name>/obj.names
    
  • Weights file (yolo-obj.weights)

  • Names file (obj.names) : contains the names of the classes

  • Config.json (This is a json file containing information about the model)

      {
        "inference_engine_name": "yolov4_darknet_detection",
        "detection_threshold": 0.6,
        "nms_threshold": 0.45,
        "hier_threshold": 0.5,
        "framework": "yolo",
        "type": "detection",
        "network": "network_name"
      }

    P.S

    • You can choose "yolov4_darknet_detection" for Yolo v4 model or "yolov3_darknet_detection" for Yolo v3 model
    • You can change detection_threshold, nms_threshold, and hier_threshold values while running the API
    • The API will return bounding boxes with a detection higher than the detection_threshold value. A high detection_threshold can show you only accurate predictions

Benchmarking

Ubuntu
Network\Hardware Intel Xeon CPU 2.3 GHz Intel Core i9-7900 3.3 GHZ Tesla V100
COCO Dataset 0.259 seconds/image 0.281 seconds/image 0.0691 seconds/image

Acknowledgment

inmind.ai

robotron.de

Antoine Charbel, inmind.ai , Beirut, Lebanon

Charbel El Achkar, Beirut, Lebanon

Hadi Koubeissy, Beirut, Lebanon

bmw-yolov4-inference-api-gpu's People

Contributors

antoinecharbel-inmind avatar antoinencharbel avatar hadikoub avatar marc-kamradt avatar mariokhoury4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bmw-yolov4-inference-api-gpu's Issues

where is the predict_batch option?

there's no "predict_batch" option in the web interface...

models/{model_name}/predict_batch (POST)
Performs inference on specified model and a list of images, and returns bounding boxes

Load Yolov3 Model

Couln't find a way to load models, In the tutorial, it is shown that model path is name like dummy_5000, which directory it is going to search for dummy_5000. I also trained yolov3 using sample dataset to get all 5 files needed, but have no idea how to load them into inference.

Inference engine not found: yolov4_darknet_detection

Hi, can improve the docs about models folder structure.
this is my config:
/root/BMW-YOLOv4-Inference-API-GPU/models/
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/yolov4.weights
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/obj.data
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/config.json
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/yolov4.cfg
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/obj.names
/root/BMW-YOLOv4-Inference-API-GPU/models/.gitignore

And this is de content of the files:
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/obj.data:
classes=80
names=/models/yolov4/obj.names
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/config.json:
{
"inference_engine_name": "yolov4_darknet_detection",
"detection_threshold": 0.6,
"nms_threshold": 0.45,
"hier_threshold": 0.5,
"framework": "yolo",
"type": "detection",
"network": "network_name"
}
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/yolov4.cfg:
[net]
batch=64
subdivisions=8

Training

#width=512
#height=512
width=608
height=608
channels=3
momentum=0.949
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1

learning_rate=0.0013
burn_in=1000
max_batches = 500500
policy=steps
steps=400000,450000
scales=.1,.1

#cutmix=1
mosaic=1

#:104x104 54:52x52 85:26x26 104:13x13 for 416

[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=mish

Downsample

[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=mish

[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=mish

[route]
layers = -2

[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=mish

[convolutional]
batch_normalize=1
filters=32
size=1
stride=1
pad=1
activation=mish

[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=mish

[shortcut]
from=-3
activation=linear

[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=mish

[route]
layers = -1,-7

[convolutional]
.....
/root/BMW-YOLOv4-Inference-API-GPU/models/yolov4_darknet_detection/obj.names:
person
bicycle
car
motorbike
aeroplane
bus
train
truck
boat
traffic light
fire hydrant
stop sign
parking meter
bench
bird
cat
dog
horse
sheep
cow
elephant
bear
zebra
giraffe
backpack
umbrella
handbag
tie
suitcase
frisbee
skis
snowboard
sports ball
kite
baseball bat
baseball glove
skateboard
surfboard
tennis racket
bottle
wine glass
cup
fork
knife
spoon
bowl
banana
apple
sandwich
orange
broccoli
carrot
hot dog
pizza
donut
cake
chair
sofa
pottedplant
bed
diningtable
toilet
tvmonitor
laptop
mouse
remote
keyboard
cell phone
microwave
oven
toaster
sink
refrigerator
book
clock
vase
scissors
teddy bear
hair drier
toothbrush
And this is the response when try to load from http://..docs#/default/load_custom_load_get
{
"data": null,
"error": "Inference engine not found: yolov4_darknet_detection",
"success": false
}
Thanks.

error cant find ".names" file

I get the following error when trying to load the models from the docs web interface.
the obj.name file is in the "models" dir and I tried to put relate and absolute path in the Yolo.data file.

names=/home/sim/Desktop/BMW-YOLOv4-Inference-API-GPU/models/tiny_fhd/obj.names

INFO:     Started server process [1]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:1234 (Press CTRL+C to quit)
Couldn't open file: /home/sim/Desktop/BMW-YOLOv4-Inference-API-GPU/models/tiny_fhd/obj.names

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.