Detecting custom objects

You can download the code on the GitHub page ( link )





Welcome to the article on recognition. Since I spend most of my work time in an open space office space, where each place is numbered, I decided to tell you about computer vision using the example of a regular plate with a workplace number. Here we will retrain the neural network to detect the plate of our choice.





I am using python3.7 and the names of all versioned modules are stored in the requirements.txt file.





.





:





  • 500 , โ€” 100, 1000 , , 2.





  • / . 80%, - 20%.





  • TF .





  • . config ( , ).





  • .





  • .





  • .





TensorFlow , , 1000 . , , . , , - .





, ().





. , . LabelImg- , GitHub , .





LabelImg GitHub ()





LabelImg ()





LabelImg, GUI. โ€” dir , . create rectbox. , . , ! w, , ctrl+s, . 1 100 , , . , !





LabelImg xml-, . xml- TFRecords, TensorFlow. , , \test \train xml-.





, . , 20% XML- test, train.





, , TFRecords, TensorFlow.





-, image .xml csv-, . , : python xml_to_csv.py.





train_labels.csv test_labels.csv CSGO_images. cmd, .bat xml_to_csv.bat.





generate_tfrecord.py . , . labelmap.pbtxt.





, , generate_tfrecord.py:





# TO-DO    label map
def class_text_to_int(row_label):
    if row_label == 'table':
        return 1
    else:
        return None
      
      



TFRecord, generate_tfrecord.bat.





train.record test.record training. .





, โ€” . , , . labelmap.pbtxt CSGO_training. . , generate_tfrecord.py.





item {
 id: 1
 name: 'table'
}
      
      



, . , . .





TensorFlow research\ object_detection\ samples\ configs faster_rcnn_ inception_v2_ coco.config CSGO_training. . .config , , . 10. num_classes , . :





num_classes : 1
 107.  fine_tune_checkpoint :
fine_tune_checkpoint : "faster_rcnn_inception_v2_coco_2018_01_28 / model.ckpt"
 122  124.   train_input_reader  input_path  label_map_path :
input_path: "CSGO_images / train. record"
label_map_path: "CSGO_training / labelmap.pbtxt"
 128.  num_examples   ,    CSGO_images\test.    113 ,     :
num_examples: 113
(   )
 136  138.   eval_input_reader  input_path  label_map_path :
input_path: "CSGO_images / test. record"
label_map_path: "CSGO_training / labelmap.pbtxt"
      
      



. ! . .





, train.bat.





. . 1.5 . , 0,05, ( , ). , . , , .





.





, , โ€” ( ). graph export_inference_graph.py,   , โ€œXXXXโ€ โ€ model.ckpt-XXXX ยป .ckpt :





python export_inference_graph.py --input_type image_tensor --pipeline_config_path CSGO_training/faster_rcnn_inception_v2_coco.config --trained_checkpoint_prefix CSGO_training/model.ckpt-XXXX --output_directory CSGO_inference_graph
      
      



frozen_inference_graph.pb /coco_v3/ CSGO_inference_ graph. .pb . frozen_inference_graph.pb . coco_v3 predict.py 39 .





PATH_TO_FROZEN_GRAPH = 'graph/frozen_inference_graph.pb'
      
      



41 labelmap.





PATH_TO_LABELS = 'graph/labelmap.pbtxt'
      
      



Finally, before running Python scripts, you need to change the NUM_CLASSES variable in the script to equal the number of classes we want to detect. I only use 1 class, so I changed it to 1:

NUM_CLASSES = 1





In line 65, you need to set the picture on which the detection will take place.





After starting, you will see a window and a recognized plate.





That's all, thanks for your attention.








All Articles