WSL CONDA Caffe foster RCNN CPU version installation

Catalog

Preface

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 https://github.com/rbgirshick/py-foster-rcnn.git
Due to the slow download speed of github, code cloud (https://gitee.com/) is used for download.

git clone https://gitee.com/shaozhechen/py-faster-rcnn.git
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 https://gitee.com/liu1guo2qiang3/caffe-fast-rcnn.git
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

Tips:
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 https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (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

Tips

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
 WITH_PYTHON_LAYER := 1

Configure Python path (based on Anaconda3 python2.7)

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

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
print(sys.executable)

Compile lib

Go to the directory \ py foster RCNN \ Lib
Modify the contents of setup.py
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_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']]
    # ),

Then make
Tips:

pip install easydict

Tips:
ImportError: No module named cv2

pip install opencv-python

Compile Caffe

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

make 
make pycaffe

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

test

Model download required:

./data/scripts/fetch_faster_rcnn_models.sh

Internet download too slow:
Provide Baidu disk download link:
Links: https://pan.baidu.com/s/13yZmsgZI72sAwyKbBzzKEw Extraction code: jmz6

Because of using cpu, we need to modify the relevant content in lib
/lib/fast_rcnn/nms_wrapper.py
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)
    else:
        return cpu_nms(dets, thresh)

Go to. \ py foster RCNN

python .tools/demo.py --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

PS:
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:
[1].https://www.jianshu.com/p/30fcc3df764d

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