目标物检测_tensorflow_object_dection


一、背景介绍

1. 应用场景

a. 计数: 统计人,车,花甚至是微生物数量,在大部分基于图像的系统中都要使用,尤其广泛应用于监控视频设备系统

b. 视觉搜索引擎:目标检测作为索引图像内容的处理流程之一。比如,你可以在不同的背景下找到某个特定的钱包

c. 空中影像分析:应用无人机摄像对人难以到达的地方进行自动监测(例如BetterView)或者使用物体检测方法进行整体分析(例如TensorFlight)

2. 深度学习模型进阶流程

a. overfit:

b.RCNN

c. fast-RCNN

d.YOLO

e.faster-RCNN

f.SSD 

g.R-FCN

3. 数据集

a. ImageNet

b. COCO

c. Pascal VOC

d.Oxford-IIIT Pet

e.KITTI Vision

二、模型版本

https://github.com/tensorflow/models/tree/266c7b87251dac41e977f3167f39078954f609dd/research/object_detection

三、走通版本3 (tensorflow 官网)

3.1 安装环境

a. 下载代码

git clone https://github.com/tensorflow/models.git

b. 安装

sudo apt-get install protobuf-compiler python-pil python-lxml

sudo pip install jupyter

sudo pip install matplotlib

c. 配置环境

# From tensorflow/models/research/

protoc object_detection/protos/*.proto --python_out=.

# From tensorflow/models/research/

export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

每次打开命令框需要重新输入export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

#######################################################################################

配置路径,开机启动,自动遍历此文件的指令
1>. home/coolpad/.bashr最下方增加:
export PYTHONPATH=$PYTHONPATH:/home/coolpad/models/research:/home/coolpad/models/research/slim
2>. 开机重启生效,不重启则需要在命令框运行source /home/coolpad/.bashrc

########################################################################################

d.查看是否配置成功

python object_detection/builders/model_builder_test.py

成功则出现:Ran 11 tests in 0.026s OK

3.2 使用API训练模型

利用 TF Object Detection API 用COCO-pretrained Faster R-CNN with Resnet-101 model 预训练迁移训练一个 Faster RCNN 目标检测模型,使用faster_rcnn_resnet101网络训练 Oxford-IIIT 宠物数据集

a. 下载训练集

下载图片:wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz     

解压图片:tar -xvf images.tar.gz

下载标注文件:wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz

解压标注文件:tar -xvf annotations.tar.gz

b.转tfrecord

python object_detection/create_pet_tf_record.py \

--label_map_path=object_detection/data/pet_label_map.pbtxt \

--data_dir=`pwd` \

 --output_dir=`pwd`

c. 下载预训练的权重

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

e. 建立训练文件夹

在任何路径mkdir my_train

将转换的pet_train.record、pet_val.record复制到此文件夹

将object_detection/data/pet_label_map.pbtxt复制到此文件夹

object_detection/samples/configs/faster_rcnn_resnet101_pets.config复制到此文件夹

f. 修改faster_rcnn_resnet101_pets.config代码路径

将所有的PATH_TO_BE_CONFIGURED替换为my_train 的路径

将fine_tune_checkpoint: "×××××××" 的×××××替换成下载的预训练权重的路径

g.运行训练

cd /root/myfloder/models/research python3 object_detection/train.py \

--logtostderr \ --pipeline_config_path='./my_train/faster_rcnn_resnet152_pets.config' \

--train_dir='./my_train'

#####################################################################

从头开始训练模型:

将  fine_tune_checkpoint: "20170820/model.ckpt"

from_detection_checkpoint: true 改成false

#####################################################################

3.4 查看训练数据:

tensorboard --logdir='./20180210'

3.5 评估训练好的网络

python3 object_detection/eval.py\

--logtostderr \ --pipeline_config_path='./my_train/faster_rcnn_resnet152_pets.config' \

--checkpoint_dir='./my_train/' \

--eval_dir='./my_train/'

以上的步骤已经走通迁移训练

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM