Training Custom Object using Tensorflow Object detection API on CPU- Part 5

Training Custom Object using Tensorflow Object detection API

Special thanks to pythonprogramming.net because I have seen their video while preparing this post so I feel my responsibility to give him the credit.

We are done with creating the xml file, csv file, record file and everything is set. If you not done with it, please read the below posts before reaching this.

Using Tensorflow Object Detection API with Pretrained model (Part1)

Creating XML file for custom objects- Object detection Part 2

Converting XML to CSV file- Custom Object detection Part 3

Creating test.record and train.record- Custom Object detection Part 4

Steps Involved are as below

    • Download the configuration file and model which is used to train the images. Make a new directory called training. Now you have following directories training, data, images. There are many models which can be downloaded. Please visit the link tensorflow detection model zoo to download  model you want. I will personally download the ssd_mobilenet_v1_coco_11_06_2017 model  and ssd_mobilenet_v1_pets.config because I am training on CPU and I have made a trade off between speed and accuracy.

  • FIles
    FIles
    • We have to make some changes in the file ssd_mobilenet_v1_pets.config . Please open it with any text editor (use sublime, nano, vim, gedit) and set the number of the classes = what ever you have labelled.

      model {
      ssd {
      num_classes: x #set the number of classes equals to whatever you have set labels like 1 for my case which is sunglasses

      GO to line where you find this code

      fine_tune_checkpoint: "PATH_TO_BE_CONFIGURED/model.ckpt"

      change this line to

      fine_tune_checkpoint: "ssd_mobilenet_v1_coco_11_06_2017/model.ckpt" #replace PATH_TO_BE_CONFIGURED with the name of the model you have downloaded.
      Now point to the following lines

      train_input_reader: {
      tf_record_input_reader {
      input_path: "PATH_TO_BE_CONFIGURED/pet_faces_train.record-?????-of-00010"
      }
      label_map_path: "PATH_TO_BE_CONFIGURED/pet_label_map.pbtxt"
      }
      Replace these lines with the following lines

      train_input_reader: {
      tf_record_input_reader {
      input_path: "data/train.record"
      }
      label_map_path: "training/object-detection.pbtxt"
      }
      Now Point to the next lines of the code as below

      tf_record_input_reader {
      input_path: "PATH_TO_BE_CONFIGURED/pet_faces_val.record-?????-of-00010"
      }
      label_map_path: "PATH_TO_BE_CONFIGURED/pet_label_map.pbtxt"

      Replace this with the following code

      tf_record_input_reader {
      input_path: "data/test.record"
      }
      label_map_path: "training/object-detection.pbtxt"
      Now please create a file object-detection.pbtxt inside the directory training which we have created and write the following lines in ititem {
      id: 1
      name: 'sunglasses' #I am showing my case
      }

      PLease note that both the ssd_mobilenet_v1_pets.config as well as object-detection.pbtxt must be inside the directory training.
    •  Please copy the directories images, data, training and ssd_mobilenet_v1_coco_11_06_2017 inside the directory models/research/object_detection and run the following command

      python3 train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config

      While I run the command I go the error NO module named deployment

      No Module Deployment
      No Module Deployment

      Donot worry, there is a solution to it

      Just come out of the directory object_detection and run the following command

      export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

      Come back again inside the directory object_detection and run the following command again
      python3 train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config
      </code?>

      I hope everything will work fine. I so you will see the result as below

      Training Process
      Training Process
    • Now you can also see the process in the tensorboard. It is very simple. Please see the below instruction.

      Just open another terminal and issue the below command in the directory models/reseach/object_detection


      tensorboard --logdir='training'

      You will get the link as http://xx-7520:6006. Please open it in the web browser and you will get access to the tensorboard where you will get the progress of each of your step. Please refer to below screeshot to know it more.

Progress at Tensorboard
Progress at Tensorboard

Thanks for sparing some time to read my post. Again special thanks goes to  pythonprogramming.net. I also suggest you to read the next tutorial on this sparking series by clicking on the link below

Tensor-flow checkpoint and Meta Graph

 

 

Advertisements

2 thoughts on “Training Custom Object using Tensorflow Object detection API on CPU- Part 5

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.