- Make sure you have the prerequisites for the Object Detection API installed. The directions for installations can be found here
For Santa Claus
- Download the training images in character-finder/characters directory and evaluation images in the characterfinder/eval_image directory
This only downloads the images for Santa Claus.
Run the following commands
# Unzip the contents
# From character-finder/characters
unzip santa.zip
# From character-finder/eval_images
unzip santa.zip
# From character-finder/
python change_csv.py
# This will change the path in the already existing csvs to point to the images in the correct directory
For Other Characters
-
Make a new directory in the character-finder/characters folder and name it the character. For example
mkdir characters/foobar
Similarly do the same for the evaluation images
mkdir eval_images/foobar
-
Save all training images for that character in
characters/foobar
and the evaluation images ineval\_images/foobar
-
Next step is to get bounding box imformation about the characters and store it in a csv which will later be converted to tf.record file. Done for both training and evaluation images.
-
Run the following command
# For Training Images python detect_labels.py --annotation_file PATH_TO_CSV --images characters/ # For Evaluation Images python detect_labels.py --annotation_file PATH_TO_CSV --images eval_images/
Note: Already existing train.csv and eval.csv have bounding box information for images of Santa Claus
- After generating csv, generate the record files
# Generate training record python --csv_input PATH_TO_TRAIN_CSV --output_path PATH_TO_TRAIN.record --label_map_path characters_label_map.pbtext
# Generate evaluation record python --csv_input PATH_TO_EVAL_CSV --output_path PATH_TO_EVAL.record --label_map_path characters_label_map.pbtext
For training, construct an object-detection training pipeline.
-
Use any of the config files present in object_detection/samples/configs/ as basis
-
Changes in the .config file:
- Adjust the number of classes depending on the number of characters training on
2 It is recommended to train the model from a pre-trained checkpoint. Tensorflow provides several pre-trained checkpoints which can be found here.
Change the
fine_tune_checkpoint: "PATH_TO_BE_CONFIGURED/model.ckpt"
to point to the checkpoint to be used - In the following Code snippet
Change the
train_input_reader: { tf_record_input_reader { input_path: "PATH_TO_BE_CONFIGURED/train.record" } label_map_path: "characters_label_map.pbtxt" }
input_path: "PATH_TO_BE_CONFIGURED/train.record"
to point to the full path of the train.record file created in the previous step and thelabel_map_path: "PATH_TO_BE_CONFIGURED/characters_label_map.pbtxt"
to point to the full path of the label map. - In the following Code snippet
Change the
eval_input_reader: { tf_record_input_reader { input_path: "PATH_TO_BE_CONFIGURED/eval.record" } label_map_path: "PATH_TO_BE_CONFIGURED/characters_label_map.pbtxt" shuffle: false num_readers: 1 num_epochs: 1 }
input_path: "PATH_TO_BE_CONFIGURED/eval.record"
to point to the full path of the eval.record file created in the previous step and thelabel_map_path: "PATH_TO_BE_CONFIGURED/characters_label_map.pbtxt"
to point to the full path of the label map.
- Adjust the number of classes depending on the number of characters training on
2 It is recommended to train the model from a pre-trained checkpoint. Tensorflow provides several pre-trained checkpoints which can be found here.
-
Run the training job
python object_detection/train.py --logtostderr --train_dir PATH_TO_SAVE_CHECKPOINTS --pipeline_config_path PATH_TO_CONFIG_FILE
-
It is advised to run the evaluation job simultaneously with the training.
python object_detection/eval.py --logtostderr --checkpoint_dir PATH_TO_CHECKPOINT_DIR --eval_dir PATH_TO_EVAL_DIR --pipeline_config_path PATH_TO_CONFIG_FILE
-
Visualise the training and evaluation by running the folowing command
tensorboard --logdir PATH_TO_CHECKPOINT_DIR
- To export the model, choose a checkpoint # to export. For example to export checkpoint no. 130912
python object_detection/export_inference_graph --input_type image_tensor --pipeline_congif_path PATH_TO_CONFIG_FILE --trained_checkpoint_prefix PATH_TO_CHECKPOINT/model.ckpt-130912 --output_directory PATH_TO_EXPORT_MODEL