TensorFlow-object detection 目標檢測(三)

本文地址:https://blog.csdn.net/shanglianlm/article/details/80812849

1 將圖片數據轉換成TF-Record格式文件 

Pet數據 Generating the Oxford-IIIT Pet TFRecord files.
python dataset_tools/create_pet_tf_record.py \
    --label_map_path=object_detection/data/pet_label_map.pbtxt \
    --data_dir=H:/pythoncode/Tensorflow/ObjectDetection/data/pets \
    --output_dir=H:/pythoncode/Tensorflow/ObjectDetection/data/pets/record

VOC數據 Generating the PASCAL VOC TFRecord files
python dataset_tools/create_pascal_tf_record.py \
    --label_map_path=object_detection/data/pascal_label_map.pbtxt \
    --data_dir=H:/pythoncode/Tensorflow/ObjectDetection/data/VOCdevkit --year=VOC2012 --set=train \
    --output_path=H:/pythoncode/Tensorflow/ObjectDetection/data/VOCdevkit/record/pascal_train.record

python dataset_tools/create_pascal_tf_record.py \
    --label_map_path=object_detection/data/pascal_label_map.pbtxt \
    --data_dir=H:/pythoncode/Tensorflow/ObjectDetection/data/VOCdevkit --year=VOC2012 --set=val \
    --output_path=H:/pythoncode/Tensorflow/ObjectDetection/data/VOCdevkit/record/pascal_val.record

2 配置訓練參數 Configuring the Trainer

 目錄 ..\models\research\object_detection\samples\configs
 修改類別數 num_classes: 20
 
fine_tune_checkpoint: "H:/pythoncode/Tensorflow/ObjectDetection/data/ssd_mobilenet_v1_coco_2017_11_17/model.ckpt"


train_input_reader: {
  tf_record_input_reader {
    input_path: "H:/pythoncode/Tensorflow/ObjectDetection/data/VOCdevkit/train/pascal_train.record" #訓練數據生成的tfrecords文件
  }
  label_map_path: "H:/pythoncode/Tensorflow/ObjectDetection/data/pascal_label_map.pbtxt" #樣本的類別信息
}
 
eval_input_reader: {
  tf_record_input_reader {
    input_path: "H:/pythoncode/Tensorflow/ObjectDetection/data/VOCdevkit/val/pascal_val.record" #校驗數據生成的tfrecords文件
  }
  label_map_path: "H:/pythoncode/Tensorflow/ObjectDetection/data/pascal_label_map.pbtxt" #樣本的類別信息
  shuffle: false
  num_readers: 1


3 訓練Running the Training Job

python train.py \
    --logtostderr \
    --pipeline_config_path=H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\ssd_mobilenet_v1_coco.config \
    --train_dir=H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\train_log

4 驗證 Running the Evaluation Job

python eval.py \
    --logtostderr \
    --pipeline_config_path=H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\ssd_mobilenet_v1_coco.config \
    --checkpoint_dir=H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\train_log \
    --eval_dir=H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\val_log

5 Tensorboard Running Tensorboard

tensorboard --logdir=H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\train_log


6 導出訓練好的模型 Exporting a trained model for inference

python export_inference_graph.py \
    --input_type image_tensor \
    --pipeline_config_path H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\ssd_mobilenet_v1_coco.config \
    --trained_checkpoint_prefix H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\train_log\model.ckpt-3538 \

    --output_directory H:\pythoncode\Tensorflow\ObjectDetection\data\VOCdevkit\object_detection_graph

 參考資料:

tensorflow 輕鬆實現自己的目標檢測

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章