赞
踩
caffe支持python2.x
所以这里,重新安装了Ancona2,将环境变量改为
export PATH=/home/devops/anaconda2/bin:$PATH
另外 linux自带的python 安装第三模块要使用下面命令来安装
pip install python-numpy
而anconda下则可以使用conda或者pip来安装python的第三方模块
1.按照官网的安装依赖库
sudo yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
sudo yum install gflags-devel glog-devel lmdb-devel
yum install atlas-devel
yum install python-devel
sudo yum install openblas-devel
2.安装caffe
wget -c https://github.com/BVLC/caffe/archive/1.0.tar.gz
tar zxvf 1.0.tar.gz
cd caffe-1.0
cp Makefile.config.example Makefile.config
3.修改文件
编辑 Makefile.config 文件,
修改前
BLAS := atlas
修改后
BLAS := open
4.编译:
make all
make test
make runtest
make pycaffe
编译 pycaffe时报错:fatal error: numpy/arrayobject.h没有那个文件或目录
其实numpy已经是安装的,anaconda2里面有,python中import numpy也没有问题,
这是因为找不到numpy的路径,通过以下python脚本找到numpy的路径,
import numpy as np np.get_include()
解决方法:
sudo vi Makefile.config
添加
\
/home/devops/anaconda2/lib/python2.7/site-packages/numpy/core/include
5.使用caffe
添加环境变量
sudo vi /etc/profile
export PYTHONPATH=/home/devops/caffe-1.0/python:$PYTHONPATH
python
import caffe
6.报错:
ImportError: No module named google.protobuf.internal
解决方法:
sudo chmod 777 -R anaconda2
conda install protobuf
7.linux本机自带的python要使用caffe
要安装
sudo pip install numpy
sudo pip install scikit-image numpy
(1)python2.7和anaconda3的python3.5共存
在配置文件中添加 黑色的部分,即可让linux自带的python2.7和anaconda3的python3.5共存
export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}$
export PATH=/home/devops/anaconda3/bin:$PATH
export CUDA_HOME=/usr/local/cuda
export PYTHONPATH=/home/devops/caffe-1.0/python:$PYTHONPATH
alias py27="/usr/bin/python2.7"
alias pyana3="/home/myname/anaconda3/bin/python3.6"
这样
使用python和pyana3进入的都是python3.6的环境,,使用py27进入的是是python2.7的环境
(2)让python2.7的pip小工具和python3.5 的pip小工具共存
cd /home/devops/anaconda3/bin
mv pip pipconda3
cd /home/devops/anaconda2/bin
mv pip pipconda2
这样
使用pip list看的就是python2.7的第三方包,使用pipconda3 list 看的就是python3.5的第三方包
安装caffe-kd
https://github.com/yjxiong/caffe/tree/kd
1.cd /home/devops/caffe-kd
2.mkdir build && cd build
yum install cmake 3.cmake .. -DUSE_MPI=ON
(1)报错:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
MPI_CXX_LIBRARIES (ADVANCED)
linked by target "caffe" in directory /home/devops/caffe-kd/src/caffe
MPI_HEADER_PATH
解决:
sudo yum install openmpi openmpi-devel
sudo vi /etc/profile
export PATH=/usr/lib64/openmpi/bin/:${PATH}
source /etc/profile
(2)报错:Could NOT find Atlas (missing: Atlas_CBLAS_INCLUDE_DIR
Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY
Atlas_LAPACK_LIBRARY)
解决方式1:
这种解决方式是使用atlas来编译的,相当的不友好,在之后make install的时候会继续报错
cmake .. -DUSE_MPI=ON .. -DAtlas=/usr/lib64/atlas
解决方式2:
优点:这种解决方式是使用openbals来编译的,相比atlas友好太多了,在之后make install的时候可以编译成功
cmake .. -DUSE_MPI=ON -DBLAS=open
修改sudo vi Makefile.config ,将默认的atlas改为open即可
/home/devops/software/OpenBLAS/usr/local/include
/home/devops/software/OpenBLAS/usr/local/lib
缺点:是要下载Openblas的安装包,然后编译,并设置环境变量
查看安装的atlas
sudo yum list installed | grep atlas
sudo yum list installed | grep blas
卸载安装的atlas
sudo yum remove atlas.x86_64 atlas-devel.x86_64
OpenBLAS安装OpenBLAS下载链接
下载后,解压,然后安装。
或者可以使用我用的版本,OpenBLAS–楼主使用的版本
然后执行下面的指令
tar -xzvf OpenBLAS.tar.gz
make
此处会报错:
undefined reference to `LAPACKE_sgesvd'……
undefined reference to `LAPACKE_zlagsy_work'……
请忽略报错即可,继续安装即可
make install PREFIX='usr/local/'
配置环境变量
sudo vi /etc/profile
export OpenBLAS_HOME=/home/devops/software/OpenBLAS/usr/local
source /etc/profile
4.make && make install
(3)报错:
[ 1%] Building CXX object src/caffe/CMakeFiles/proto.dir/__/__/include/caffe/proto/caffe.pb.cc.o
In file included from /home/devops/caffe-kd/build/include/caffe/proto/caffe.pb.cc:4:0:
/home/devops/caffe-kd/build/include/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
#error This file was generated by a newer version of protoc which is
^
/home/devops/caffe-kd/build/include/caffe/proto/caffe.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
#error incompatible with your Protocol Buffer headers. Please update
^
/home/devops/caffe-kd/build/include/caffe/proto/caffe.pb.h:14:2: error: #error your headers.
#error your headers.
^
In file included from /home/devops/caffe-kd/build/include/caffe/proto/caffe.pb.cc:4:0:
/home/devops/caffe-kd/build/include/caffe/proto/caffe.pb.h:23:35: fatal error: google/protobuf/arena.h: No such file or directory
#include <google/protobuf/arena.h>
^
compilation terminated.
make[2]: *** [src/caffe/CMakeFiles/proto.dir/__/__/include/caffe/proto/caffe.pb.cc.o] Error 1
make[1]: *** [src/caffe/CMakeFiles/proto.dir/all] Error 2
make: *** [all] Error 2
主要原因:是protobuf 的版本有问题,估计是装的protobuf 的版本太多了,导致不知道找那个了,其实是因为anconda中的protobuf和这里的冲突了
解决方法:把环境变量中的anaconda的路径给注释掉,让其不再排斥
查看当前protoc版本:protoc --version
查看protoc安装位置:which protoc
查找protoc相关文件:sudo find / -name protoc
找到所有protoc相关文件都删除
(4)报错:
[1%]BuildingNVCC(Device)object src/caffe/CMakeFiles/cuda_compile.dir/layers/./cuda_compile_generated_normalize_layer.cu.o
/home/devops/caffe-kd/include/caffe/util/cudnn.hpp(107): error: too few arguments in function call
1 error detected in the compilation of "/tmp/tmpxft_000069cb_00000000-5_normalize_layer.cpp4.ii".
CMake Error at cuda_compile_generated_normalize_layer.cu.o.cmake:264 (message):
Error generating file
/home/devops/caffe-kd/build/src/caffe/CMakeFiles/cuda_compile.dir/layers/./cuda_compile_generated_normalize_layer.cu.o
make[2]: *** [src/caffe/CMakeFiles/cuda_compile.dir/layers/./cuda_compile_generated_normalize_layer.cu.o] Error 1
make[1]: *** [src/caffe/CMakeFiles/caffe.dir/all] Error 2
make: *** [all] Error 2
原因:cdunn的v6比v5多一个参数,参照win10-caffe-gpu编译注意
解决方法:但是这种方法会有各种警告,最终编译还是失败
cd /home/devops/caffe-kd/include/caffe/util
vi cudnn.hpp
修改第 107行
原来:
CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,
pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION));
现在改成:
CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,
pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION,CUDNN_DATA_FLOAT));
然后再重新make && make install即可
(5)报错(解决方式1导致的错误):
[ 91%] Building CXX object tools/CMakeFiles/caffe.bin.dir/caffe.cpp.o
Linking CXX executable caffe
../lib/libcaffe.so: undefined reference to `cblas_sgemv'
../lib/libcaffe.so: undefined reference to `cblas_dgemm'
../lib/libcaffe.so: undefined reference to `cblas_sscal'
../lib/libcaffe.so: undefined reference to `cblas_dgemv'
../lib/libcaffe.so: undefined reference to `cblas_saxpy'
../lib/libcaffe.so: undefined reference to `cblas_ddot'
../lib/libcaffe.so: undefined reference to `cblas_dasum'
../lib/libcaffe.so: undefined reference to `cblas_sgemm'
../lib/libcaffe.so: undefined reference to `cblas_dscal'
../lib/libcaffe.so: undefined reference to `cblas_scopy'
../lib/libcaffe.so: undefined reference to `cblas_sasum'
../lib/libcaffe.so: undefined reference to `cblas_daxpy'
../lib/libcaffe.so: undefined reference to `cblas_dcopy'
../lib/libcaffe.so: undefined reference to `cblas_sdot'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/caffe] Error 1
make[1]: *** [tools/CMakeFiles/caffe.bin.dir/all] Error 2
make: *** [all] Error 2
解决:改错没找到解决方案,坑了,建议放弃atlas方式安装
(6)报错(解决方式2导致的错误):
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
CMake Error at cmake/Modules/FindOpenBLAS.cmake:53 (MESSAGE):
Could not find OpenBLAS
Call Stack (most recent call first):
cmake/Dependencies.cmake:78 (find_package)
CMakeLists.txt:30 (include)
解决:下载并编译openblas,同时设置openblas的环境变量,使用yum的方式安装openblas是不行的,因为安装的路径无法被caffe找到,从报错信息中查看源码可以看到,只有在以下路径才能被检测到openblas
(7)报错:
[devops@data-mining-gpu-1 caffe-kd]$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
#include <numpy/arrayobject.h>
解决:
查找 numpy所在的目录
sudo find / -name numpy
可以得到路径/usr/lib64/python2.7/site-packages/numpy
和/usr/lib64/python2.7/site-packages/numpy/core/include/numpy
修改配置文件Makefile.config,加入找到的路径
sudo vi Makefile.config
报错:
_caffe.so: undefined symbol: _ZN5caffe4mtx_E
解决:
修改 sudo vi Makefile.config
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
但是要把整个项目删掉,重新编译pycaffe才行,否则还是报这个错
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。