如何才能将Faster R-CNN训练起来?

 

如何才能将Faster R-CNN训练起来?

 

  首先进入 Faster RCNN 的官网啦,即:https://github.com/rbgirshick/py-faster-rcnn#installation-sufficient-for-the-demo

  先用提供的 model 自己测试一下效果嘛。。。

  按照官网安装教程,安装基本需求。

  



 

Installation (sufficient for the demo)

 

  1. Clone the Faster R-CNN repository

    # Make sure to clone with --recursive
    git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
  2. We'll call the directory that you cloned Faster R-CNN into FRCN_ROOT

    Ignore notes 1 and 2 if you followed step 1 above.

    Note 1: If you didn't clone Faster R-CNN with the --recursive flag, then you'll need to manually clone the caffe-fast-rcnn submodule:

    git submodule update --init --recursive

    Note 2: The caffe-fast-rcnn submodule needs to be on the faster-rcnn branch (or equivalent detached state). This will happen automatically if you followed step 1 instructions.

  3. Build the Cython modules
    cd $FRCN_ROOT/lib
    make
  4. Build Caffe and pycaffe
    cd $FRCN_ROOT/caffe-fast-rcnn
    # Now follow the Caffe installation instructions here:
    #   http://caffe.berkeleyvision.org/installation.html
    
    # If you're experienced with Caffe and have all of the requirements installed
    # and your Makefile.config in place, then simply do:
    make -j8 && make pycaffe
  5. Download pre-computed Faster R-CNN detectors
    cd $FRCN_ROOT
    ./data/scripts/fetch_faster_rcnn_models.sh

    This will populate the $FRCN_ROOT/data folder with faster_rcnn_models. See data/README.md for details. These models were trained on VOC 2007 trainval.

 

Demo

 

After successfully completing basic installation, you'll be ready to run the demo.

 

To run the demo

 

cd $FRCN_ROOT
./tools/demo.py

 

The demo performs detection using a VGG16 network trained for detection on PASCAL VOC 2007.

 



  你自己要下载一个 caffe-master,因为这个检测方法就是调用 caffe的啦,自己下载了,然后放到(注意,是拷贝内容):

  ./py-faster-rcnn-master/caffe-fast-rcnn/

 

  然而,情况总是不太顺利啊,遇到了如下问题:

 

 



  执行 demo 的过程中,遇到的首个问题是:

wangxiao@GTX980:~/Desktop/py-faster-rcnn-master$ ./tools/demo.py
Traceback (most recent call last):
File "./tools/demo.py", line 18, in <module>
from fast_rcnn.test import im_detect
File "/home/wangxiao/Desktop/py-faster-rcnn-master/tools/../lib/fast_rcnn/test.py", line 16, in <module>
import caffe
File "/home/wangxiao/Desktop/py-faster-rcnn-master/tools/../caffe-fast-rcnn/python/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
File "/home/wangxiao/Desktop/py-faster-rcnn-master/tools/../caffe-fast-rcnn/python/caffe/pycaffe.py", line 15, in <module>
import caffe.io
File "/home/wangxiao/Desktop/py-faster-rcnn-master/tools/../caffe-fast-rcnn/python/caffe/io.py", line 2, in <module>
import skimage.io
ImportError: No module named skimage.io
wangxiao@GTX980:~/Desktop/py-faster-rcnn-master$

 

 

  解决方法是: sudo easy_install -U scikit-image



 

  那么,就这样完了?? 噢,no,并不是:

  

wangxiao@GTX980:~/Desktop/py-faster-rcnn-master/tools$ ./demo.py
/usr/local/lib/python2.7/dist-packages/matplotlib-2.0.0b3-py2.7-linux-x86_64.egg/matplotlib/font_manager.py:279: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
Traceback (most recent call last):
File "./demo.py", line 127, in <module>
'fetch_faster_rcnn_models.sh?').format(caffemodel))
IOError: /home/wangxiao/Desktop/py-faster-rcnn-master/data/faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel not found.
Did you run ./data/script/fetch_faster_rcnn_models.sh?

 

  因为你测试的时候,没有提供给他测试的 model啊,ok,执行这句吧,下载一个模型:

   ./data/script/fetch_faster_rcnn_models.sh

  速度还是有点慢的,耐心等候啊,少年!

  

 

 



  然后,

wangxiao@GTX980:~/Desktop/py-faster-rcnn-master/tools$ ./demo.py
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0729 10:57:41.107311 7997 _caffe.cpp:122] DEPRECATION WARNING - deprecated use of Python interface
W0729 10:57:41.107381 7997 _caffe.cpp:123] Use this instead (with the named "weights" parameter):
W0729 10:57:41.107398 7997 _caffe.cpp:125] Net('/home/wangxiao/Desktop/py-faster-rcnn-master/models/pascal_voc/VGG16/faster_rcnn_alt_opt/faster_rcnn_test.pt', 1, weights='/home/wangxiao/Desktop/py-faster-rcnn-master/data/faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel')
[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 350:21: Message type "caffe.LayerParameter" has no field named "roi_pooling_param".
F0729 10:57:41.132531 7997 upgrade_proto.cpp:79] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: /home/wangxiao/Desktop/py-faster-rcnn-master/models/pascal_voc/VGG16/faster_rcnn_alt_opt/faster_rcnn_test.pt
*** Check failure stack trace: ***
Aborted
wangxiao@GTX980:~/Desktop/py-faster-rcnn-master/tools$

 

 

 



 

  我更新了一下系统,但是提示我无法更新啊。。。

wangxiao@GTX980:~$ sudo apt-get update
[sudo] password for wangxiao:
E: Type 'Reading' is not known on line 1 in source list /etc/apt/sources.list.d/bazel.list
E: The list of sources could not be read.

  进去这个路径,将这个文件删掉,即可,即:sudo rm /etc/apt/sources.list.d/bazel.list 



 

 

  之前出现各种蛋疼的情况主要是因为:不能自己从caffe官网下的那个caffe来用,而应该是从作者自己的 github上来下。

  然后加到对应的文件夹进行编译,就不会出现这些问题了。

 

  



  至于训练的话,有两种方式,一种是: end-to-end,即:

  在终端执行:选择 GPU-0,网络为: ZF 数据集为: pascal_voc 

  ./experiments/scripts/faster_rcnn_end2end.sh 0 ZF pascal_voc

  那么,就可以跑了 。。。

  

  不像 matlab版本那么蛋疼,跑一下,就会自动关闭matlab一次,╮(╯▽╰)╭ 伤不起 。。。

 



  这是最终跑出来的结果:mAP 是:59.09 %   

Saving cached annotations to /home/wangxiao/Desktop/py-faster-rcnn-master/data/VOCdevkit2007/annotations_cache/annots.pkl
AP for aeroplane = 0.6043
AP for bicycle = 0.7138
AP for bird = 0.5504
AP for boat = 0.4721
AP for bottle = 0.3404
AP for bus = 0.6633
AP for car = 0.7369
AP for cat = 0.7021
AP for chair = 0.3631
AP for cow = 0.6086
AP for diningtable = 0.6191
AP for dog = 0.6469
AP for horse = 0.7789
AP for motorbike = 0.6782
AP for person = 0.6489
AP for pottedplant = 0.3073
AP for sheep = 0.5715
AP for sofa = 0.5015
AP for train = 0.7026
AP for tvmonitor = 0.6089
Mean AP = 0.5909
~~~~~~~~
Results:
0.604
0.714
0.550
0.472
0.340
0.663
0.737
0.702
0.363
0.609
0.619
0.647
0.779
0.678
0.649
0.307
0.571
0.502
0.703
0.609
0.591
~~~~~~~~

--------------------------------------------------------------
Results computed with the **unofficial** Python eval code.
Results should be very close to the official MATLAB eval code.
Recompute with `./tools/reval.py --matlab ...` for your paper.
-- Thanks, The Management
--------------------------------------------------------------

real 5m25.471s
user 5m11.620s
sys 0m35.848s

 



  Matlab 版本碰到过如下的问题:

  1. 找不到 ZF文件夹下面的 test.prototxt 文件:

    

fast_rcnn startup done
GPU 1: free memory 3786178560
Use GPU 1
Error using CHECK_FILE_EXIST (line 4)
/home/wangxiao/Desktop/matlab-faster_rcnn-master/experiments/models/rpn_prototxts/ZF/test.prototxt does not exist

 

Error in caffe.get_net (line 21)
CHECK_FILE_EXIST(model_file);

 

Error in caffe.Net (line 31)
self = caffe.get_net(varargin{:});

 

Error in proposal_calc_output_size (line 10)
caffe_net = caffe.Net(test_net_def_file, 'test');

 

Error in script_faster_rcnn_VOC2007_ZF>proposal_prepare_anchors (line 91)
[output_width_map, output_height_map] ...

 

Error in script_faster_rcnn_VOC2007_ZF (line 41)
[conf_proposal.anchors, conf_proposal.output_width_map, conf_proposal.output_height_map] ...

 

解决方案是:没有下载那个文件,囧,下载地址:https://onedrive.live.com/download?resid=36FEC490FBC32F1A!113&authkey=!AIzdm0sD_SmhUQ4&ithint=file%2czip

 

2. 将上一个问题搞定后,有出现新的,这个有点摸不着头脑了:

 

 

fast_rcnn startup done
GPU 1: free memory 3761143808
Use GPU 1
No appropriate method, property, or field reshape_as_input for class caffe.Net.

Error in proposal_calc_output_size (line 28)
caffe_net.reshape_as_input(net_inputs);

Error in script_faster_rcnn_VOC2007_ZF>proposal_prepare_anchors (line 91)
[output_width_map, output_height_map] ...

Error in script_faster_rcnn_VOC2007_ZF (line 41)
[conf_proposal.anchors, conf_proposal.output_width_map, conf_proposal.output_height_map]
...

 

解决方法是:可能是你 caffe 版本不对,重新从 faster rcnn 官网上下载,然后编译 。。。 

 

3. 更蛋疼的是这个问题,表面上看,正在运行,但是 这个时候你看看终端上的显示: 

 

 

 

File not found: ./models/rpn_prototxts/ZF/train_vali.prototxt 

但是,这个文件明明就放在那里啊。。。无语。。。

 

解决方案是:由于下载的model中,关于 prototxt文件中路径的问题,请改为绝对路径,如下图所示,且用”/“作为分隔符,因为下载了的分隔符是不对的,所以,一直找不到这个文件,哎,坑啊。。。。

 

  

搞完之后,就可以继续正常的运行了。。。 

 

fast_rcnn startup done
GPU 1: free memory 3676987392
Use GPU 1
Warning: Specified caffe folder
(/home/wangxiao/Documents/faster_rcnn-master/experiments/external/caffe/matlab/caffe_faster_rcnn) is not exist,
change to default one (/home/wangxiao/Documents/faster_rcnn-master/experiments/external/caffe/matlab)
> In active_caffe_mex at 19
  In script_faster_rcnn_VOC2007_ZF at 17
Cleared 0 solvers and 1 stand-alone nets

***************
stage one proposal
***************
conf:
                      batch_size: 256
                    bg_thresh_hi: 0.3000
                    bg_thresh_lo: 0
                       bg_weight: 1
         drop_boxes_runoff_image: 1
                     feat_stride: 16
                     fg_fraction: 0.5000
                       fg_thresh: 0.7000
                     image_means: [224x224x3 single]
                   ims_per_batch: 1
                        max_size: 1000
                        rng_seed: 6
                          scales: 600
                  target_only_gt: 1
                     test_binary: 0
    test_drop_boxes_runoff_image: 0
                   test_max_size: 1000
               test_min_box_size: 16
                        test_nms: 0.3000
                     test_scales: 600
                     use_flipped: 1
                         use_gpu: 1
                         anchors: [9x4 double]
                output_width_map: [901x1 containers.Map]
               output_height_map: [901x1 containers.Map]

opts:
           cache_name: 'faster_rcnn_VOC2007_ZF_stage1_rpn'
                 conf: [1x1 struct]
               do_val: 1
           imdb_train: {[1x1 struct]}
             imdb_val: [1x1 struct]
             net_file: '/home/wangxiao/Documents/faster_rcnn-master/experiments/models/pre_trained_models/ZF/ZF...'
          roidb_train: {[1x1 struct]}
            roidb_val: [1x1 struct]
    snapshot_interval: 10000
      solver_def_file: '/home/wangxiao/Documents/faster_rcnn-master/experiments/models/rpn_prototxts/ZF/solver_...'
         val_interval: 2000
            val_iters: 500

Preparing training data...Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers.
Done.
Preparing validation data...Done.

------------------------- Iteration 2000 -------------------------
Training : err_fg 0.521, err_bg 0.0187, loss (cls 0.242 + reg 0.0218)
Testing  : err_fg 0.487, err_bg 0.0131, loss (cls 0.203 + reg 0.0167)

------------------------- Iteration 4000 -------------------------
Training : err_fg 0.495, err_bg 0.0187, loss (cls 0.209 + reg 0.0206)
Testing  : err_fg 0.458, err_bg 0.0143, loss (cls 0.182 + reg 0.0158)

------------------------- Iteration 6000 -------------------------
Training : err_fg 0.462, err_bg 0.0205, loss (cls 0.196 + reg 0.0189)
Testing  : err_fg 0.409, err_bg 0.0229, loss (cls 0.177 + reg 0.0184)

------------------------- Iteration 8000 -------------------------
Training : err_fg 0.46, err_bg 0.0196, loss (cls 0.19 + reg 0.0194)
Testing  : err_fg 0.404, err_bg 0.0163, loss (cls 0.165 + reg 0.0151)

------------------------- Iteration 10000 -------------------------
Training : err_fg 0.437, err_bg 0.0202, loss (cls 0.179 + reg 0.0189)
Testing  : err_fg 0.413, err_bg 0.0154, loss (cls 0.168 + reg 0.0158)
Saved as /home/wangxiao/Documents/faster_rcnn-master/experiments/output/rpn_cachedir/faster_rcnn_VOC2007_ZF_stage1_rpn/voc_2007_trainval/iter_10000

  

 4. Faster RCNN 运行出现问题:

fast_rcnn startup done
Error using gpuDevice (line 26)
An unexpected error occurred during CUDA execution. The CUDA error was:
cannot set while device is active in this process

Error in auto_select_gpu (line 15)
g = gpuDevice(i);

Error in script_faster_rcnn_VOC2007_ZF (line 16)
opts.gpu_id = auto_select_gpu;



答:如果之前正常运行,突然出现这个问题,重启你的 matlab,然后以 sudo 开启,重新跑一下就没事了。。。

 

 5. 下面是今天重新跑 faster RCNN 遇到的一个问题:

 

 

 

 解决方案是:

  数据集的名字或者文件夹不存在,额,将数据集加上就行了...

 

 



 

   

 6. 之前一直很纳闷,script_faster_rcnn_VOC0712_VGG16.m 这个脚本的数据集该怎么设置? 是分别单独设置两个文件夹,还是将其放到一个文件夹中???

  看到这个代码,我终于恍然大悟 ...

 

  

 

7. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

时间: 2024-08-01 16:33:48

如何才能将Faster R-CNN训练起来?的相关文章

神经网络CNN训练心得--调参经验

1.样本要随机化,防止大数据淹没小数据 2.样本要做归一化.关于归一化的好处请参考:为何需要归一化处理3.激活函数要视样本输入选择(多层神经网络一般使用relu)4.mini batch很重要,几百是比较合适的(很大数据量的情况下)5.学习速率(learning rate)很重要,比如一开始可以lr设置为0.01,然后运行到loss不怎么降的时候,学习速率除以10,接着训练6.权重初始化,可用高斯分布乘上一个很小的数,这个可以看:权值初始化 7.Adam收敛速度的确要快一些,可结果往往没有sgd

计算机视觉怎么给图像分类?KNN、SVM、BP神经网络、CNN、迁移学习供你选(附开源代码)

图像分类问题就是从固定的一组分类中,给输入图像分配标签的任务.这是计算机视觉的核心问题之一,尽管它看似简单,却在实际生活中有着各种各样的应用. 传统方式:功能描述和检测. 也许这种方法对于一些样本任务来说是比较好用的,但实际情况却要复杂得多. 因此,我们将使用机器学习来为每个类别提供许多示例,然后开发学习算法来查看这些示例,并了解每个类的视觉外观,而不是试图直接在代码中指定每一个大家感兴趣的类别是什么样的.  然而,图像分类问题就是一个非常复杂的工作,它总是借用诸如卷积神经网络(CNN)这样的深

杂谈CNN:如何通过优化求解输入图像

机器学习和优化问题 很多机器学习方法可以归结为优化问题,对于一个参数模型,比如神经网络,用 y=f(x;θ) 来表示的话,训练模型其实就是下面的参数优化问题: 其中 L 是loss function,比如神经网络中分类常用的 cross-entropy. CNN学到了什么? 特征(Representation).把原始图像看做一个维度是像素×通道的向量,经过各种复杂的CNN结构,其实只不过成了另一个向量.这个向量所在的空间也许有更好的线性可分性,也许是相似样本的"距离"更近,原始的数据

卷积神经网络(CNN)在无人驾驶中的应用

无人驾驶的感知部分作为计算机视觉的领域范围,也不可避免地成为CNN发挥作用的舞台.本文是无人驾驶技术系列的第八篇,深入介绍CNN(卷积神经网络)在无人驾驶3D感知与物体检测中的应用. CNN简介 卷积神经网络(Convolutional Neural Network,CNN)是一种适合使用在连续值输入信号上的深度神经网络,比如声音.图像和视频.它的历史可以回溯到1968年,Hubel和Wiesel在动物视觉皮层细胞中发现的对输入图案的方向选择性和平移不变性,这个工作为他们赢得了诺贝尔奖.时间推进

浅谈AndroidManifest.xml与R.java及各个目录的作用

原文:浅谈AndroidManifest.xml与R.java及各个目录的作用 在开发Android项目中,AndroidManifest.xml与R.java是自动生成的.但是对于测试来说,非常重要.经过师父的点拨,我对AndroidManifest.xml与R.java有了更深一层的理解. AndroidManifest.xml会自动生成引用包的属性配置,有权限的管理作用.引用的package必须声明了权限才能使用. R.java是对资源的索引,自动标识资源索引,相当于资源字典,里面包含项目

CNN与图像语义分割

级别1:DL快速上手 级别2:从Caffe着手实践 级别3:读paper,网络Train起来 级别4:Demo跑起来 读一些源码玩玩 熟悉Caffe接口,写Demo这是硬功夫 分析各层Layer输出特征 级别5:何不自己搭个CNN玩玩 Train CNN时关于数据集的一些注意事项 级别6:加速吧,GPU编程 关于语义分割的一些其它工作 说好的要笔耕不缀,这开始一边实习一边找工作,还摊上了自己的一点私事困扰,这几个月的东西都没来得及总结一下.这就来记录一下关于CNN.Caffe.Image Sem

CNN

 分类:   30.Machine L & Deep Learning(11)  目录(?)[-]                通俗理解卷积神经网络cs231n与5月dl班课程笔记 前言 人工神经网络 1 神经元 2 激活函数 3 神经网络 卷积神经网络之层级结构 CNN之卷积计算层 1 什么是卷积 2 图像上的卷积 3 GIF动态卷积图 CNN之激励层与池化层 1 ReLU激励层 2 池化pool层 后记 参考文献与延伸阅读                通俗理解卷积神经网络(cs231n与

图普科技工程师:Mask R-CNN的理论创新会带来怎样的可能性?

melmcgowan 上周,雷锋网 AI 科技评论报道了 Facebook 实验室出炉的新论文<Mask R-CNN>,第一作者何恺明带领团队提出了一种名为「Mask R-CNN」的目标实例分割框架.研究显示,该框架相比传统的操作方法更佳简单灵活. 论文地址:https://arxiv.org/abs/1703.06870 如果对物体识别和分割技术有所了解的读者们,可能对这个流程并不陌生.传统的物体识别和图像语义分割技术目前集中于运用 Fast/Faster R-CNN 和全卷积网络(FCN)

多模态小组阅读笔记精选 | 每周一起读 #7

本期精读文章 An Empirical Study of Language CNN for Image Captioning 文章来源 https://arxiv.org/abs/1612.07086 推荐理由 本篇论文提出了用 CNN 模型来对单词序列进行表达,该 CNN 的输入为之前时刻的所有单词,进而可以抓住对生成描述很重要的历史信息.其中总体架构如下图所示: 该模型主要由四部分组成,用于图像特征提取的 CNN_I,用于自然语言建模的 CNN_L,用于结合 CNN_I 和 CNN_L 信息