欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 人工智能 > caffe >内容正文

caffe

caffe-凯发k8官方网

发布时间:2024/9/21 caffe 11 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 caffe-fast-rcnn(caffe、fsrcnn、fastrcnn) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

作者:forest_world

转载请注明:http://blog.csdn.net/forest_world
一、文件架构

二、fsrcnn开发环境搭建:

faster-rcnn: matlab版本shaoqingren/faster_rcnn: faster r-cnn rbg提供的python版本rbgirshick/py-faster-rcnn
  • 1
  • 2
  • 3
  • 4
  • 5
git clone https://github.com/lmdb/lmdb cloning into 'lmdb'... remote: counting objects: 7201, done. remote: total 7201 (delta 0), reused 0 (delta 0), pack-reused 7201 receiving objects: 100% (7201/7201), 1.40 mib | 7.00 kib/s, done. resolving deltas: 100% (3097/3097), done. checking connectivity... done.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

安装lmdb
cd liblmdb
make
sudo make install

git clone –recursive https://github.com/rbgirshick/fast-rcnn.git

编译:cython module
cd lib
make

编译:caffe and pycaffe
cd caffe-fast-rcnn
make -j8 && make pycaffe

@ubuntu:~/fast-rcnn/caffe-fast-rcnn$ make -j8 && make pycaffe ld -o .build_release/lib/libcaffe.so cxx/ld -o .build_release/tools/compute_image_mean.bin cxx/ld -o .build_release/tools/upgrade_net_proto_binary.bin cxx/ld -o .build_release/tools/upgrade_net_proto_text.bin cxx/ld -o .build_release/tools/finetune_net.bin cxx/ld -o .build_release/tools/net_speed_benchmark.bin cxx/ld -o .build_release/tools/train_net.bin cxx/ld -o .build_release/tools/caffe.bin cxx/ld -o .build_release/tools/convert_imageset.bin cxx/ld -o .build_release/tools/extract_features.bin cxx/ld -o .build_release/tools/device_query.bin cxx/ld -o .build_release/tools/test_net.bin cxx/ld -o .build_release/examples/cifar10/convert_cifar_data.bin cxx/ld -o .build_release/examples/mnist/convert_mnist_data.bin cxx/ld -o .build_release/examples/siamese/convert_mnist_siamese_data.bin cxx/ld -o python/caffe/_caffe.so python/caffe/_caffe.cpp touch python/caffe/proto/__init__.py protoc (python) src/caffe/proto/caffe.proto
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

错误1:

ld -o .build_release/lib/libcaffe.so .build_release/src/caffe/layers/absval_layer.o: file not recognized: file truncated collect2: error: ld returned 1 exit status make: *** [.build_release/lib/libcaffe.so] error 1
  • 1
  • 2
  • 3
  • 4
  • 5
cxx src/caffe/layers/dummy_data_layer.cpp in file included from ./include/caffe/layer.hpp:8:0,from src/caffe/layers/relu_layer.cpp:4: ./include/caffe/blob.hpp:9:34: fatal error: caffe/proto/caffe.pb.h: no such file or directory#include "caffe/proto/caffe.pb.h"^ compilation terminated. the bug is not reproducible, so it is likely a hardware or os problem. make: *** [.build_release/src/caffe/layers/relu_layer.o] error 1 make: *** waiting for unfinished jobs.... in file included from ./include/caffe/fast_rcnn_layers.hpp:13:0,from src/caffe/layers/roi_pooling_layer.cpp:10: ./include/caffe/blob.hpp:9:34: fatal error: caffe/proto/caffe.pb.h: no such file or directory#include "caffe/proto/caffe.pb.h"^ compilation terminated. the bug is not reproducible, so it is likely a hardware or os problem. make: *** [.build_release/src/caffe/layers/roi_pooling_layer.o] error 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

解决:
~/fast-rcnn/caffe-fast-rcnn/src/caffe/proto$ protoc --cpp_out=/home/hello/fast-rcnn/caffe-fast-rcnn/include/caffe/ caffe.proto

sudo apt-get install libatlas-base-dev

三、训练检测

下载模型文件:

@ubuntu:~/fast-rcnn$ ./data/scripts/fetch_fast_rcnn_models.sh downloading fast r-cnn demo models (0.96g)... --2016-11-08 11:01:15-- http://www.cs.berkeley.edu/~rbg/fast-rcnn-data/fast_rcnn_models.tgz resolving www.cs.berkeley.edu (www.cs.berkeley.edu)... 23.253.180.102 connecting to www.cs.berkeley.edu (www.cs.berkeley.edu)|23.253.180.102|:80... connected. http request sent, awaiting response... 302 found location: http://101.96.10.61/www.cs.berkeley.edu/~rbg/fast-rcnn-data/fast_rcnn_models.tgz [following] --2016-11-08 11:01:16-- http://101.96.10.61/www.cs.berkeley.edu/~rbg/fast-rcnn-data/fast_rcnn_models.tgz connecting to 101.96.10.61:80... connected. http request sent, awaiting response... 303 see other location: https://people.eecs.berkeley.edu/~rbg/fast-rcnn-data/fast_rcnn_models.tgz [following]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

1、出现问题:

~/fast-rcnn/tools$ ./demo.py traceback (most recent call last):file "./demo.py", line 17, in <module>from fast_rcnn.config import cfgfile "/home//fast-rcnn/tools/../lib/fast_rcnn/__init__.py", line 8, in <module>from . import configfile "/home//fast-rcnn/tools/../lib/fast_rcnn/config.py", line 23, in <module>from easydict import easydict as edict importerror: no module named easydict
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

解决:
sudo apt-get install python-pip
sudo pip install easydict

~/fast-rcnn/tools$ ./demo.py traceback (most recent call last):file "./demo.py", line 17, in <module>from fast_rcnn.config import cfgfile "/home//fast-rcnn/tools/../lib/fast_rcnn/__init__.py", line 9, in <module>from . import trainfile "/home//fast-rcnn/tools/../lib/fast_rcnn/train.py", line 10, in <module>import caffefile "/home//fast-rcnn/tools/../caffe-fast-rcnn/python/caffe/__init__.py", line 1, in <module>from .pycaffe import net, sgdsolverfile "/home//fast-rcnn/tools/../caffe-fast-rcnn/python/caffe/pycaffe.py", line 14, in <module>import caffe.iofile "/home//fast-rcnn/tools/../caffe-fast-rcnn/python/caffe/io.py", line 2, in <module>import skimage.io importerror: no module named skimage.io
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

sudo pip install scikit-image
sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags cython ipython

2、出现问题:

@ubuntu:~/fast-rcnn/tools$ ./demo.py warning: logging before initgooglelogging() is written to stderr f1108 15:18:01.710467 13445 common.cpp:55] cannot use gpu in cpu-only caffe: check mode. *** check failure stack trace: *** aborted (core dumped)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

解决:

#if args.cpu_mode:caffe.set_mode_cpu()#else:#caffe.set_mode_gpu()#caffe.set_device(args.gpu_id)
  • 1
  • 2
  • 3
  • 4
  • 5

3、出现问题:

libprotobuf warning google/protobuf/io/coded_stream.cc:505] reading dangerously large protocol message. if the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons. to increase the limit (or to disable these warnings), see codedinputstream::settotalbyteslimit() in google/protobuf/io/coded_stream.h. [libprotobuf warning google/protobuf/io/coded_stream.cc:78] the total number of bytes read was 538766130loaded network /home//fast-rcnn/data/fast_rcnn_models/vgg16_fast_rcnn_iter_40000.caffemodel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ demo for data/demo/000004.jpg f1108 15:28:31.449816 13520 syncedmem.hpp:27] check failed: *ptr host allocation of size 255744000 failed *** check failure stack trace: *** aborted (core dumped)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

解决:
内存问题

测试结果:

loaded network /home//fast-rcnn/data/fast_rcnn_models/vgg16_fast_rcnn_iter_40000.caffemodel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ demo for data/demo/000004.jpg detection took 56.309s for 2888 object proposals all car detections with p(car | box) >= 0.8 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ demo for data/demo/001551.jpg detection took 40.754s for 2057 object proposals all sofa detections with p(sofa | box) >= 0.8 all tvmonitor detections with p(tvmonitor | box) >= 0.8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

参考资料:
1、http://blog.csdn.net/cyh_24/article/details/51440344 卷积神经网络-进化史 从lenet到alexnet

2、accelerating the super-resolution convolutional neural network
chao dong, chen change loy, and xiaoou tang
department of information engineering, the chinese university of hong kong

3、http://www.cnblogs.com/louyihang-loves-baiyan/p/4885659.html fastrcnn 训练自己数据集 (1编译配置)
git clone –recursive https://github.com/rbgirshick/fast-rcnn.git

ubuntu:~$ git clone --recursive https://github.com/rbgirshick/fast-rcnn.git fatal: destination path 'fast-rcnn' already exists and is not an empty directory. @ubuntu:~$ rm -rf fast-rcnn/ @ubuntu:~$ git clone --recursive https://github.com/rbgirshick/fast-rcnn.git cloning into 'fast-rcnn'... remote: counting objects: 1269, done. remote: compressing objects: 100% (3/3), done. remote: total 1269 (delta 2), reused 2 (delta 2), pack-reused 1264 receiving objects: 100% (1269/1269), 452.91 kib | 27.00 kib/s, done. resolving deltas: 100% (793/793), done. checking connectivity... done. submodule 'caffe-fast-rcnn' (https://github.com/rbgirshick/caffe-fast-rcnn.git) registered for path 'caffe-fast-rcnn' cloning into 'caffe-fast-rcnn'... remote: counting objects: 23976, done. remote: compressing objects: 100% (2/2), done. remote: total 23976 (delta 0), reused 0 (delta 0), pack-reused 23974 receiving objects: 100% (23976/23976), 31.60 mib | 37.00 kib/s, done. resolving deltas: 100% (15681/15681), done. checking connectivity... done. submodule path 'caffe-fast-rcnn': checked out 'bcd9b4eadc7d8fbc433aeefd564e82ec63aaf69c'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

出现问题:

@ubuntu:~/fast-rcnn/lib$ make python setup.py build_ext --inplace traceback (most recent call last):file "setup.py", line 11, in <module>from cython.distutils import build_ext importerror: no module named cython.distutils make: *** [all] error 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

解决:sudo apt-get install cython

sudo apt-get install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel

4、http://www.w2bc.com/article/125121 目标检测 faster rcnn算法详解
5、http://www.w2bc.com/article/168733 rcnn fast-rcnn faster-rcnn资料
6、http://www.w2bc.com/article/128354 rcnn学习笔记(7):faster r-cnn 英文论文翻译笔记
faster r-cnn: towards real-time object detection with region proposal networks

7、http://www.w2bc.com/article/120530 目标检测 fast rcnn算法详解
8、http://www.w2bc.com/article/136766 faster_rcnn c 版本的 caffe 封装,动态库(2)
9、http://www.cnblogs.com/louyihang-loves-baiyan/p/5485955.html faster_rcnn c 版本的 caffe 封装(1)

10、https://github.com/yihanglou/fasterrcnn-encapsulation-cplusplus

11、http://blog.csdn.net/xyy19920105/article/details/50440957 将faster rcnn的python demo改成c demo

12、http://m.blog.csdn.net/article/details?id=51036677 目标检测 fast rcnn算法详解

13、http://jingyan.baidu.com/article/eae07827f7f2d01fec5485f7.html ubuntu 安装python

14、http://www.cnblogs.com/linkboy1980/p/5469994.html caffe fastercnn安装记录

15、http://blog.csdn.net/ture_dream/article/details/52758422 一张图理清cnn脉络 rcnn spp fastrcnn fasterrcnn 到 mscnn

补充资料:
https://github.com/rbgirshick/fast-rcnn
this code base is no longer maintained and exists as a historical artifact to supplement my iccv 2015 paper. for more recent work that’s faster and more accurrate, please see faster r-cnn (which also includes functionality for training fast r-cnn).
fast r-cnn: fast region-based convolutional networks for object detection

created by ross girshick at microsoft research, redmond.
introduction

fast r-cnn is a fast framework for object detection with deep convnets. fast r-cnn

trains state-of-the-art models, like vgg16, 9x faster than traditional r-cnn and 3x faster than sppnet, runs 200x faster than r-cnn and 10x faster than sppnet at test-time, has a significantly higher map on pascal voc than both r-cnn and sppnet, and is written in python and c /caffe.

fast r-cnn was initially described in an arxiv tech report and later published at iccv 2015.
license

fast r-cnn is released under the mit license (refer to the license file for details).
citing fast r-cnn

if you find fast r-cnn useful in your research, please consider citing:

@inproceedings{girshickiccv15fastrcnn,
author = {ross girshick},
title = {fast r-cnn},
booktitle = {international conference on computer vision ({iccv})},
year = {2015}
}

contents

requirements: software requirements: hardware basic installation demo beyond the demo: training and testing usage extra downloads

requirements: software

requirements for caffe and pycaffe (see: caffe installation instructions)note: caffe must be built with support for python layers!# in your makefile.config, make sure to have this line uncommented with_python_layer := 1you can download my makefile.config for reference. python packages you might not have: cython, python-opencv, easydict [optional] matlab (required for pascal voc evaluation only)

requirements: hardware

for training smaller networks (caffenet, vgg_cnn_m_1024) a good gpu (e.g., titan, k20, k40, ...) with at least 3g of memory suffices for training with vgg16, you'll need a k40 (~11g of memory)

installation (sufficient for the demo)

clone the fast r-cnn repository# make sure to clone with --recursive git clone --recursive https://github.com/rbgirshick/fast-rcnn.gitwe'll call the directory that you cloned fast r-cnn into frcn_rootignore notes 1 and 2 if you followed step 1 above.note 1: if you didn't clone fast r-cnn with the --recursive flag, then you'll need to manually clone the caffe-fast-rcnn submodule:git submodule update --init --recursivenote 2: the caffe-fast-rcnn submodule needs to be on the fast-rcnn branch (or equivalent detached state). this will happen automatically if you follow these instructions.build the cython modulescd $frcn_root/lib makebuild caffe and pycaffecd $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 pycaffedownload pre-computed fast r-cnn detectorscd $frcn_root ./data/scripts/fetch_fast_rcnn_models.shthis will populate the $frcn_root/data folder with fast_rcnn_models. see data/readme.md for details.

demo

after successfully completing basic installation, you’ll be ready to run the demo.

python

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. the object proposals are pre-computed in order to reduce installation requirements.

note: if the demo crashes caffe because your gpu doesn’t have enough memory, try running the demo with a small network, e.g., ./tools/demo.py –net caffenet or with –net vgg_cnn_m_1024. or run in cpu mode ./tools/demo.py –cpu. type ./tools/demo.py -h for usage.

matlab

there’s also a basic matlab demo, though it’s missing some minor bells and whistles compared to the python version.

cd $frcn_root/matlab
matlab # wait for matlab to start…

fast_rcnn_demo

fast r-cnn training is implemented in python only, but test-time detection functionality also exists in matlab. see matlab/fast_rcnn_demo.m and matlab/fast_rcnn_im_detect.m for details.

computing object proposals

the demo uses pre-computed selective search proposals computed with this code. if you’d like to compute proposals on your own images, there are many options. here are some pointers; if you run into trouble using these resources please direct questions to the respective authors.

selective search: original matlab code, python wrapper edgeboxes: matlab code gop and lpo: python code mcg: matlab code rigor: matlab code

apologies if i’ve left your method off this list. feel free to contact me and ask for it to be included.
beyond the demo: installation for training and testing models

download the training, validation, test data and vocdevkitwget http://host.robots.ox.ac.uk/pascal/voc/voc2007/voctrainval_06-nov-2007.tar wget http://host.robots.ox.ac.uk/pascal/voc/voc2007/voctest_06-nov-2007.tar wget http://host.robots.ox.ac.uk/pascal/voc/voc2007/vocdevkit_08-jun-2007.tarextract all of these tars into one directory named vocdevkittar xvf voctrainval_06-nov-2007.tar tar xvf voctest_06-nov-2007.tar tar xvf vocdevkit_08-jun-2007.tarit should have this basic structure$vocdevkit/ # development kit $vocdevkit/voccode/ # voc utility code $vocdevkit/voc2007 # image sets, annotations, etc. # ... and several other directories ...create symlinks for the pascal voc datasetcd $frcn_root/data ln -s $vocdevkit vocdevkit2007using symlinks is a good idea because you will likely want to share the same pascal dataset installation between multiple projects. [optional] follow similar steps to get pascal voc 2010 and 2012 follow the next sections to download pre-computed object proposals and pre-trained imagenet models

download pre-computed selective search object proposals

pre-computed selective search boxes can also be downloaded for voc2007 and voc2012.

cd $frcn_root
./data/scripts/fetch_selective_search_data.sh

this will populate the $frcn_root/data folder with selective_selective_data.
download pre-trained imagenet models

pre-trained imagenet models can be downloaded for the three networks described in the paper: caffenet (model s), vgg_cnn_m_1024 (model m), and vgg16 (model l).

cd $frcn_root
./data/scripts/fetch_imagenet_models.sh

these models are all available in the caffe model zoo, but are provided here for your convenience.
usage

train a fast r-cnn detector. for example, train a vgg16 network on voc 2007 trainval:

./tools/train_net.py –gpu 0 –solver models/vgg16/solver.prototxt \
–weights data/imagenet_models/vgg16.v2.caffemodel

if you see this error

environmenterror: matlab command ‘matlab’ not found. please add ‘matlab’ to your path.

then you need to make sure the matlab binary is in your $path. matlab is currently required for pascal voc evaluation.

test a fast r-cnn detector. for example, test the vgg 16 network on voc 2007 test:

./tools/test_net.py –gpu 1 –def models/vgg16/test.prototxt \
–net output/default/voc_2007_trainval/vgg16_fast_rcnn_iter_40000.caffemodel

test output is written underneath $frcn_root/output.

compress a fast r-cnn model using truncated svd on the fully-connected layers:

./tools/compress_net.py –def models/vgg16/test.prototxt \
–def-svd models/vgg16/compressed/test.prototxt \
–net output/default/voc_2007_trainval/vgg16_fast_rcnn_iter_40000.caffemodel

./tools/test_net.py –gpu 0 –def models/vgg16/compressed/test.prototxt \
–net output/default/voc_2007_trainval/vgg16_fast_rcnn_iter_40000_svd_fc6_1024_fc7_256.caffemodel

experiment scripts

scripts to reproduce the experiments in the paper (up to stochastic variation) are provided in $frcn_root/experiments/scripts. log files for experiments are located in experiments/logs.

note: until recently (commit a566e39), the rng seed for caffe was not fixed during training. now it’s fixed, unless train_net.py is called with the –rand flag. results generated before this commit will have some stochastic variation.
extra downloads

experiment logs pascal voc test set detectionsvoc_2007_test_results_fast_rcnn_caffenet_trained_on_2007_trainval.tgzvoc_2007_test_results_fast_rcnn_vgg16_trained_on_2007_trainval.tgzvoc_2007_test_results_fast_rcnn_vgg_cnn_m_1024_trained_on_2007_trainval.tgzvoc_2012_test_results_fast_rcnn_vgg16_trained_on_2007_trainvaltest_2012_trainval.tgzvoc_2012_test_results_fast_rcnn_vgg16_trained_on_2012_trainval.tgz fast r-cnn vgg16 model trained on voc07 train,val,test union with voc12 train,val

本文地址:http://blog.csdn.net/forest_world

与50位技术专家面对面20年技术见证,附赠技术全景图

总结

以上是凯发k8官方网为你收集整理的caffe-fast-rcnn(caffe、fsrcnn、fastrcnn)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图