tensorflow訓練Oxford-IIIT Pets
阿新 • • 發佈:2017-07-26
flow -i github hub 打開 cti infer val bject
參考鏈接https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_pets.md
先參考https://github.com/tensorflow/models/blob/master/object_detection/g3doc/installation.md安裝好環境
以下默認都在models目錄下操作
mkdir petstrain
註意PYTHONPATH庫路徑的設置
# From tensorflow/models/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
下載Oxford-IIIT Pets的圖片和標註信息
# From tensorflow/models/
cd petstrain
wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz
wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz
tar -xvf images.tar.gz
tar -xvf annotations.tar.gz
cd ..
轉換成TFRecord格式
# From tensorflow/models/
cp object_detection/data/pet_label_map.pbtxt petstrain/
python3 object_detection/create_pet_tf_record.py --label_map_path=petstrain/pet_label_map.pbtxt --data_dir=petstrain --output_dir=petstrain
在petstrain目錄生成pet_train.record pet_val.record
下載預訓練的模型
cd petstrain
wget http://storage.googleapis.com/download.tensorflow.org/models/object_detection/faster_rcnn_resnet101_coco_11_06_2017.tar.gz tar -xvf faster_rcnn_resnet101_coco_11_06_2017.tar.gz
mv faster_rcnn_resnet101_coco_11_06_2017/model.ckpt.* .
cd ..
修改配置文件
cp object_detection/samples/configs/faster_rcnn_resnet101_pets.config petstrain/
# From tensorflow/models/
# Edit the faster_rcnn_resnet101_pets.config template. Please note that there
# are multiple places where PATH_TO_BE_CONFIGURED needs to be set.
sed -i "s|PATH_TO_BE_CONFIGURED|petstrain|g" petstrain/faster_rcnn_resnet101_pets.config
訓練的目錄下會有以下文件
+ petstrain/
- faster_rcnn_resnet101_pets.config
- model.ckpt.index
- model.ckpt.meta
- model.ckpt.data-00000-of-00001
- pet_label_map.pbtxt
- pet_train.record
- pet_val.record
開始訓練
# From tensorflow/models/
python3 object_detection/train.py --logtostderr --pipeline_config_path=petstrain/faster_rcnn_resnet101_pets.config --train_dir=petstrain/res/
查看訓練進度
# From tensorflow/models/
tensorboard --logdir=pet-train/res/
打開瀏覽器localhost:6006
導出訓練好的圖
# From tensorflow/models/
object_detection/export_inference_graph.py --input_type image_tensor \
--pipeline_config_path petstrain/faster_rcnn_resnet101_pets.config \
--checkpoint_path petstrain/res/model.ckpt-445 \
--inference_graph_path petstrain/output_inference_graph.pb
這樣便得到output_inference_graph.pb文件
tensorflow訓練Oxford-IIIT Pets