tf41:使用TF models训练自己的目标检测器

MachineLP的Github(欢迎follow):https://github.com/MachineLP

(1)目标检测样本集的标定: https://github.com/MachineLP/labelImg
(2) 生成训练集和测试集的txt文件: https://github.com/MachineLP/tf-faster-rcnn/blob/master/tools/g_img_path.py
(3)按照pascal_voc的格式组织

tensorflow/models-research-object_detection, 使用说明: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_pets.md

# From tensorflow/models/
(ubuntu下安装 protobufhttps://blog.csdn.net/xiexievv/article/details/47396725)protoc object_detection/protos/*.proto --python_out=.
# From tensorflow/models/research/ python setup.py sdist(cd slim && python setup.py sdist)

(4)生成tfRecords:
( export PYTHONPATH=$PYTHONPATH: `pwd` : `pwd`)
python object_detection/dataset_tools/create_pascal_tf_record.py --label_map_path=object_detection/data/pascal_label_map.pbtxt --data_dir=object_detection/VOCdevkit --year=VOC2012 --set=train --output_path=object_detection/train/pascal_train.record

(5)train文件夹的目录:
train:
pascal_train.record
pascal_val.record
faster_rcnn_inception_v2_coco.config (samples/configs) (参数、训练路径和测试路径)
pascal_label_map.pbtxt (data/)
mode.ckpt*

(6)开始训练:
python object_detection/train.py --logtostderr --pipeline_config_path=object_detection/train/faster_rcnn_inception_v2_coco.config --train_dir=object_detection/train

之后会遇到一个bug:
Tried to convert 't' to a tensor and failed. Error: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted [].


(7) 转 pb文件:
python object_detection/export_inference_graph.py --pipeline_config_path object_detection/train/faster_rcnn_inception_v2_coco.config --trained_checkpoint_prefix object_detection/train/model.ckpt-1072 --output_directory object_detection/train

(8)进行测试:
pythonw object_detection_tutorial.py

(9) 训练监控有没有新的权重保存:
python object_detection/eval.py --logtostderr --pipeline_config_path=object_detection/train/faster_rcnn_inception_v2_coco.config --checkpoint_dir=object_detection/train --eval_dir=object_detection/val

(10)使用tensorboard查看结果:
tensorboard --logdir val

猜你喜欢

转载自blog.csdn.net/u014365862/article/details/80875435
tf