Instructions for training and evaluating networks from TensorFlow object detection model zoo for sign detection using the TT100K dataset. Tested on Ubuntu 16.04.5 LTS with Python 3.6, TensorFlow 1.12.0 and TensorFlow models v1.11.
If you are using AWS, follow the instructions here to set up an EC2 instance. Copy the TT100K dataset from S3 using
aws s3 sync s3://<path-to-tt100k>
If you're using a local GPU, skip this step.
Activate the in-built Conda environment for TensorFlow using
source activate <environment-name>
Refer the logs printed after you connect to the instance for the appropriate environment name.
Note that AWS Deep Learning AMIs come with TensorFlow preinstalled but not the object detection API.
- Clone the TensorFlow models repo from here.
mkdir tensorflow git clone <url>
- Follow the instructions [here] to complete the installation. You can use this script to install most of the dependencies. Make sure that you test the installation by running
from
python object_detection/builders/model_builder_test.py
tensorflow/models/research
. If you are getting errors, try reactivating the Conda environment. - If there are any CUDA linking issues while running the scripts, resolve them by running
sudo ldconfig /usr/local/cuda/lib64
Generate the label map .pbtxt file by running
python code/generate_label_map.py -d <path-to-TT100K-dataset-root-directory> -o <path-to-output-pbtxt-file>
Create training and test .record files by running
python create_tt100k_tf_record.py --data_dir=<path-to-TT100K-dataset-root-directory> --output_dir=<path-to-tfrecord-output-directory> --label_map_path=<path-to-label-map-pbtxt>
Here, output_dir
is the path to the directory where you want to store the .record files which the Python script will generate.
- Create a folder named
models
mkdir models cd models
- Download the model to be trained from the TensorFlow detection model zoo. For example, you can download SSD Mobilenet by running
wget http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz tar -xvzf ssd_mobilenet_v1_coco_2018_01_28.tar.gz
- Change the number of classes and set appropriate paths in
pipeline.config
. Refer the file for more details.
- Train the model by running the following command from the
tensorflow/models/research
directorypython object_detection/model_main.py --pipeline_config_path <path-to-model-config-file> --model_dir <path-to-output-directory>
- The above script does not print losses to the console. You can visualize training using TensorBoard by running
where the output directory is the same as used in the first step.
tensorboard --logdir=<path-to-output-directory>
- If training stops for some reason or the loss is high and you want to train further, use the latest checkpoint in the config file and insert the following line after
fine_tune_checkpoint
:This will reload the box predictor's weights along with those of the feature extractor.load_all_detection_checkpoint_vars: true