tensorflow 目標檢測訓練及評估
阿新 • • 發佈:2019-01-28
基於tensorflow訓練車輛檢測器原始碼已上傳github,裡面集成了一鍵式訓練的指令碼。
0.硬體,一塊1080Ti及以上顯示卡的機器,不建議用CPU訓練。
1.安裝gpu版tensorflow,並搭建訓練環境
sudo pip install tensorflow-gpu
sudo pip install pillow
sudo pip install lxml
sudo pip install jupyter
sudo pip install matplotlib
git clone https://github.com/tensorflow/models
將目錄切換至tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
測試安裝是否成功
python object_detection/builders/model_builder_test.py
確保返回OK
2.準備訓練資料
切換目錄至tensorflow/models/research/
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 annotations.tar.gz tar -xvf images.tar.gz python object_detection/dataset_tools/create_pet_tf_record.py \ --label_map_path=object_detection/data/pet_label_map.pbtxt \ --data_dir=`pwd` \ --output_dir=`pwd`
3.將資料轉換為tfrecords
python object_detection/dataset_tools/create_pet_tf_record.py \
--label_map_path=object_detection/data/pet_label_map.pbtxt \
--data_dir=`pwd` \
--output_dir=`pwd`
4.訓練模型,參考連結https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_locally.md
cp object_detection/samples/configs/ssd_mobilenet_v1_pets.config ssd_mobilenet_v1_pets.config
修改ssd_mobilenet_v1_pets.config中PATH_TO_BE_CONFIGURED的值為本機的路徑
下載預訓練的模型,參考連結https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
wget http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2017_11_17.tar.gz
解壓到當前目錄:
tar -zvxf ssd_mobilenet_v1_coco_2017_11_17.tar.gz
python object_detection/train.py \
--logtostderr \
--pipeline_config_path=ssd_mobilenet_v1_pets.config \
--train_dir=voc/train_logs \
2>&1 | tee voc/train_logs.txt
5.評估模型
python object_detection/eval.py \
--logtostderr \
--pipeline_config_path=ssd_mobilenet_v1_pets.config \
--checkpoint_dir=voc/train_logs \
--eval_dir=voc/eval_logs