////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

一:初步进行检测

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

1.首先opencv是需要安装的,我用的ubuntu16,opencv3.4,具体安装教程可以参考网上很多,不想多提。

2.安装几个依赖包:cython,python-opencv和easydict,直接用sudo apt-get安装,网上很多用pip安装,bug比较多。

3.从github上clone项目文件,注意:一定要在clone时加入--recursive参数,不然会很麻烦,也不要直接下载:

git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git 

4.Cython模块的编译

cd py-faster-rcnn/lib

make

5.编译caffe-fast-rcnn

cd ..

cd caffe-fast-rcnn

修改这个目录下的Makefile.config(如果没有这个文件,就直接cp Makefile.config.example Makefile.config)

将CPU_ONLY := 1开关和WITH_PYTHON_LAYER开关打开:

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

6.运行demo.py

在环境一切就绪的情况下,将faster的模型下载下来:

在py-faster-rcnn/data/scripts 目录下,执行./fetch_faster_rcnn_models.sh 将数据下载,可能需要一定时间,慢慢等吧~~~

能成功吗?如果现在直接运行肯定是万万不可以成功的!

https://blog.csdn.net/u012675539/article/details/53537271

源码地址:https://github.com/rbgirshick/py-faster-rcnn

由于 faster rcnn 依赖是基于 caffe 的,所以需要先安装 caffe,所以前提是你已经在本机上装过 caffe ,然后直接复制该 Makefile.config 到目录 $FRCN_ROOT/caffe-fast-rcnn 下然后执行 make -j8 && make pycaffe 即可。

Run demo in cpu

安装完后可以跑个 demo 试试

cd $FRCN_ROOT
./tools/demo.py

如果出现如下错误:

ImportError: No module named gpu_nms
  • 1

说明 demo.py 脚本默认使用 gpu 检测物体,如果想要使用 cpu 修要做如下修改:

  • $FRCN_ROOT/lib/setup.py 中含有nms.gpu_nms的部分注释掉,注释后的内容如下。同时需要将该文件中 58 行左右的 CUDA = locate_cuda() 也注释掉。
ext_modules = [
Extension(
"utils.cython_bbox",
["utils/bbox.pyx"],
extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]},
include_dirs = [numpy_include]
),
Extension(
"nms.cpu_nms",
["nms/cpu_nms.pyx"],
extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]},
include_dirs = [numpy_include]
),
#Extension('nms.gpu_nms',
#['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
#library_dirs=[CUDA['lib64']],
#libraries=['cudart'],
#language='c++',
#runtime_library_dirs=[CUDA['lib64']],
## this syntax is specific to this build system
## we're only going to use certain compiler args with nvcc and not with
## gcc the implementation of this trick is in customize_compiler() below
#extra_compile_args={'gcc': ["-Wno-unused-function"],
#'nvcc': ['-arch=sm_35',
#'--ptxas-options=-v',
#'-c',
#'--compiler-options',
#"'-fPIC'"]},
#include_dirs = [numpy_include, CUDA['include']]
#),
Extension(
'pycocotools._mask',
sources=['pycocotools/maskApi.c', 'pycocotools/_mask.pyx'],
include_dirs = [numpy_include, 'pycocotools'],
extra_compile_args={
'gcc': ['-Wno-cpp', '-Wno-unused-function', '-std=c99']},
),
]
  • $FRCN_ROOT/lib/fast_rcnn/config.py中 205 行的 __C.USE_GPU_NMS = True 改成 __C.USE_GPU_NMS = False
  • $FRCN_ROOT/lib/fast_rcnn/nms_wrapper.py中的第 9 行 from nms.gpu_nms import gpu_nms 注释掉

现在执行 ./tool/demo.py --cpu就可以看到物体检测的效果了。

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

二  接下来训练自己的数据集了

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Train in cpu

首先需要对$/FRCN_ROOT/caffe-faster-rcnn/src/caffe/layers/内的roi_pooling_layer.cpp和smooth_L1_loss_layer.cpp进行替换并重新编译,替换文件在 github-faster-rcnn-cpu
    将该数据集放在py-faster-rcnn\data下,用你的数据集替换VOC2007数据集(即用你的Annotations,ImagesSets和JPEGImages替换 py-faster-rcnn\data\VOCdevkit2007\VOC2007 中对应文件夹)
    下载ImageNet数据集下预训练得到的模型参数(用来初始化),解压,然后将该文件放在py-faster-rcnn\data下。(提供一个百度云地址:http://pan.baidu.com/s/1hsxx8OW)
    对模型的配置文件进行一些修改,主要有:
        修改 $/FRCN_ROOT/lib/datasets/pascal_voc.py 中待检测物体的类别名,主要时第 30 行 self._classes = ('__background__', ) 中加入你自己想要分类的物体名。
        修改文件stage1_rpn_train.pt,stage2_rpn_train.pt,stage1_fast_rcnn_train.pt,stage1_fast_rcnn_train.pt 中待分类的个数。
    修改 $/FRCN_ROOT/experiments/scripts/faster_rcnn_alt_opt.sh 脚本,去掉 46 行 time ./tools/train_faster_rcnn_alt_opt.py --gpu ${GPU_ID} \ 中的 --gpu ${GPU_ID},对 57 行做同样的操作。

执行命令 ./experiments/scripts/faster_rcnn_alt_opt.sh 0 ZF pascal_voc 就可以使用预训练的 ImageNet 数据 finetune 自己的数据了。

但此时会出现错误:

WARNING: Logging before InitGoogleLogging() is written to STDERR
F1209 11:40:45.697101   535 common.cpp:66] Cannot use GPU in CPU-only Caffe: check mode.
*** Check failure stack trace: ***

1
    2
    3

主要原因时文件 $/FRCN_ROOT/tool/train_faster_rcnn_alt_opt.py 默认使用了 caffe gpu mode,需要对该文件做如下修改:

注释掉 34-36 行,注释后的结果如下:

33     parser = argparse.ArgumentParser(description='Train a Faster R-CNN network')
34     # parser.add_argument('--gpu', dest='gpu_id',
35     #                     help='GPU device id to use [0]',
36     #                     default=0, type=int)
37     parser.add_argument('--net_name', dest='net_name',

1
    2
    3
    4
    5

注释掉 102-103 行 的 caffe.set_mode_gpu() 和 caffe.set_device(cfg.GPU_ID),并在后面加上 caffe.set_mode_cpu()
    注释掉出现 gpu_id 的地方

再次执行命令 ./experiments/scripts/faster_rcnn_alt_opt.sh 0 ZF pascal_voc 就可以看到训练效果了。
Reference

http://www.cnblogs.com/justinzhang/p/5386837.html

http://www.aichengxu.com/view/11065139

ubuntu16+caffe fast-rcnnCPU运行步骤的更多相关文章

  1. Qt creator自定义编译运行步骤

    一直用Qt creator开发.无它,只是因为linux下C++ IDE选择不多.同时因为我抛弃了MFC,平时写个小工具还得靠Qt,正好一举两用. 用Qt creator开发一般的工程,是不用修改编译 ...

  2. Optaplanner - 从探究示例中的hello world,初步认识规划引擎的运行步骤。

    上一篇我们成功以把Opotaplanner规划引擎下载回来,并把它的示例运行起来,简单解析了一下它的Cloud balance示例.这一篇我们这些示例的源代码导入到Eclipse中,看看它在后台是怎么 ...

  3. 【ARM-Linux开发】【Qt开发】Qt Creator自定义编译运行步骤

    原文:http://www.linuxidc.com/Linux/2015-04/115763.htm 一直用Qt Creator开发.无它,只是因为linux下C++ IDE选择不多.同时因为我抛弃 ...

  4. Elasticsearch后台运行步骤

    Elasticsearch后台运行步骤 1.cmd 到elasticsearch 中bin目录下 2.elasticsearch-service 出现  3.安装服务 elasticsearch-se ...

  5. ubuntu16.04下caffe以cpu运行faster rcnn demo

    参考https://haoyu.love/blog404.html 获取并修改代码 首先,我们需要获取源代码: git clone --recursive https://github.com/rbg ...

  6. ubuntu16.04安装MATLAB R2017b步骤详解(附完整文件包)

    摘要:介绍在ubuntu16.04中从下载到安装成功的完整步骤.本文给出MATLAB R2017b(Linux系统)的完整安装包百度云盘下载地址,逐步介绍一种简单易行的安装方法,在桌面创建快捷方式,最 ...

  7. hadoop自带例子wordcount的具体运行步骤

    1.在hadoop所在目录“usr/local”下创建一个文件夹input root@ubuntu:/usr/local# mkdir input 2.在文件夹input中创建两个文本文件file1. ...

  8. Fitnesse-20140630与RestFixture-3.1编译与运行步骤

    为了能使RestFixture-3.1在Fitnesse-20140630中正确打印测试结果,准备修改RestFixture. 1.下载并编译Fitnesse-20140630 以下步骤以在64位Wi ...

  9. php运行步骤解析

    2000年, PHP4.0发布的时候,引入了Zend Engine. Zend引擎把PHP代码的执行切分成两个阶段: 一. Zend Engine 解析PHP代码并生成二进制中间码Zend Opcod ...

随机推荐

  1. 强制找回GitLab管理员账户密码的方法

    为了开发运维工具,我们采用自行搭建的GitLab来管理所有代码.悲催的是最近忘记了管理员账户的密码,而且没有邮件服务器,因此无法接收密码找回的邮件,导致无法新建用户或者项目,这样一来,岂不就成为了一个 ...

  2. Apache http 包中的常量

    org.apache.* org.apache.http.Consts public static final int CR 13 public static final int HT 9 publi ...

  3. 八数码问题 双向BFS/Hsh链表存储

    转自洛谷 作者EndSaH #include<iostream> #include<string> #include<cmath> #include<cstr ...

  4. 吴裕雄--天生自然java开发常用类库学习笔记:日期操作类DataFormat、SimpleDataFormat

    import java.text.DateFormat ; import java.util.Date ; public class DateDemo03{ public static void ma ...

  5. thinkphp配置到二级目录,不配置到根目录,访问除首页的其他路径都是404报错

    1.在nginx的配置里面,进行重定向 vi /etc/nginx/conf.d/default.conf 2.进入编辑 location /thinkphp/public { if (!-e $re ...

  6. js数字排序方法

    function bubbleSort(arr){ var flag = false; // 定义一个变量为false,未交换位置 for(var i=0;i<arr.length-1;i++) ...

  7. python --- mysql数据库的操作

    1.pymysql的初使用 import pymysql db_config = { 'host' :'127.0.0.1', 'user':'root', ', , 'database':'test ...

  8. HDU - 6201 transaction transaction transaction(spfa求最长路)

    题意:有n个点,n-1条边的无向图,已知每个点书的售价,以及在边上行走的路费,问任选两个点作为起点和终点,能获得的最大利益是多少. 分析: 1.从某个结点出发,首先需要在该结点a花费price[a]买 ...

  9. s5pc100开发板Nand flash移植

    相关软件下载地址:http://pan.baidu.com/s/16yo8Y fsc100开发板 交叉编译工具:arm-cortex_a8-linux-gnueabi-gcc Ÿ   添加针对我们平台 ...

  10. 虚拟机安装centos6.5出现Error processing drive:pci-0000:00:10-scsi-0:0:0:0问题

    vmware安装linux系统出现Error processing drive:pci-0000:00:10-scsi-0:0:0:0问题 问题出现原因:我给虚拟机的内存太小了,只给了512M 解决办 ...