Training Custom object (knife) detection in Tensorflow object Detection API
-
Download Tensorflow Repository models: https://github.com/tensorflow/models
-
Download model: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
-
Clone the following Repo: https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10
# labelImg (Python2)
sudo apt-get install pyqt4-dev-tools
sudo pip install lxml
make qt4py2
python labelImg.py
# Run the following in Paperspace VM
sudo pip2 install tensorflow==1.5.0
sudo apt-get install protobuf-compiler python-pil python-lxml python-tk
export PYTHONPATH=~/Desktop/tf_training/models:$PYTHONPATH
export PYTHONPATH=~/Desktop/tf_training/models/research:$PYTHONPATH
export PYTHONPATH=~/Desktop/tf_training/models/research/slim:$PYTHONPATH
# Run the following from models/research:
protoc object_detection/protos/*.proto --python_out=.
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
-
Extract contents of models in ~Deskop/tf_training
-
Extract "faster_rcnn_inception_v2_coco" in models/research/object_detection
-
Extract the contents of "TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10" to object_detection
-
Empty the following directories: a) training b) inference_graph c) images/test d) images/train
-
Create xml annotations using label_image/program/labelImg.py
-
Convert xml annotations to csv by running the following in reference_code:
python xml_to_csv.py
-
Generate tf.record files for both test and train labels by running the following in reference_code:
python generate_tfrecord.py --csv_input=images/train_labels.csv --image_dir=images/train --output_path=train.record python generate_tfrecord.py --csv_input=images/test_labels.csv --image_dir=images/test --output_path=test.record
-
Create labelmap-"labelmap.pbtxt" and training configuration file-"faster_rcnn_inception_v2_pets.config"
-
Copy training_files contents to object_detection directory and start training by using following command:
python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config
-
Export the inference_graph (trained model):
python export_inference_graph.py --input_type image_tensor --pipeline_config_path training/faster_rcnn_inception_v2_pets.config --trained_checkpoint_prefix training/model.ckpt-XXXX --output_directory inference_graph