BMW-InnovationLab/BMW-TensorFlow-Inference-API-GPU

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

Project Overview

BMW-TensorFlow-Inference-API-GPU is a tool that turns TensorFlow object detection models into a web service. It lets you send images to the API and get back bounding boxes (rectangles around detected objects) or even the image with boxes drawn on it. It also includes optical character recognition (OCR) to extract text from images.

It's built on top of the official TensorFlow Object Detection API and uses TensorFlow 1.13.1. The service runs on a GPU and is only supported on Linux.

Key Features

  • Multiple models at once: You can load and use several object detection models simultaneously.
  • OCR services: Two ways to extract text: with a detection model to first crop interesting areas, or directly without detection.
  • Flexible deployment: Use plain Docker for a single instance, or Docker Swarm for redundancy, coordination, and scaling.
  • Customizable confidence and prediction limits: You can adjust how confident the model must be to return a box, and how many boxes to return.

How It Works

  • The API loads models from a models folder. Each model subfolder contains:
    • A .pb file (frozen inference graph – the model's weights).
    • A .pbtxt file (class labels).
    • A config.json file with settings like confidence threshold, max predictions, and network type.
  • You interact with the API via HTTP endpoints (see below).
  • The service runs inside a Docker container, which you build and start.

Requirements

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

Deployment

Build the Docker image

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

(There's also a proxy option if needed.)

Run with Docker (single instance)

sudo NV_GPU=0 nvidia-docker run -itv $(pwd)/models:/models -v $(pwd)/models_hash:/models_hash -p <docker_host_port>:4343 tensorflow_inference_api_gpu
  • NV_GPU selects which GPU(s) to use (e.g., 0,1 for multiple).
  • The API listens on the chosen port.

Run with Docker Swarm

Use Swarm only if you need:

  • Redundancy (if one container fails, requests go to another).
  • Coordination between containers.
  • Scaling up for faster predictions under traffic.

API Endpoints

The README lists these endpoints (all under http://<machine_IP>:<docker_host_port>):

  • /docs – Swagger UI to see all endpoints.
  • /load (GET) – Loads all available models and returns each with a hash value. Loaded models are cached.
  • /detect (POST) – Runs inference on a specified model and image, returns bounding boxes.
  • /get_labels (POST) – Returns all labels for a specified model with hashes.
  • /models/{model_name}/predict_image (POST) – Runs inference, draws boxes on the image, returns the annotated image.
  • /models (GET) – Lists all available models.
  • /models/{model_name}/load (GET) – Loads a specific model (cached).
  • /models/{model_name}/predict (POST) – Runs inference and returns bounding boxes.
  • /models/{model_name}/labels (GET) – Returns labels for a model.
  • /models/{model_name}/config (GET) – Returns the model's configuration.
  • /models/{model_name}/predict_batch (POST) – Runs inference on a list of images (not shown in Swagger).
  • /models/{model_name}/one_shot_ocr (POST) – Extracts text using a detection model to crop areas first.
  • /models/{model_name}/ocr (POST) – Extracts text directly without detection.

Important: For custom endpoints like /load, /detect, /get_labels, and /one_shot_ocr, always call /load first, then the others.

Model Structure

Each model lives in a subfolder under models. Inside that folder you need:

  • frozen_inference_graph.pb – the model weights.
  • object-detection.pbtxt – class labels.
  • config.json – example:
{
    "inference_engine_name": "tensorflow_detection",
    "confidence": 60,
    "predictions": 15,
    "number_of_classes": 2,
    "framework": "tensorflow",
    "type": "detection",
    "network": "inception"
}
  • confidence and predictions can be changed at runtime.
  • The API returns boxes with confidence above the confidence value, and limits the number of boxes to predictions.

Performance

The README includes a benchmark table comparing different networks (e.g., ssd_fpn, frcnn_resnet_50, ssd_mobilenet) on different hardware (CPU vs GPU). For example, on a GeForce GTX 1080, ssd_fpn takes 0.0658 seconds per image, while frcnn_resnet_101 takes 0.364 seconds. This shows GPU acceleration is much faster than CPU.

Acknowledgments

The project credits inmind.ai, robotron.de, and several individuals.


All information above is directly from the README; no external details were added.

Related

  • Project
  • Project
  • Project
  • Project