关键词:
说明:本博文假设你已经做好了自己的数据集,该数据集格式和VOC2007相同。下面是训练前的一些修改。
(做数据集的过程可以看http://blog.csdn.net/sinat_30071459/article/details/50723212)
Faster-RCNN源码下载地址:
Matlab版本:https://github.com/ShaoqingRen/faster_rcnn
Python版本:https://github.com/rbgirshick/py-faster-rcnn
本文用到的是Matlab版本,在Windows下运行。
python版本的训练过程:http://blog.csdn.net/sinat_30071459/article/details/51332084
资源下载:https://github.com/ShaoqingRen/faster_rcnn,网页最后有所有的资源。
准备工作:
(1)
安装vs2013;
安装Matlab;
安装CUDA;
上面的安装顺序最好不要乱,否则可能出现Matlab找不到vs的情况,在Matlab命令行窗口输入:mbuild -setup,如果出现:
说明Matlab可以找到vs2013。CUDA应在安装vs2013后再安装。
(2)
如果你的cuda是6.5,那么,运行一下:
- fetch_data/fetch_caffe_mex_windows_vs2013_cuda65.m
(运行代码下载失败的话,用百度云下载:https://pan.baidu.com/s/1i3m0i0H ,解压到faster_rcnn-master下)
得到mex文件。如果不是cuda6.5(如我的是cuda7.5),则需要自己编译mex文件,编译过程参考这里:Caffe for Faster R-CNN,按步骤做就行了。
也可以下载我编译得到的文件(注意cuda版本)。
下载地址:Faster-RCNN(Matlab) external文件夹
建议还是自己编译,因为版本问题可能会出错。在训练前,可以先下载作者训练好的模型,测试一下,如果可以的话,就不用自己编译了。
测试过程:
(1)运行faster_rcnn-masterfaster_rcnn_build.m
(2)运行faster_rcnn-masterstartup.m
(3)运行faster_rcnn-masterfetch_datafetch_faster_rcnn_final_model.m 下载训练好的模型
(下载失败的话,可以用百度云下载:https://pan.baidu.com/s/1hsFKmeK ,解压到faster_rcnn-master下)
(4)修改faster_rcnn-masterexperimentsscript_faster_rcnn_demo.m的model_dir为你下载的模型,然后运行。
最终得到:
在训练前请确保你的路径faster_rcnn-masterexternalcaffematlabcaffe_faster_rcnn下有以下文件:
(我的OpenCV版本是2.4.9,cuda版本是7.5,因版本不同上述文件和你的编译结果可能会有差异。+caffe文件夹是从caffe-master或caffe-faster-R-CNN里拷贝过来的。)
如果你没有按上面说的测试过,请先运行:
(1)faster_rcnn-masterfaster_rcnn_build.m
(2)faster_rcnn-masterstartup.m
然后再进行下面的修改。
1 、VOCdevkit2007VOCcodeVOCinit.m的修改
(1)路径的修改
说明:本博文假设你已经做好了自己的数据集,该数据集格式和VOC2007相同。下面是训练前的一些修改。
(做数据集的过程可以看http://blog.csdn.net/sinat_30071459/article/details/50723212)
Faster-RCNN源码下载地址:
Matlab版本:https://github.com/ShaoqingRen/faster_rcnn
Python版本:https://github.com/rbgirshick/py-faster-rcnn
本文用到的是Matlab版本,在Windows下运行。
python版本的训练过程:http://blog.csdn.net/sinat_30071459/article/details/51332084
资源下载:https://github.com/ShaoqingRen/faster_rcnn,网页最后有所有的资源。
准备工作:
(1)
安装vs2013;
安装Matlab;
安装CUDA;
上面的安装顺序最好不要乱,否则可能出现Matlab找不到vs的情况,在Matlab命令行窗口输入:mbuild -setup,如果出现:
说明Matlab可以找到vs2013。CUDA应在安装vs2013后再安装。
(2)
如果你的cuda是6.5,那么,运行一下:
- fetch_data/fetch_caffe_mex_windows_vs2013_cuda65.m
(运行代码下载失败的话,用百度云下载:https://pan.baidu.com/s/1i3m0i0H ,解压到faster_rcnn-master下)
得到mex文件。如果不是cuda6.5(如我的是cuda7.5),则需要自己编译mex文件,编译过程参考这里:Caffe for Faster R-CNN,按步骤做就行了。
也可以下载我编译得到的文件(注意cuda版本)。
下载地址:Faster-RCNN(Matlab) external文件夹
建议还是自己编译,因为版本问题可能会出错。在训练前,可以先下载作者训练好的模型,测试一下,如果可以的话,就不用自己编译了。
测试过程:
(1)运行faster_rcnn-masterfaster_rcnn_build.m
(2)运行faster_rcnn-masterstartup.m
(3)运行faster_rcnn-masterfetch_datafetch_faster_rcnn_final_model.m 下载训练好的模型
(下载失败的话,可以用百度云下载:https://pan.baidu.com/s/1hsFKmeK ,解压到faster_rcnn-master下)
(4)修改faster_rcnn-masterexperimentsscript_faster_rcnn_demo.m的model_dir为你下载的模型,然后运行。
最终得到:
在训练前请确保你的路径faster_rcnn-masterexternalcaffematlabcaffe_faster_rcnn下有以下文件:
(我的OpenCV版本是2.4.9,cuda版本是7.5,因版本不同上述文件和你的编译结果可能会有差异。+caffe文件夹是从caffe-master或caffe-faster-R-CNN里拷贝过来的。)
如果你没有按上面说的测试过,请先运行:
(1)faster_rcnn-masterfaster_rcnn_build.m
(2)faster_rcnn-masterstartup.m
然后再进行下面的修改。
1 、VOCdevkit2007VOCcodeVOCinit.m的修改
(1)路径的修改
VOCopts.annopath=[VOCopts.datadir VOCopts.dataset ‘/Annotations/%s.xml‘]; VOCopts.imgpath=[VOCopts.datadir VOCopts.dataset ‘/JPEGImages/%s.jpg‘]; VOCopts.imgsetpath=[VOCopts.datadir VOCopts.dataset ‘/ImageSets/Main/%s.txt‘]; VOCopts.clsimgsetpath=[VOCopts.datadir VOCopts.dataset ‘/ImageSets/Main/%s_%s.txt‘]; VOCopts.clsrespath=[VOCopts.resdir ‘Main/%s_cls_‘ VOCopts.testset ‘_%s.txt‘]; VOCopts.detrespath=[VOCopts.resdir ‘Main/%s_det_‘ VOCopts.testset ‘_%s.txt‘];
上面这些路径要正确,第一个是xml标签路径;第二个是图片的路径;第三个是放train.txt、val.txt、test.txt和trainval.txt的路径;第四、五、六个不需要;一般来说这些路径不用修改,你做的数据集格式和VOC2007相同就行。(图片格式默认是jpg,如果是png,修改上面第二行的代码即可。)
(2)训练集文件夹修改
VOCopts.dataset = ‘你的文件夹名‘;
(3)标签的修改
VOCopts.classes={... ‘你的标签1‘ ‘你的标签2‘ ‘你的标签3‘ ‘你的标签4‘};
将其改为你的标签。
2 、VOCdevkit2007 esults
results下需要新建一个文件夹,名字是1. (2)中“你的文件夹名”。“你的文件夹名”下新建一个Main文件夹。(因为可能会出现找不到文件夹的错误)
3 、VOCdevkit2007local
local下需要新建一个文件夹,名字是1. (2)中“你的文件夹名”。(同上)
4 、functionfast_rcnnfast_rcnn_train.m
ip.addParamValue(‘val_iters‘, 500, @isscalar); ip.addParamValue(‘val_interval‘, 2000, @isscalar);
可能在randperm(N,k)出现错误,根据数据集修改。(VOC2007中val有2510张图像,train有2501张,作者将val_iters设为500,val_interval设为2000,可以参考作者的设置修改,建议和作者一样val_iters约为val的1/5,val_interval不用修改)
5、function pnproposal_train.m
这里的问题和fast_rcnn_train.m一样。
6.imdbimdb_eval_voc.m
%do_eval = (str2num(year) <= 2007) | ~strcmp(test_set,‘test‘); do_eval = 1;
注释掉
do_eval = (str2num(year) <= 2007) | ~strcmp(test_set,‘test‘);
并令其为1,否则测试会出现精度全为0的情况
7. imdb oidb_from_voc.m
ip.addParamValue(‘exclude_difficult_samples‘, true, @islogical);
不包括难识别的样本,所以设置为true。(如果有就设置为false)。
8.网络模型的修改
(1) models fast_rcnn_prototxtsF train_val.prototxt
input: "bbox_targets" input_dim: 1 # to be changed on-the-fly to match num ROIs input_dim: 84 # 根据类别数改,该值为(类别数+1)*4 ################# input_dim: 1 input_dim: 1
input: "bbox_loss_weights" input_dim: 1 # to be changed on-the-fly to match num ROIs input_dim: 84 # 根据类别数改,该值为(类别数+1)*4 ############ input_dim: 1 input_dim: 1
layer { bottom: "fc7" top: "cls_score" name: "cls_score" param { lr_mult: 1.0 } param { lr_mult: 2.0 } type: "InnerProduct" inner_product_param { num_output: 21 #根据类别数改该值为类别数+1 #########
layer { bottom: "fc7" top: "bbox_pred" name: "bbox_pred" type: "InnerProduct" param { lr_mult: 1.0 } param { lr_mult: 2.0 } inner_product_param { num_output: 84 #根据类别数改,该值为(类别数+1)*4 ##########
(2)models fast_rcnn_prototxtsF test.prototxt
layer { bottom: "fc7" top: "cls_score" name: "cls_score" param { lr_mult: 1.0 } param { lr_mult: 2.0 } type: "InnerProduct" inner_product_param { num_output: 21 #类别数+1 ##########
layer { bottom: "fc7" top: "bbox_pred" name: "bbox_pred" type: "InnerProduct" param { lr_mult: 1.0 } param { lr_mult: 2.0 } inner_product_param { num_output: 84 #4*(类别数+1) ##########
(3) models fast_rcnn_prototxtsF_fc6 train_val.prototxt
input: "bbox_targets" input_dim: 1 # to be changed on-the-fly to match num ROIs input_dim: 84 # 4*(类别数+1) ########### input_dim: 1 input_dim: 1
input: "bbox_loss_weights" input_dim: 1 # to be changed on-the-fly to match num ROIs input_dim: 84 # 4*(类别数+1) ########### input_dim: 1 input_dim: 1
layer { bottom: "fc7" top: "cls_score" name: "cls_score" param { lr_mult: 1.0 } param { lr_mult: 2.0 } type: "InnerProduct" inner_product_param { num_output: 21 #类别数+1 ############
layer { bottom: "fc7" top:"bbox_pred" name:"bbox_pred" type:"InnerProduct" param { lr_mult:1.0 } param { lr_mult:2.0 } inner_product_param{ num_output: 84 #4*(类别数+1) ###########
(4) models fast_rcnn_prototxtsF_fc6 test.prototxt
layer { bottom: "fc7" top: "cls_score" name: "cls_score" param { lr_mult: 1.0 } param { lr_mult: 2.0 } type: "InnerProduct" inner_product_param { num_output: 21 类别数+1 #######
layer { bottom: "fc7" top: "bbox_pred" name: "bbox_pred" type: "InnerProduct" param { lr_mult: 1.0 } param { lr_mult: 2.0 } inner_product_param { num_output: 84 #4*(类别数+1) ##########
9.solver的修改
model.stage1_rpn.solver_def_file = fullfile(pwd, ‘models‘, ‘rpn_prototxts‘, ‘ZF‘, ‘solver_30k40k.prototxt‘);%solver_60k80k.prototxt model.stage1_rpn.test_net_def_file = fullfile(pwd, ‘models‘, ‘rpn_prototxts‘, ‘ZF‘, ‘test.prototxt‘); model.stage1_rpn.init_net_file = model.pre_trained_net_file;
10.开始训练
(2).运行:
experiments/script_faster_rcnn_VOC2007_ZF.m
经过一会的准备工作,就进入迭代了:
11.训练完后
将relu5(包括relu5)前的层删除,并将roi_pool5的bottom改为data和rois。并且前面input: "data"下的input_dim:分别改为1,256,50,50(如果是VGG就是1,512,50,50,其他修改基本一样),具体如下
input: "data" input_dim: 1 input_dim: 256 input_dim: 50 input_dim: 50
# ------------------------ layer 1 ----------------------------- layer { bottom: "data" bottom: "rois" top: "pool5" name: "roi_pool5" type: "ROIPooling" roi_pooling_param { pooled_w: 6 pooled_h: 6 spatial_scale: 0.0625 # (1/16) } }
12.测试
训练完成后,打开experimentsscript_faster_rcnn_demo.m,将模型路径改成训练得到的模型路径:
model_dir = fullfile(pwd, ‘output‘, ‘faster_rcnn_final‘, ‘faster_rcnn_VOC2007_ZF‘)
将测试图片改成你的图片:
im_names = {‘001.jpg‘, ‘002.jpg‘, ‘003.jpg‘};
showboxes(im, boxes_cell, classes);
showboxes(im, boxes_cell, classes, ‘default‘);
如果测试发现出现的框很多,且这些框没有目标,可以将阈值设高一些(默认是0.6):
thres = 0.9;
如何在faster-rcnn上训练自己的数据集
参考技术A不要发私信 查看详情
faster-rcnn训练自己的数据集——备忘
...。刚刚调通,记下来,以备以后自己少走些弯路。配置py-faster-rcnn没什么好记的,文档也很多。先说下数据集,需要准备三个文件夹:Annotations Images &n 查看详情
windows下使用自己制作的数据集训练faster-rcnn(tensorflow版)用于目标检测
步骤一下载配置windows下tensorflow版faster-rcnn,参考博客:windows10下运行tensorflow版的faster-Rcnn步骤二制作自己的数据集参考博客:http://blog.csdn.net/u011574296/article/details/78953681步骤三用你的Annotations,Imag 查看详情
使用labelimg制作自己的数据集(voc2007格式)用于faster-rcnn训练(代码片段)
https://blog.csdn.net/u011956147/article/details/53239325https://blog.csdn.net/u011574296/article/details/789536812018年01月02日17:13:59 ZealCV 阅读数:10459 标签: faster-r-cnn数据标注 更多个人分类: 深度学习 版权声明:本文为博主... 查看详情
深度学习caffe实战笔记(19)windows平台faster-rcnn制作自己的数据集
...过程,这篇博客先介绍如果制作voc2007自己的数据集用于faster-rcnn训练,下一篇博客介绍如何用faster-rcnn训练自己的数据。1、准备图像图像要用.jpg或者jpeg格式的,如果是png或者其它格式,自己转换一下就好,图像名称要用000001.jpg... 查看详情
折腾faster-rcnn(三)--训练篇
...(空格分隔):Linux深度学习前面,我们已经成功跑起来faster-rcnn,并且自己动手训练了PascalVOC2007图像集,但是笔者接下来继续沿着官方文件跑PascalVOC2012,训练到第二阶段的某个点,程序就开始报错退出。查看logs发现,找不到... 查看详情
在自定义数据集上训练 Faster-RCNN 模型时加载检查点
】在自定义数据集上训练Faster-RCNN模型时加载检查点【英文标题】:LoadingcheckpointswhiletrainingaFaster-RCNNmodelonacustomdataset【发布时间】:2021-12-1002:16:09【问题描述】:我正在尝试使用Faster-RCNN架构(准确地说是FasterR-CNNResNet50V1640x640,... 查看详情
深度学习和目标检测系列教程11-300:小麦数据集训练faster-rcnn模型(代码片段)
@Author:Runsen上次训练的Faster-RCNN的数据格式是xml和jpg图片提供,在很多Object-Detection中,数据有的是csv格式,数据集来源:https://www.kaggle.com/c/global-wheat-detectionwidth和heigth是图片的长和宽,b 查看详情
tusimple车道线检测处理自己的数据集用自己的数据集训练模型
tusimple车道线检测处理自己的数据集用自己的数据集训练模型_喜欢爱喝矿泉水的男孩的博客-CSDN博客标注数据将自己的数据用labelme(至于如何安装和使用请自查)打开,然后选择线段或者点进行标注,标注完成之后会生成jso... 查看详情
用yolov5ds训练自己的数据集,注意点!
...天打算使用YOLOv5做一下实例分割,找到用YOLOv5ds训练自己的数据集——同时检测和分割_2021黑白灰的博客-CSDN博客_yolov5图像分割Yolov5同时进行目标检测和分割分割_LeeCW2022的博客-CSDN博客_yolov5分割这两篇文章当参考,但是中... 查看详情
怎样用自己的数据集对caffe训练好的model进行fineture
...话可以在现有的比较好的网络结构上进行修改,使之符合自己的需求。最难的就是从零开始设计训练网络模型。题主可以体验一下从零开始设计训练模型,但是不要陷太深。如果题主设计了很好的网络模型,欢迎分享啊根据您的... 查看详情
在自己的数据集上训练 TensorFlow 对象检测
】在自己的数据集上训练TensorFlow对象检测【英文标题】:TrainTensorflowObjectDetectiononowndataset【发布时间】:2017-12-1121:27:26【问题描述】:在花了几天时间尝试完成这项任务后,我想分享一下我如何回答这个问题的经验:如何使用TS... 查看详情
[课程][原创]yolov5安装标注训练自己数据集windows版
搞定系列:yolov5训练自己数据集windows版课程地址:搞定系列:yolov5训练自己数据集windows版--深度学习视频教程-人工智能-CSDN程序员研修院开会员学更多课程课程介绍课程目录讨论留言你将收获1、学会如何搭建yolov5环... 查看详情
pytorch Faster-RCNN 的验证损失
】pytorchFaster-RCNN的验证损失【英文标题】:ValidationlossforpytorchFaster-RCNN【发布时间】:2020-06-0522:10:21【问题描述】:我目前正在使用从pytorch预训练的Faster-RCNN模型(例如在torchvisiontutorial中)的迁移学习对自定义数据集进行对象检... 查看详情
[课程][原创]paddleocr训练自己数据集windows版
paddleocr训练自己数据集windows版课程地址:paddleocr训练自己数据集windows版--深度学习视频教程-人工智能-CSDN程序员研修院15节节数课程介绍课程目录讨论留言你将收获1、可以学会安装paddleocr在windows上GPU环境2、学会paddleocr训练... 查看详情
[深度学习][原创]yolox快速训练自己数据集方法
...在火热更新中,本文将使用非常简单的步骤即可完成自己模型训练任务。第一步:搭建自己的yolox环境,yolox支持windows和linux大家按照官方教程安装即可,这里不是本文重点介绍。第二步准备数据集:一般我们用的... 查看详情
yolov7训练自己的数据集(口罩检测)(代码片段)
YOLOv7训练自己的数据集(口罩检测)前言前提条件实验环境项目结构制作自己的数据集数据集目录结构训练自己的数据集VOC格式数据集转换成YOLO格式数据集修改cfg配置新建一个myyolov7.yaml配置文件myyolov7.yaml内容创建自己... 查看详情
yolox训练流程解析
yolox训练代码写得比较简单,就是需要我们自己根据自己的数据定义好加载数据的方式,评估方式即可。整体训练流程我用xmind画出来了,最主要就是定义YourDataDetection类,加载我们自己的训练集数据和验证集数据... 查看详情