创建
conda create -n caffeEnv(虚拟环境名字) python=3.6
激活环境
source activate caffeEnv
关闭
deactivate
创建
pip install virtualenv
sudo apt-get virtualenv
virtualenv caffeEnv(虚拟环境名字) -p /usr/bin/python3(版本)
激活
cd caffeEnv && source ./bin/activate
关闭
deactivate
(我试过8.0+5.1和9.1+7.0都可以)
可以看我的另外两篇博客,亲测过好几次,可用!!!
(根据自己版本稍微修改,肯定可以的)
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
git clone https://github.com/BVLC/caffe.git
cd caffe
cp Makefile.config.example Makefile.config
复制一份的原因是编译 caffe 时需要的是 Makefile.config 文件,Makefile.config.example 只是caffe 给出的配置文件例子
gedit Makefile.config
将
#USE_CUDNN := 1
修改成:
USE_CUDNN := 1
将
#OPENCV_VERSION := 3
修改为:
OPENCV_VERSION := 3
将
#WITH_PYTHON_LAYER := 1
修改为
WITH_PYTHON_LAYER := 1
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
CUDA_DIR := /usr/local/cuda
修改为:
CUDA_DIR := /usr/local/nvidia/cuda/8.0
OK ,可以开始在 caffe 目录下编译 :
make all -j8
(-j8表示自己的cpu核数,如果不知道就直接make all)
如果出错,则检查前面步骤,或者利用搜索引擎解决问题
make runtest -j8
1、 编译
make pycaffe -j8
2、配置到环境变量
gedit ~/.bahsrc
把以下内容加到最下方
export PYTHONPATH=/(caffe所在目录)/caffe/python:$PYTHONPATH
若有多个环境需要添加则像如下添加方法,环境之后需要加“ : ”
export PYTHONPATH=/(caffe所在目录)/caffe/python:/home/xxx/python/:$PYTHONPATH
让环境变量生效
source ~/.bahsrc
have a try!看看能不能用
>>> import caffe
临时配置法(记录一下给自己看)
import sys
sys.path.append("/(caff所在目录)/caffe/python")
sys.path.append("/(caffe所在目录)/caffe/python/caffe")
最后贴一些可能会出现的安装问题:
问题:
Unsupported gpu architecture ‘compute_20’
解决方案:
https://askubuntu.com/questions/960238/nvcc-fatal-unsupported-gpu-architecture-compute-20
即去掉Makefile.config 中两行:
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_50,code=compute_50
改为:
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_62,code=sm_62 \
-gencode arch=compute_61,code=compute_61
awk: symbol lookup error: /home/lzm/.conda/envs/lzm2/lib/libreadline.so.6: undefined symbol: PC
解决方案:
https://github.com/conda-forge/rpy2-feedstock/issues/1
https://github.com/bioconda/bioconda-recipes/issues/5350
即 run
conda install -c conda-forge readline = 6.2
./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: no such file or directory
解决方案:
https://github.com/BVLC/caffe/issues/2690
https://github.com/NVIDIA/DIGITS/issues/156
即Makefile.config 拿两行改掉:
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/hdf5/serial/
./include/caffe/util/nccl.hpp:5:18: fatal error: nccl.h: No such file or directory
解决方案:
新建文件为env
将服务器已经安装的nccl路径配置到env:
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/home/lzm/data/caffe/caffe1.0_nccl/nccl/install/include
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/home/lzm/data/caffe/caffe1.0_nccl/nccl/install/include
export LIBRARY_PATH=$LIBRARY_PATH:/home/lzm/data/caffe/caffe1.0_nccl/nccl/install/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/lzm/data/caffe/caffe1.0_nccl/nccl/install/lib
每次要用的时候都激活环境:
source ./env
.build_release/lib/libcaffe.so: undefined reference to `cv::imdecode
解决方案:https://github.com/BVLC/caffe/issues/4621
把Makefile.config 中 OPENCV_VERSION = 3的注释去掉即可
/caffe/bin/…/lib/libstdc++.so.6: version `GLIBCXX_3.4.21’ not found (required by caffe-ssh/python/caffe/_caffe.so)
解决方案:https://github.com/BVLC/caffe/issues/4953
conda install libgcc