Py-faster-rcnn: How to setup with CPU ONLY mode

Created on 22 Mar 2016  Â·  26Comments  Â·  Source: rbgirshick/py-faster-rcnn

I'd like to install py-faster-rcnn in CPU ONLY mode. Is this possible? Which configuration files should I modify?

Thanks.

Most helpful comment

It is definitely possible but not recommended. CPU version is almost two magnitude slower than GPU as I tested a few months ago. Here is a quick list of modifications.

  • Set USE_GPU_NMS in ./lib/fast_rcnn/config.py (or your YAML file) to False.
  • In ./tools/test_net.py / train_net.py, replace caffe.set_mode_gpu() with caffe_set_mode_cpu().
  • Plus, if you do not have a GPU, you can compile Caffe in CPU_ONLY mode (and also ignore the GPU nms code).

All 26 comments

It is definitely possible but not recommended. CPU version is almost two magnitude slower than GPU as I tested a few months ago. Here is a quick list of modifications.

  • Set USE_GPU_NMS in ./lib/fast_rcnn/config.py (or your YAML file) to False.
  • In ./tools/test_net.py / train_net.py, replace caffe.set_mode_gpu() with caffe_set_mode_cpu().
  • Plus, if you do not have a GPU, you can compile Caffe in CPU_ONLY mode (and also ignore the GPU nms code).

I made the changes you mentioned. When I try to build the cython modules, i.e. after running

cd $FRCN_ROOT/lib; make

I get:

python setup.py build_ext --inplace
Traceback (most recent call last):
File "setup.py", line 58, in
CUDA = locate_cuda()
File "setup.py", line 46, in locate_cuda
raise EnvironmentError('The nvcc binary could not be '
EnvironmentError: The nvcc binary could not be located in your $PATH. Either add it to your path, or set $CUDAHOME
make: *** [all] Error 1

As I said, you will need to ignore GPU nms code. You can do so by removing 'nms.gpu_nms' module in ./libs/setup.py.

@eakbas, I did everything as @happyharrycn recommended, including his last recommendation, but, anyway, I got the same error message as you did. But after that I removed line "CUDA = locate_cuda()" in ./lib/setup.py, after that I executed "cd $FRCN_ROOT/lib; make" and it went without error messages.

cd $FRCN_ROOT/lib, modify setup.py,annotate these code that are correlative GPU, then make

...

CUDA = locate_cuda()

...
...

self.set_executable('compiler_so', CUDA['nvcc'])

...
...

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']]

)

@happyharrycn @eakbas @SrCMpink @dumka
I am trying to implement CPU_ONLY mode. I have followed this complete issue and made a clean make for ./lib. It gave no error. But upon running the demo from ./tools/demo.py it gave error as:

F0825 21:46:15.782125 7066 common.cpp:55] Cannot use GPU in CPU-only Caffe: check mode.

All modifications are made by me given in the post. Please suggest some solution.

@shubh-agrawal Are you running demo.py with the --cpu option specified?

No I haven't. I tried it out but came up with this error now,

[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".
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0826 11:47:10.569231 2981 upgrade_proto.cpp:928] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: /home/shubh/py-faster-rcnn/models/pascal_voc/VGG16/faster_rcnn_alt_opt/faster_rcnn_test.pt
* Check failure stack trace: *
Aborted (core dumped)

Any idea about this?

Can you try for --net zf and update the results?

@shubh-agrawal That looks to me like the caffe-fast-rcnn submodule is on the wrong branch. If you cd into that directory and run git checkout faster-rcnn and then rerun the demo (with the ZF net as @sandeeppalakkal suggests) what happens?

You guys solved the problem. Thank you guys. The demo worked seamlessly. @mcdickenson @sandeeppalakkal

But I would update one more modification, here, so that other fellows following similar problem could follow up. There is nms_wrapper.py which still uses nms_gpu module. Hence, it was necessary to comment out piece of code related to that in $FRCN_ROOT/lib/fast_rcnn/nms_wrapper.py.
Uncomment the import module for nms_gpu. Rest making modification as discusses in this issue will solve the problem.

I wonder, why not any documentation with much needed modification for ONLY_CPU is found over the air.

@mcdickenson I all the things mentioned above but I got the floowing error

[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 47:11: Message type "caffe.LRNParameter" has no field named "engine".

How should I go about this?

@divamgupta I'm not sure, I haven't encountered that before. It might be worth opening a separate issue for that. Are you building from master?

@divamgupta I had encountered this error before. It occurs if you are on master branch of caffe-fast-rcnn. Please checkout to other branch that will be enlisted in git branch.
I hope this helps !

I used the faster-rcnn branch. This problem is only arising in the zf model only. vgg16 is working fine.

@divamgupta
Have you solved this problem?
[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 47:11: Message type "caffe.LRNParameter" has no field named "engine".

The meaning of git checkout faster-rcnn is to checkout the "faster-rcnn"
branch. See the above discussion about the issue on the master branch.

On Wed, Feb 22, 2017 at 12:06 PM IvyGongoogle notifications@github.com
wrote:

@mcdickenson https://github.com/mcdickenson @shubh-agrawal
https://github.com/shubh-agrawal @sandeeppalakkal
https://github.com/sandeeppalakkal when I run 'tools/demo.py', I get
the same error
[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". WARNING: Logging before
InitGoogleLogging() is written to STDERR F0222 14:23:16.447522 29479
upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file,
param) Failed to parse NetParameter file:
/home/ztgong/objectDetectionAndRecognition/py-faster-rcnn/models/pascal_voc/VGG16/faster_rcnn_alt_opt/
faster_rcnn_test.pt * Check failure stack trace: *
but I do not understand the meaning of git checkout faster-rcnn' how to
solve this error?
thankyou very much!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rbgirshick/py-faster-rcnn/issues/123#issuecomment-281582786,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABC0-K3bjhUfm8PPWHDNRbIQx-qY9MTXks5re9dYgaJpZM4H2FbP
.

@happyharrycn @dumka @SrCMpink @shubh-agrawal @eakbas
Can you help me to see this problem,thanks!
http://stackoverflow.com/questions/42604481/faster-rcnn-demo-py-all-300-object-proposals-without-output-results#

Hey guys, I found this solution works.
Comment these code in lib/setup.py
`

CUDA = locate_cuda()

`

`

self.set_executable('compiler_so', CUDA['nvcc'])

`

`

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']]

),

`

And then
make

@GloryDream
Did you find there are lots of repetitive bbox in the result pictures displayed in demo.py?
I just make it in windows10 and use CPU mode,too.

@Anhaoxu
Sorry, I didn't run it successfully on my mac.

@divamgupta could you solve it? I get a segmentation fault even when I don't specify --net zf.

for test, you just need too run './tools/demo.py --cpu'.
for end2end train, as there is only Forward_gpu implementation insmooth_L1_loss_layer.cu for SmoothL1LossLayer, so it seems that you only can use GPU mode.

How many seconds on average needed for CPU-run only on a single image,say of size (224,224) ?

C:\Users\lenovo\Anaconda3python.exe D:/tf-faster-rcnn-master/lib/setup.py
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help

error: no commands supplied

I modified setup.py file ,but reported a new error

after above changes I'm getting this:

python setup.py build_ext --inplace
Traceback (most recent call last):
File "setup.py", line 12, in
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
Makefile:2: recipe for target 'all' failed
make: * [all] Error 1

When I executed pip install Cython it says:
Requirement already satisfied: cython in /usr/lib/python3/dist-packages (0.26.1)

Was this page helpful?
0 / 5 - 0 ratings