Ubuntu14.04 + CUDA 7.0.28 + OpenCV 2.4.10 +Caffe 环境搭建

一 NVIDIA CUDA安装。

主要参照了小村长技术博客,能够顺利安装CUDA和MKL。这其中值得注意的是,CUDA7.0.28 已经包含了NVIDIA的驱动,不需要再之前安装NVIDIA驱动,而Ubuntu14.04有默认带了NVIDIA驱动,需要按照小村长技术博客那样把他干掉。之前没有清楚认识到这点,误将其安装了结果导致开机不能进入系统,后来看到一位兄弟的博客,才意识到这个问题,能够回到系统继续下面的安装。

二 OpenCV的安装

① 首先还是尝试[1]给出的方法进行安装,在安装过程中出现在make依赖项时出现错误,报错为:

make[2]: *** 没有规则可以创建"lib/libopencv_cudev.so.3.0.0"需要的目标"/usr/lib/x86_64-linux-gnu/libGL.so"。停止
② 接着尝试手动安装,先去官网下载OpenCV2.4.9 for Linux,并且按照[2]安装,中间出现报错:

Unsupported gpu architecture 'compute_11'

参照博客[3]得以解决,进入解压后的文件夹,新建一个build,进入build,执行cmake,具体方法时添加如下语句

 
  

cd OpecnCV-2.4.10
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..
 
  
 
  

值得注意的是,这一步如果直接cmake的话,会报错,必须这样才可以。执行这条语句时要保证当前位置在OpenCV目录下的build文件夹中,文件夹所在目录应该包含CMakeList.txt文件。

再次报错

/home/cb/opencv-2.4.9/modules/gpu/src/nvidia/core/NCNVPixelOperations.hpp(51): error: a storage class is not allowed in an explicit specialization


这次保报错比较常见,解决方案是需要去官网下载一个文件NCNVPixelOperations.hpp,但是这个文件现在已经不提供下载了。所以又被迫改安装了opencv2.4.10,去官网下载相应安装文件后参照里搭建完毕可以运行。

三 安装Caffe并测试

1. 安装pycaffe必须的一些依赖项:

         

$ sudo apt-get install -y python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags Cythonipython
$ sudo apt-get install -y protobuf-c-compilerprotobuf-compiler

         ☆这里Cythonipython没有装上。

2 cuDnn安装

3 点击这里下载Caffe。


4 报错信息

① 运行make all -j8出错

make: *** [.build_release/src/caffe/layers/cudnn_lrn_layer.o] 错误 1
解决方案:参照这里【问题3】,CUDNN只支持CUDA Capability 3.0以上的GPU加速,而我的笔记本显卡GT520M才2.1的加速能力,在其他3.0以上的显卡运行正常,因此选择不启用cuDNN加速,在Makefile.config中注释USE_CUDNN行。

② 运行make runtest -j8出错

root@cb-K43SJ:/opt/caffe-master# make runtest -j8
.build_release/tools/caffe
.build_release/tools/caffe: error while loading shared libraries: libmkl_rt.so: cannot open shared object file: No such file or directory
make: *** [runtest] 错误 127

-- 可尝试如下几种解决方案。

解决方案【1】:参照这里【问题1】,重新执行:

make clean make all -j8 make test -j8 make runtest -j8

解决方案【2】:在自己的~/.bashrc 中添加library path:

LD_LIBRARY_PATH=your_anaconda_path/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

解决方案【3】:参照这里还有这里

# 后来发现此文件在/opt/intel/mkl/lib/intel64/ 中,要将此路径加入共享文件库,输入如下指令
# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/opt/intel/mkl/lib/intel64/" >> /etc/ld.so.conf
# ldconfig
③ make runtest -j8 出错

// 第一次运行
[----------] Global test environment tear-down
[==========] 927 tests from 140 test cases ran. (55790 ms total)
[  PASSED  ] 922 tests.
[  FAILED  ] 5 tests, listed below:
[  FAILED  ] SGDSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdaGradSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] NesterovSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdaDeltaSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdamSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice

 5 FAILED TESTS
make: *** [runtest] 错误 1
// 第二次运行
[----------] Global test environment tear-down
[==========] 927 tests from 140 test cases ran. (55337 ms total)
[  PASSED  ] 920 tests.
[  FAILED  ] 7 tests, listed below:
[  FAILED  ] SGDSolverTest/0.TestSnapshot, where TypeParam = caffe::CPUDevice
[  FAILED  ] SGDSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdaGradSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] NesterovSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdaDeltaSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdamSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] RMSPropSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice

 7 FAILED TESTS
make: *** [runtest] 错误 1
试一下重新clean

make clean make all -j8 make test -j8 make runtest -j8

依然有失败

[----------] Global test environment tear-down
[==========] 927 tests from 140 test cases ran. (54264 ms total)
[  PASSED  ] 919 tests.
[  FAILED  ] 8 tests, listed below:
[  FAILED  ] SGDSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdaGradSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] NesterovSolverTest/0.TestSnapshot, where TypeParam = caffe::CPUDevice
[  FAILED  ] NesterovSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdaDeltaSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdamSolverTest/0.TestSnapshot, where TypeParam = caffe::CPUDevice
[  FAILED  ] AdamSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice
[  FAILED  ] RMSPropSolverTest/0.TestSnapshotShare, where TypeParam = caffe::CPUDevice

 8 FAILED TESTS
make: *** [runtest] 错误 1

四、MNIST数据集测试:

Caffe默认情况会安装在$CAFFE_ROOT,就是解压到那个目录,例如:$ home/username/caffe-master,所以下面的工作,默认已经切换到了该工作目录。下面的工作主要是,用于测试Caffe是否工作正常,不做详细评估。具体设置请参考官网:http://caffe.berkeleyvision.org/gathered/examples/mnist.html

$ sudo sh data/mnist/get_mnist.sh
出现如下错误:

100%[======================================>] 1,936       --.-K/s   用时 0s    

2016-01-25 12:00:16 (76.5 MB/s) - 已保存 “train-images-idx3-ubyte.gz” [1936/1936])

--2016-01-25 12:00:16--  http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz
正在解析主机 yann.lecun.com (yann.lecun.com)... 128.122.47.89
正在连接 yann.lecun.com (yann.lecun.com)|128.122.47.89|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:http://202.202.0.163 [跟随至新的 URL]
--2016-01-25 12:00:17--  http://202.202.0.163/
正在连接 202.202.0.163:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 1936 (1.9K) [text/html]
正在保存至: “train-labels-idx1-ubyte.gz”

100%[======================================>] 1,936       --.-K/s   用时 0s    

2016-01-25 12:00:17 (122 MB/s) - 已保存 “train-labels-idx1-ubyte.gz” [1936/1936])

--2016-01-25 12:00:17--  http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz
正在解析主机 yann.lecun.com (yann.lecun.com)... 128.122.47.89
正在连接 yann.lecun.com (yann.lecun.com)|128.122.47.89|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:http://202.202.0.163 [跟随至新的 URL]
--2016-01-25 12:00:17--  http://202.202.0.163/
正在连接 202.202.0.163:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 1936 (1.9K) [text/html]
正在保存至: “t10k-images-idx3-ubyte.gz”

100%[======================================>] 1,936       --.-K/s   用时 0s    

2016-01-25 12:00:17 (129 MB/s) - 已保存 “t10k-images-idx3-ubyte.gz” [1936/1936])

--2016-01-25 12:00:17--  http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz
正在解析主机 yann.lecun.com (yann.lecun.com)... 128.122.47.89
正在连接 yann.lecun.com (yann.lecun.com)|128.122.47.89|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:http://202.202.0.163 [跟随至新的 URL]
--2016-01-25 12:00:17--  http://202.202.0.163/
正在连接 202.202.0.163:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 1936 (1.9K) [text/html]
正在保存至: “t10k-labels-idx1-ubyte.gz”

100%[======================================>] 1,936       --.-K/s   用时 0s    

2016-01-25 12:00:17 (101 MB/s) - 已保存 “t10k-labels-idx1-ubyte.gz” [1936/1936])

Unzipping...

gzip: train-images-idx3-ubyte.gz: not in gzip format

gzip: train-labels-idx1-ubyte.gz: not in gzip format

gzip: t10k-images-idx3-ubyte.gz: not in gzip format

gzip: t10k-labels-idx1-ubyte.gz: not in gzip format
Done.

注:我执行此命令的时候报告说not in gzformat,后来发现是联网下载的mnist数据有问题,然后我就去网上了下载了mnist数据集,后在ubuntu上手动解压的,再执行后面的命令。


五、Matlab2014a的安装

① 下载Matlab:http://pan.baidu.com/s/1pJGF5ov [Matlab2014a(密码:en52);

② 解压文件“MATHWORKS_R2014A.part1.rar”,得到相应的ISO文件;


③ 挂载到文件夹


$ cd 到要挂载的文件夹下(随便找一个文件夹都可以)
$ sudo mkdir matlab_iso
$ sudo mount -o loop [路径]/MATHWORKS_R2014A.iso /[路径]/matlab_iso
$ cd matlab_iso
$ sudo ./install

六、FCNT编译【论文下载】


参考https://gist.github.com/bearpaw/c38ef18ec45ba6548ec0,http://coldmooon.github.io/2015/08/03/caffe_install/

你可能感兴趣的:(【开发环境】)