深度学习实战tensorflow目标检测-4-代码修改

首先下载预训练模型

https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md

在这我使用Faster-RCNN-Inception-V2-COCO model

The last thing to do before training is to create a label map and edit the training configuration file.

1. Label map

The label map tells the trainer what each object is by defining a mapping of class names to class ID numbers. Use a text editor to create a new file and save it as labelmap.pbtxt in the C:\tensorflow1\models\research\object_detection\training folder. (Make sure the file type is .pbtxt, not .txt !) In the text editor, copy or type in the label map in the format below (the example below is the label map for my Pinochle Deck Card Detector):

item {
  id: 1
  name: 'tea'
}

item {
  id: 2
  name: 'x8'
}

item {
  id: 3
  name: 'coffee'
}

item {
  id: 4
  name: 'paper'
}

item {
  id: 5
  name: 'book'
}

The label map ID numbers should be the same as what is defined in the generate_tfrecord.py file

# TO-DO replace this with label map
def class_text_to_int(row_label):
    if row_label == 'tea':
        return 1
    elif row_label == 'x8':
        return 2
    elif row_label == 'coffee':
        return 3
    elif row_label == 'paper':
        return 4
    elif row_label == 'book':
        return 5
    else:
        None

 

 

2.Configure training(下面做相应的改变)

Finally, the object detection training pipeline must be configured. It defines which model and what parameters will be used for training. This is the last step before running training!

Navigate to C:\tensorflow1\models\research\object_detection\samples\configs and copy the faster_rcnn_inception_v2_pets.config file into the \object_detection\training directory. Then, open the file with a text editor. There are several changes to make to the .config file, mainly changing the number of classes and examples, and adding the file paths to the training data.

Make the following changes to the faster_rcnn_inception_v2_pets.config file. Note: The paths must be entered with single forward slashes (NOT backslashes), or TensorFlow will give a file path error when trying to train the model! Also, the paths must be in double quotation marks ( " ), not single quotation marks ( ' ).

  • Line 9. Change num_classes to the number of different objects you want the classifier to detect. For the above basketball, shirt, and shoe detector, it would be num_classes : 3 .

  • Line 110. Change fine_tune_checkpoint to:

    • fine_tune_checkpoint : "C:/tensorflow1/models/research/object_detection/faster_rcnn_inception_v2_coco_2018_01_28/model.ckpt"
  • Lines 126 and 128. In the train_input_reader section, change input_path and label_map_path to:

    • input_path : "C:/tensorflow1/models/research/object_detection/train.record"
    • label_map_path: "C:/tensorflow1/models/research/object_detection/training/labelmap.pbtxt"
  • Line 132. Change num_examples to the number of images you have in the \images\test directory.

  • Lines 140 and 142. In the eval_input_reader section, change input_path and label_map_path to:

    • input_path : "C:/tensorflow1/models/research/object_detection/test.record"
    • label_map_path: "C:/tensorflow1/models/research/object_detection/training/labelmap.pbtxt"

Save the file after the changes have been made. That’s it! The training job is all configured and ready to go!

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值