"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

April 16, 2019

Day #241 - Tensorflow on CPU - Object Detection


Tensorflow on CPU
===================
Follow all steps in previous article,
#Not Needed CUDA
Step 2 - Cleanup Tensorflow
=============================
#Had to manually goto folder remove all packages named tf, tensorflow, tensorboard
#C:\Users\XXXXXX\AppData\Local\Continuum\anaconda3\envs\tflow\Lib\site-packages
pip install --ignore-installed --upgrade tensorflow
conda install jupyter
conda install scipy
Step 3 - Custom Training
=========================
Goto Link https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
Download http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz
C:\Tensorflow1\models\research\object_detection\faster_rcnn_inception_v2_coco_2018_01_28
Download code from https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10
Extract to C:\Tensorflow1\models\research\object_detection\TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10-master
Replace in C:\Tensorflow1\models\research\object_detection
Delete file in C:\Tensorflow1\models\research\object_detection\training, C:\Tensorflow1\models\research\object_detection\inference_graph, C:\Tensorflow1\models\research\object_detection\images (test and training label xls files)
Step#4 - Command
==================
cd C:\Tensorflow1\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
python setup.py build
python setup.py install
cd C:\Tensorflow1\models\research\object_detectiona
jupyter notebook object_detection_tutorial.ipynb




Finally was able to train Custom Object Detection



Notes on Custom Object Detection (Notes - Link )
Step #1 - Define Inputs - Specify files in TFRecord file format
Step #2 - Configure Train_config. Key Values are

  • Model parameter initialization.
  • Input preprocessing.
  • SGD parameters.

Step #3 - fine_tune_checkpoint should provide a path to the pre-existing checkpoint, To speed up the training process, it is recommended that users re-use the feature extractor parameters from a pre-existing image classification or object detection checkpoint
Step #4 - SGD - hyperparameters for gradient descent
Step #5 - Evaluator Config)

To get reasonable mAP@IoU scores for object detection API:

1. Try varying the Intersection over Union (IoU) threshold, e.g 0.2-0.5 and see if you get an increase in average precision. You would have to modify matching_iou_threshold parameter in object_detection/utils/object_detection_evaluation.py

2. Try different evaluator classes (the default one is EVAL_DEFAULT_METRIC = 'pascal_voc_detection_metrics'). If you are training on Open Image Dataset it makes sense to use open_images_V2_detection_metrics

3. Check your eval config file and increase the number of examples used in the evaluation set, e.g.

eval_config: {
  num_examples: 20000
  num_visualizations: 16
  min_score_threshold: 0.2
  # Note: The below line limits the evaluation process to 10 evaluations.
  # Remove the below line to evaluate indefinitely.
  max_evals: 1
}

4. Train the object detector for more iterations
5. Check current mAP against reported metrics (e.g. COCO mAP@IoU=0.5)

Step by Step: Build Your Custom Real-Time Object Detector  - Link
Detectron2 Train a Instance Segmentation Model
Installing the Tensorflow Object Detection API

For custom object training BMW has shared their opensource framework. It is a packaged version of the complete object detection setup. (Yolo / TensorFlow this is good set of tools)


I haven't experimented with it. This is a good place to leverage the setup as common tool.  This was released few months back. I am working in my windows setup for a while.

Happy Mastering DL!!!

No comments: