Breaking News

Setup Tensorflow Object detection on Linux

Tensorflow has a lot of work in reasearch. Which contains different models for deep learning such as DeepSpeech, GAN, Object detection and many more. We will setup Tensorflow's Object detection model on both Windows and Linux

Tensorflow Object detection repo is published on github. So first clone it using this command in cmd

git clone https://github.com/tensorflow/models.git
Now change directory to `models/research/`.

Installation

Dependencies

Tensorflow Object Detection API depends on the following libraries: All of these libraries are available in pip.
  • Protobuf 3.0.0
  • Python-tk
  • Pillow 1.0
  • lxml
  • tf Slim (which is included in the "tensorflow/models/research/" checkout)
  • Jupyter notebook
  • Matplotlib
  • Tensorflow (>=1.12.0)
  • Cython
  • contextlib2
  • cocoapi
For detailed steps to install Tensorflow, follow the Tensorflow installation instructions. A typical user can install Tensorflow using one of the following commands:
# For CPU
pip install tensorflow
# For GPU
pip install tensorflow-gpu
For GPU, you require CUDA and CUDNN installiation. Which can be done by visiting this link.
The remaining libraries can be installed using via apt-get:
sudo apt-get install protobuf-compiler python-pil python-lxml python-tk
pip install Cython
Alternatively, users can install dependencies using pip:
pip install --user Cython
pip install contextlib2
pip install pillow
pip install lxml
pip install jupyter
pip install matplotlib
For Ubuntu
Note: sometimes "sudo apt-get install protobuf-compiler" will install Protobuf 3+ versions for you and some users have issues when using 3.5. If that is your case, try the manual installation.

Protobuf Compilation

The Tensorflow Object Detection API uses Protobufs to configure model and training parameters. Before the framework can be used, the Protobuf libraries must be compiled. This should be done by running the following command from the tensorflow/models/research/ directory:
# From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.
Note: If you're getting errors while compiling, you might be using an incompatible protobuf compiler. If that's the case, use the following manual installation
Manual protobuf-compiler installation and usage
If you are on `linux`:
Download and install the 3.0 release of protoc, then unzip the file.
# From tensorflow/models/research/
wget -O protobuf.zip https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip
unzip protobuf.zip
Run the compilation process again, but use the downloaded version of protoc
# From tensorflow/models/research/
./bin/protoc object_detection/protos/*.proto --python_out=.
If you are on `MacOS`:
If you have homebrew, download and install the protobuf with brew install protobuf
Alternately, run:
curl -OL https://github.com/google/protobuf/releases/download/v3.3.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
rm -f $PROTOC_ZIP
Run the compilation process again:
# From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.
Add Libraries to PYTHONPATH
When running locally, the tensorflow/models/research/ and slim directories should be appended to PYTHONPATH. This can be done by running the following from tensorflow/models/research/:
# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
Note: This command needs to run from every new terminal you start. If you wish to avoid running this manually, you can add it as a new line to the end of your ~/.bashrc file, replacing `pwd` with the absolute path of tensorflow/models/research on your system.

Testing the Installation

You can test that you have correctly installed the Tensorflow Object Detection
API by running the following command:
python object_detection/builders/model_builder_test.py

No comments