0%

Ubuntu16.04 编译安装caffe

第2次配置caffe环境吧,感觉只要之前没有瞎搞过其实caffe还挺好装的。(写的比较简略,主要记录了一些error)

Ubuntu16.04 编译安装caffe

基本按照caffe官方文档给出的操作就可以,可能会碰到一些问题,在下面记录了

error1

1
nvcc fatal   : Unsupported gpu architecture 'compute_20'

solution1

1
2
3
4
5
6
7
8
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH := -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

error2

1
2
3
4
5
In file included from ./include/caffe/blob.hpp:8:0,
from ./include/caffe/layers/absval_layer.hpp:6,
from src/caffe/layers/absval_layer.cpp:3:
./include/caffe/common.hpp:5:27: fatal error: gflags/gflags.h: 没有那个文件或目录
compilation terminated.

solution2

Commonly encountered build issues这篇里面写了一些常见的问题,确实有用。

1
2
3
sudo apt-get install libgflags-dev
sudo apt-get install libgflags-dev
sudo apt-get install libgoogle-glog-dev

error3

1
2
3
4
5
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: 找不到 -lboost_python3
collect2: error: ld returned 1 exit status
Makefile:582: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed

solution3

Solve the problem: “cannot find -lboost_python3” when using Python3 Ubuntu16.04

1
2
cd /usr/lib/x86_64-linux-gnu
sudo ln -s libboost_python-py35.so libboost_python3.so

pycaffe接口

这部分在官方文档的Python and/or MATLAB Caffe (optional)部分,

error1

1
2
3
4
5
6
7
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'caffe'

solution1

1
2
sparta:caffe$ sudo echo export PYTHONPATH="/opt/caffe/python" >> ~/.bashrc
sparta:caffe$ source ~/.bashrc

error2

1
2
3
4
5
6
7
8
9
10
11
12
13
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/caffe/python/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/opt/caffe/python/caffe/pycaffe.py", line 15, in <module>
import caffe.io
File "/opt/caffe/python/caffe/io.py", line 2, in <module>
import skimage.io
ImportError: No module named 'skimage'

solution2

1
2
cd $CAFFE_PATH/python
sudo pip3 install -r requirement.txt

error3

1
2
3
4
File "/usr/local/lib/python3.5/dist-packages/dateutil/rrule.py", line 55
raise ValueError, "Can't create weekday with n == 0"
^
SyntaxError: invalid syntax

solution3

1
sudo pip3 install python-dateutil --upgrade

欢迎关注我的其它发布渠道