##windows 10 . anaconda python3.6 . using anaconda prompt
in my case I use google images to find [chinook] photos , I gather 200 sample
convert all images extensoins to xx.jpg
, using Format Factory http://www.pcfreetime.com/
go to images directory in my case chinook
and type in cmd python renameFiles.py
using labelImg
https://github.com/tzutalin/labelImg
unzip labelImg
run cmd and go to labelImg dir
conda install pyqt=5
pyrcc5 -o resources.py resources.qrc
python labelImg.py
all my samples = 200 ,130 for train ,70 for test
pip install --upgrade tensorflow-gpu
conda create -n tensorflow1 pip python=3.5
activate tensorflow1
pip install --ignore-installed --upgrade tensorflow-gpu
other necessary packages
(tensorflow1) C:\> conda install -c anaconda protobuf
(tensorflow1) C:\> pip install pillow
(tensorflow1) C:\> pip install lxml
(tensorflow1) C:\> pip install Cython
(tensorflow1) C:\> pip install jupyter
(tensorflow1) C:\> pip install matplotlib
(tensorflow1) C:\> pip install pandas
(tensorflow1) C:\> pip install opencv-python
https://github.com/tensorflow/models.git
https://github.com/seraj94ai/Train-Object-Detection-Classifier.git
unzip folder and copy paste in C:\tensorflow1\models\research\object_detection
open cmd
cd C:\tensorflow1\models\research\object_detection
mkdir images
mkdir inference_graph
mkdir training
Configure PYTHONPATH environment variable set PYTHONPATH=D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models;D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models\research;D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models\research\slim
Protobuf (Protocol Buffers) libraries must be compiled , it used by TensorFlow to configure model and training parameters
Open Anaconda Prompt and go to C:\tensorflow1\models\research
cd /d D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models\research
protoc --python_out=. .\object_detection\protos\anchor_generator.proto .\object_detection\protos\argmax_matcher.proto .\object_detection\protos\bipartite_matcher.proto .\object_detection\protos\box_coder.proto .\object_detection\protos\box_predictor.proto .\object_detection\protos\eval.proto .\object_detection\protos\faster_rcnn.proto .\object_detection\protos\faster_rcnn_box_coder.proto .\object_detection\protos\grid_anchor_generator.proto .\object_detection\protos\hyperparams.proto .\object_detection\protos\image_resizer.proto .\object_detection\protos\input_reader.proto .\object_detection\protos\losses.proto .\object_detection\protos\matcher.proto .\object_detection\protos\mean_stddev_box_coder.proto .\object_detection\protos\model.proto .\object_detection\protos\optimizer.proto .\object_detection\protos\pipeline.proto .\object_detection\protos\post_processing.proto .\object_detection\protos\preprocessor.proto .\object_detection\protos\region_similarity_calculator.proto .\object_detection\protos\square_box_coder.proto .\object_detection\protos\ssd.proto .\object_detection\protos\ssd_anchor_generator.proto .\object_detection\protos\string_int_label_map.proto .\object_detection\protos\train.proto .\object_detection\protos\keypoint_box_coder.proto .\object_detection\protos\multiscale_anchor_generator.proto .\object_detection\protos\graph_rewriter.proto .\object_detection\protos\calibration.proto
just on time
cd /d D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models\research
python setup.py build
python setup.py install
Test TensorFlow setup to verify it works
cd /d D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models\research\object_detection
jupyter notebook object_detection_tutorial.ipynb
TFRecords is an input data to the TensorFlow training model
creat .csv
files from .xml
files
cd /d D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models\research\object_detection
python xml_to_csv.py
This creates a train_labels.csv
and test_labels.csv
file in the \object_detection\images
folder.
edit generate_tfrecord.py
and put your classes names
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
go to \data
copy pet_label_map.pbtxt
to \training
dir and rename it to labelmap.pbtxt
edit it to your class chinook
cd C:\tensorflow1\models\research\object_detection\samples\configs
copy faster_rcnn_inception_v2_pets.config
past it in \training
dir and edit it
In the model
section change num_classes
to number of different classes
fine_tune_checkpoint : C:/tensorflow1/models/research/object_detection/faster_rcnn_inception_v2_coco_2018_01_28/model.ckpt
In the train_input_reader
section change input_path
and label_map_path
as :
Input_path : C:/tensorflow1/models/research/object_detection/train.record
Label_map_path: C:/tensorflow1/models/research/object_detection/training/labelmap.pbtxt
In the eval_config
section change num_examples
as :
Num_examples = number of files in \images\test
directory.
In the eval_input_reader
section change input_path
and label_map_path
as :
Input_path : C:/tensorflow1/models/research/object_detection/test.record
Label_map_path: C:/tensorflow1/models/research/object_detection/training/labelmap.pbtxt
in training folder we have a folder that is result of extracting downloaded model e.g ssd_inception_v2_coco_2018_01_28 label_map.pbtxt sth like cofiguration file
cd /d D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models\research\object_detection
python train.py --logtostderr --train_dir=training/dir --pipeline_config_path=training/ssd_inception_v2_coco.config
in cmd type cd /d D:\AI\object-detection\tf_api\workspace\Train-Object-Detection-Classifier-master\models\research\object_detection tensorboard --logdir=training
training is complete ,the last step is to generate the frozen inference graph (.pb file) change “XXXX” in “model.ckpt-XXXX” should be replaced with the highest-numbered .ckpt file in the training folder:
clean inference_graph folder in object detection
python export_inference_graph.py --input_type image_tensor --pipeline_config_path training//ssd_inception_v2_coco.config --trained_checkpoint_prefix training/dir/model.ckpt-2000 --output_directory inference_graph
You can use “echo %PATH%” and “echo %PYTHONPATH%” to check the environment variables and make sure they are set up correctly.
Also, make sure you have run these commands from the \models\research
directory:
setup.py build
setup.py install
ImportError: cannot import name 'string_int_label_map_pb2' (or similar errors with other pb2 files) This occurs when the protobuf files (in this case, preprocessor.proto) have not been compiled go to step 12
in C:\tensorflow1\models\research\object_detection\utils\learning_schedules.py
replace range(num_boundaries)
to [i for i in range(num_boundaries)]
(tensorflow1) C:\tensorflow1\models\research> python setup.py build
(tensorflow1) C:\tensorflow1\models\research> python setup.py install
in C:\tensorflow1\models\research\object_detection\generate_tfrecord.py
replace [else: None]
by [else: return 0]