【TensorFlow学习笔记】目标识别篇(五):基于Faster-rcnn-tensorflow-python3.5-master打造属于自己的物体检测模型

一、环境配置

win10系统,显卡GeForce GTX 960M;
TensorFlow-gpu 1.13.0-rc2,CUDA 10.0,Cudnn 7.4.2;
python 3.6

Tensorflow-gpu是在windows PowerShell里用pip安装的,同时安装一些必要的库:cython、easydict、matplotlib、python-opencv等,可直接使用pip安装或者下载相应的.whl离线文件安装。

  • Faster RCNN下载

下载地址https://github.com/dBeker/Faster-RCNN-TensorFlow-Python3.5

下载完成后,项目的根目录为:Faster-RCNN-TensorFlow-Python3.5-master

cd到Faster-RCNN-TensorFlow-Python3.5-master\data\coco\PythonAPI目录下,打开cmd,运行编译提供的代码:

python setup.py build_ext --inplace
python setup.py build_ext install

二、准备数据集

图片分辨率500x350
训练模型部分:
需要更改的主要有以下地方:

1.在…\Faster-RCNN\data目录下,检查是否有个叫cache的文件夹,每次在训练模型前,建议清空这个文件夹里面的东西。

2.在…\Faster-RCNN\data目录下,将VOCDevkit2007替换成自己的数据集。(如果有需要,以后我在写如何制作自己的VOC数据集)

3.在…\Faster-RCNN\lib\config目录下,有个config.py文件,可以设置一些参数,比如learning_rate、max_iters、batch_size、step_size等等,这个可以根据自己需求改。比如,显卡性能一般的话,可以适当降低batch_size,觉得默认设置的max_iters迭代次数不够的话,可以改成七万等。

4.在…\Faster-RCNN\lib\datasets目录下,有pascal_voc.py文件,这个是必须要更改的,代码中 self._classes要来指定识别的类别,如下所示

三、模型下载

  • VGG16模型的下载地址:http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz,也可去百度云盘下载,
    链接:https://pan.baidu.com/s/11Ty10NJ-rgXkkvM92SVVKw ,提取码:d2jz
    下载完后解压,文件重命名为vgg16.ckpt,如图2所示。新建文件夹imagenet_weights,把vgg16.ckpt放到imagenet_weights下,再将imagenet_weights文件夹复制到data文件夹下。文件夹目录:
    Faster-RCNN-TensorFlow-Python3.5-master\data\imagenet_weights\vgg16.ckpt

在这里插入图片描述

  • resnet模型下载

四、 训练模型

训练模型的参数可以在Faster-RCNN-TensorFlow-Python3.5-master\lib\config文件夹里的config.py修改,包括训练的总步数、权重衰减、学习率、batch_size等参数。

tf.app.flags.DEFINE_float('weight_decay', 0.0005, "Weight decay, for regularization")
tf.app.flags.DEFINE_float('learning_rate', 0.001, "Learning rate")
tf.app.flags.DEFINE_float('momentum', 0.9, "Momentum")
tf.app.flags.DEFINE_float('gamma', 0.1, "Factor for reducing the learning rate")
 
tf.app.flags.DEFINE_integer('batch_size', 128, "Network batch size during training")
tf.app.flags.DEFINE_integer('max_iters', 40000, "Max iteration")
tf.app.flags.DEFINE_integer('step_size', 30000, "Step size for reducing the learning rate, currently only support one step")
tf.app.flags.DEFINE_integer('display', 20, "Iteration intervals for showing the loss during training, on command line interface")
 
tf.app.flags.DEFINE_string('initializer', "truncated", "Network initialization parameters")
tf.app.flags.DEFINE_string('pretrained_model', "./data/imagenet_weights/vgg16.ckpt", "Pretrained network weights")
 
tf.app.flags.DEFINE_boolean('bias_decay', False, "Whether to have weight decay on bias as well")
tf.app.flags.DEFINE_boolean('double_bias', True, "Whether to double the learning rate for bias")
tf.app.flags.DEFINE_boolean('use_all_gt', True, "Whether to use all ground truth bounding boxes for training, "
                                                "For COCO, setting USE_ALL_GT to False will exclude boxes that are flagged as ''iscrowd''")
tf.app.flags.DEFINE_integer('max_size', 1000, "Max pixel size of the longest side of a scaled input image")
tf.app.flags.DEFINE_integer('test_max_size', 1000, "Max pixel size of the longest side of a scaled input image")
tf.app.flags.DEFINE_integer('ims_per_batch', 1, "Images to use per minibatch")
tf.app.flags.DEFINE_integer('snapshot_iterations', 5000, "Iteration to take snapshot")

参数调整完后,在Faster-RCNN-TensorFlow-Python3.5-master的目录下,运行 python train.py,就可以训练

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值