您的位置:首页 > 其它

tensorflow 目标检测训练及评估

2018-03-01 10:24 429 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: