ubuntu16.04 install Caffe1.0

1. First install various dependency packages

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libopenblas-dev
sudo apt-get install the python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

2. Download caffe

Most of the tutorials for installing caffe found on the Internet are git download https://github.com/BVLC/caffe

But there is a caffe3d folder
in the inherited file, which can be obtained from https://github.com/fyu/caffe3d on GitHub

After that, I got the clue information in the readme file of the existing folder and
found Video-Caffe: Caffe with C3D implementation and video reader,
https://github.com/chuckcho/video-caffe
that is Video-Caffe: with C3D implementation and Caffe of video reader,

In the existing papers, it is also mentioned that the experimental environment is the R-C3D network based on the caffe framework with the added video processing layer,
so it is now recognized as Video-Caffe on GitHub.


3. Modify the file

3.1 Makefile.config

Because the make command can only make Makefile.config file, and Makefile.config.example is the makefile example given by caffe.

Therefore, first copy the contents of Makefile.config.example to Makefile.config:
sudo cp Makefile.config.example Makefile.config

Then modify the Makefile.config file and open the file in the caffe directory:
sudo gedit Makefile.config

Modify the contents of the Makefile.config file according to personal circumstances:
(1) If cudnn is used, then:

将
#USE_CUDNN := 1
修改成: 
USE_CUDNN := 1

(2) If the opencv version used is 3, then:

将
#OPENCV_VERSION := 3 
修改为: 
OPENCV_VERSION := 3

(3) If it is CUDA version >=9.0, the calculation power of 20 and 21 will be removed, as follows:

CUDA_ARCH := \
#-gencode arch=compute_20,code=sm_20 \
#		-gencode arch=compute_20,code=sm_21 \
		-gencode arch=compute_30,code=sm_30 \
		-gencode arch=compute_35,code=sm_35 \
		-gencode arch=compute_50,code=sm_50 \
		-gencode arch=compute_52,code=sm_52 \
		-gencode arch=compute_60,code=sm_60 \
		-gencode arch=compute_61,code=sm_61 \
		-gencode arch=compute_61,code=compute_61

PS: I have a file that I have used before, using CUDA8.0. The above file has been modified as follows:

# For CUDA < 6.0, comment the *_50 lines for compatibility.
#CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
		-gencode arch=compute_20,code=sm_21 \
		-gencode arch=compute_30,code=sm_30 \
		-gencode arch=compute_35,code=sm_35
CUDA_ARCH := -gencode arch=compute_50,code=sm_50 \
                -gencode arch=compute_52,code=sm_52 \
                -gencode arch=compute_60,code=sm_60 \
                -gencode arch=compute_61,code=sm_61 \
                -gencode arch=compute_61,code=compute_61

(4) If you use python to write the layer, then:

将
#WITH_PYTHON_LAYER := 1 
修改为 
WITH_PYTHON_LAYER := 1

(5) An important item: Will # Whatever else you find you need goes here. The following:

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib 
修改为: 
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 /usr/lib/x86_64-linux-gnu/hdf5/serial       

3.2 Makefile

Then modify the Makefile in the caffe directory:
sudo gedit Makefile

将:
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

The following change was not in the previous file.

将:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

3.3 Edit host_config.h

Edit /usr/local/cuda/include/host_config.h and comment out line 115:
sudo gedit /usr/local/cuda/include/host_config.h

将
#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
改为
//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!

4. Compile

make all -j8 #-j根据自己电脑配置决定

image.png


Errors during compilation
(1) Error: Compilation error:
Makefile:568: recipe for target'.build_release/lib/libcaffe.so.1.0.0-rc3' failed
Solution:
https://blog.csdn.net/ CAU_Ayao/article/details/84023510
(2) Error:
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_videoio
Picture.png
Solution:
https://blog.csdn.net/w113691 /article/details/77942408 See this tutorial.
https://blog.csdn.net/Dillon2015/article/details/79858116


5. Testing

make test -j8

image.png

make runtest -j8

image.png

If the displayed result is as shown in the figure above, it means that caffe has been installed successfully.

出错:recipe for target ‘runtest’ failed
Picture.png


PS: Because runtest has always made mistakes, all thoughts are lost. Finally, I chose to use the viedo-caffe downloaded on GitHub, and re-modify the file-compile-configure


Configure pycaffe:

sudo make pycaffe -j16 // Place pycaffe

image.png

6. Environment variable configuration:

gedit ~/.bashrc

Add at the end:
fill in the python directory under your caffe here

export PYTHONPATH=~/caffe/python:$PYTHONPATH to
make the environment variable take effect:

source ~/.bashrc

7. Guide package test

Enter python to enter the python environment, and then continue to enter
import caffe

pip installs the missing packages. After the installation is complete, import caffe is complete.


At 19:06 on March 12, 2021,
the version downloaded from the Internet does not seem to work, but the built-in caffe3d is still installed.

Guess you like

Origin blog.csdn.net/LemonShy2019/article/details/114920491