http://caffe.berkeleyvision.org/
1: 下载源码
git clone https://github.com/BVLC/caffe && cd caffe
2: 更改配置
首先: cp Makefile.config.example Makefile.config
编辑: vim Makefile.config
USE_CUDNN := 1
OPENCV_VERSION := 3
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
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
其中如使用了GPU则需要取消USE_CUDNN的注解,及根据CUDA的版本相应的更改CUDA_ARCH,根据所使用的opencv的版本决定是否需要取消OPENCV_VERSION的注释.
然后修改Makefile文件中的LIBRARIES为
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
3: 编译
make -j && make pycaffe
4:安装基础包
可根据requirements.txt中的说明进行相应的安装
cd ~/caffe/python
# 这里面是了些python常用包,需要装不上的直接删去
pip install –r requirements.txt
5: 设置环境变量
export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
6:验证
root@smart:/usr/local# python2.7
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>> exit()
7: 成功安装
问题描述:
./include/caffe/util/hdf5.hpp:7:18: fatal error: hdf5.h: 没有那个文件或目录
解决方案:
修改Makefile.config文件,在INCLUDE_DIRS最后增加 /usr/include/hdf5/serial/
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
Makefile中修改为
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
问题描述:
/usr/bin/ld: 找不到 -lhdf5_hl
/usr/bin/ld: 找不到 -lhdf5
collect2: error: ld returned 1 exit status
Makefile:582: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1
解决方案:
找到.so文件的位置然后cp到/usr/local/lib/路径下
root@smart:~/Muyi/caffe# locate libhdf5.so
/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so
root@smart:~/Muyi/caffe# locate libhdf5_hl.so
/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_hl.so
cp /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so /usr/local/lib/
cp /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_hl.so /usr/local/lib/
然后重新编译即可
问题描述:
.build_release/lib/libcaffe.so:对‘cv::imread(cv::String const&, int)’未定义的引用
解决方案:
查看已安装的opencv版本
root@smart:~/Muyi/caffe# pip2.7 list | grep opencv
opencv-python 4.0.0.21
版本为3.0之上,则需要相应的去掉OPENCV_VERSION位置的注释
修改Makefile.config文件,去除OPENCV_VERSION位置的注释
问题描述:
python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: 没有那个文件或目录
解决方案:
在Makefile.config找到PYTHON_INCLUDE,发现有点不同:
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
要加一个local,变成:
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
问题描述:
Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4.
解决方案:
更换低版本Matplotlib即可,例更换为2.2.3
pip2.7 install matplotlib==2.2.3
相应的出现的其他安装失败的情况只需要相应的做版本升级或者降低版本即可
问题描述:
IPython 7.0+ supports Python 3.5 and above.
解决方案:
指定低版本的ipython即可
pip2.7 install ipython==5.3.0
如不知道版本号,可以
root@smart:/usr/local# pip2.7 install ipython==000
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting ipython==000
Could not find a version that satisfies the requirement ipython==000 (from versions: 0.10, 0.10.1, 0.10.2, 0.11, 0.12, 0.12.1, 0.13, 0.13.1, 0.13.2, 1.0.0, 1.1.0, 1.2.0, 1.2.1, 2.0.0, 2.1.0, 2.2.0, 2.3.0, 2.3.1, 2.4.0, 2.4.1, 3.0.0, 3.1.0, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 4.0.0b1, 4.0.0, 4.0.1, 4.0.2, 4.0.3, 4.1.0rc1, 4.1.0rc2, 4.1.0, 4.1.1, 4.1.2, 4.2.0, 4.2.1, 5.0.0b1, 5.0.0b2, 5.0.0b3, 5.0.0b4, 5.0.0rc1, 5.0.0, 5.1.0, 5.2.0, 5.2.1, 5.2.2, 5.3.0, 5.4.0, 5.4.1, 5.5.0, 5.6.0, 5.7.0, 5.8.0, 6.0.0rc1, 6.0.0, 6.1.0, 6.2.0, 6.2.1, 6.3.0, 6.3.1, 6.4.0, 6.5.0, 7.0.0b1, 7.0.0rc1, 7.0.0, 7.0.1, 7.1.0, 7.1.1, 7.2.0, 7.3.0)
No matching distribution found for ipython==000
root@smart:/usr/local# pip2.7 install ipython==5.4.0