WSL CONDA Caffe foster RCNN CPU version installation



In this paper, the Caffe foster RCNN CPU version is installed in WSL (windows subsystem for linux) based on Anconda3. The plan is to build a CPU environment on a notebook for code understanding and reasoning testing. The model training plan is implemented on the cloud platform.

Creating a virtual environment with conda

conda create -n caffe_py27 python=2.7

Tip: update related system source, conda source

Follow up to Caffe? Py27 for operation

conda activate caffe_py27

Git download fast RCNN Library

Original download instruction: git clone -- recursive
Due to the slow download speed of github, code cloud ( is used for download.

git clone
cd ./py-faster-rcnn/

Download Caffe fast RCNN (! Note that @ 0dcd397 in the author library is the corresponding upload version! I repeated it several times before I found out...)

git clone
cd ./caffe-fast-rcnn
git checkout 0dcd397 #This is synchronized to the specified version of commit

Install python dependencies

Go to the directory. \ py fast RCNN \ Caffe fast RCNN \ Python

pip install -r requirements.txt

You are using pip version 9.0.1, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

pip install --upgrade pip

Collecting pip
Downloading (1.4MB)
4% |█▍ | 61kB 4.2kB/s eta 0:05:33E
Network link broken
You can directly copy the link to download it through thunderbolt, and install it with the following command (the installation file needs to be copied to the current directory)

pip install pip-20.0.2-py2.py3-none-any.whl

Many are caused by bad network timeout; you can try to increase the waiting delay

sudo pip install --default-timeout=100 future


Update by command

pip install --upgarde python-dateutil

Update success

In addition, the relevant version in requirements.txt needs to be modified: Python dateutil > = 1.4, < 2.9  
There are many libraries that are too slow to update online, which are basically downloaded through Xunlei and then installed; some of them are uploaded to csdn resources, please download by yourself.

Compile configuration modification

Go to the directory. \ py fast RCNN \ Caffe fast RCNN
Copy profile

cp Makefile.config.example Makefile.config

Remove notes

 CPU_ONLY := 1

Configure Python path (based on Anaconda3 python2.7)

 ANACONDA_HOME := $(HOME)/anaconda3/envs/caffe_py27
		 $(ANACONDA_HOME)/include/python2.7 \
		 $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

Add hd5f library path

/usr/include/hdf5/serial and / usr / lib / x86_linuxgnu / HDF5 / serial

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

ps: do not know your own python path:

python #Enter python script
import sys

Compile lib

Go to the directory \ py foster RCNN \ Lib
Modify the contents of
Notes correspond to the following

#CUDA = locate_cuda()  only cpu
#self.set_executable('compiler_so', CUDA['nvcc'])  only cpu

# Extension('nms.gpu_nms',
        # ['nms/', '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']]
    # ),

Then make

pip install easydict

ImportError: No module named cv2

pip install opencv-python

Compile Caffe

Enter Directory \py-faster-rcnn\caffe-fast-rcnn

make pycaffe

No error will be reported normally. If the error is reported, check whether there is something missing or version conflict


Model download required:


Internet download too slow:
Provide Baidu disk download link:
Links: Extraction code: jmz6

Because of using cpu, we need to modify the relevant content in lib
The results are as follows:

from fast_rcnn.config import cfg
#from nms.gpu_nms import gpu_nms
from nms.cpu_nms import cpu_nms

def nms(dets, thresh, force_cpu=False):
    """Dispatch to either CPU or GPU NMS implementations."""

    if dets.shape[0] == 0:
        return []
    # if cfg.USE_GPU_NMS and not force_cpu:
        # return gpu_nms(dets, thresh, device_id=cfg.GPU_ID)
        return cpu_nms(dets, thresh)

Go to. \ py foster RCNN

python .tools/ --cpu

Final success!!!

Loaded network /mnt/d/9_deeplearning/caffe_rcnn_try/py-faster-rcnn/data/faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel
Demo for data/demo/000456.jpg
Detection took 29.743s for 300 object proposals
Demo for data/demo/000542.jpg
Detection took 21.961s for 161 object proposals
Demo for data/demo/001150.jpg
Detection took 22.609s for 194 object proposals
Demo for data/demo/001763.jpg
Detection took 20.895s for 196 object proposals
Demo for data/demo/004545.jpg
Detection took 22.609s for 300 object proposals

The following figure shows that "ROI ﹣ pooling ﹣ param" is a caffe version error, and the "0 version dcd397" uploaded by the author should be used

On multiple protobuf Libraries
You can view the version through protoc --version;
You can also see which versions are installed
conda list and pip list
There may be different versions of the above two commands, which can be uninstalled
Protobuf Library in conda includes libprotobuf and protobuf

conda remove libprotobuf
pip uninstall protobuf

Finally, I installed protobuf version 2.6.1
Install successfully through pip install protobuf==2.6.1
Reference link:

27 original articles published, praised 8, visited 60000+
Private letter follow

Keywords: pip Python git network

Added by chenggn on Mon, 10 Feb 2020 09:55:13 +0200