If you’re looking to harness the power of TensorFlow for object detection without the need for a GPU, you’re in the right place! This guide will walk you through the steps necessary to set up the TensorFlow CPU Inference API on both Windows and Linux systems. Moreover, we will explore how to extract text from images using optical character recognition (OCR).
Prerequisites
- Operating System:
- Ubuntu 16.04 or 18.04
- Windows 10 Pro/Enterprise
- Docker installed
Checking for Prerequisites
To verify if you have Docker installed, run the following command:
docker --version
Installing Prerequisites
For Ubuntu
Run the following commands to install Docker:
chmod +x install_prerequisites.sh && source install_prerequisites.sh
For Windows 10
You can install Docker by following the instructions at this link.
**P.S: After installation, open Docker Desktop and adjust resources under Settings and Advanced**
Building the Docker Image
To create the project’s Docker image, execute the following command from the project’s root directory:
sudo docker build -t tensorflow_inference_api_cpu -f docker/Dockerfile .
Behind a Proxy?
If you’re behind a proxy, use the command like this:
sudo docker build --build-arg http_proxy= --build-arg https_proxy= -t tensorflow_inference_api_cpu -f docker/Dockerfile .
Running the Docker Container
You can deploy this API using either **docker** or **docker swarm**. If there’s no specific requirement for redundancy or scaling, just use docker. To run the container, navigate to the API’s directory and execute:
Using Linux-based Docker:
sudo docker run -it -v $(pwd)/models:models -v $(pwd)/models_hash:models_hash -p :4343 tensorflow_inference_api_cpu
Using Windows-based Docker:
docker run -it -v $PWD/models:models -v $PWD/models_hash:models_hash -p :4343 tensorflow_inference_api_cpu
The docker_host_port can be any unique port of your choice. Once executed, the API will be ready to accept HTTP requests on that port.
Understanding the API Endpoints
After running the API, access the available endpoints by navigating to: http://
- load (GET) – Loads all available models.
- detect (POST) – Performs inference on a specified model and returns bounding boxes.
- get_labels (POST) – Returns all the specified model labels.
- models/model_name/ocr (POST) – Uses images to extract text details.
**Note:** For custom endpoints like load, detect, and get_labels, always use the load endpoint first.
Model Structure
The folder named models contains subfolders for each model. Each subfolder must include:
- pb file — frozen_inference_graph.pb (model weights).
- pbtxt file — object-detection.pbtxt (model classes).
- Config.json — Configuration information for the model.
Troubleshooting
If you encounter issues during deployment or API usage, consider the following:
- Ensure Docker is correctly installed and running.
- Check if the specified Docker host port is not in use by another application.
- Review the API endpoint calls for correct syntax.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

