Lab223服务器caffe装配过程

  1. 安装ubuntu 16.04 LTS x64
    使用工具 大白菜装机版 或者 UltroISO 或者 Uiversal-USB-install- 最新版 制作U盘启动盘,官方下载64位版本: ubuntu-16.04-desktop-amd64.iso,千万注意在装机过程中不要插网线,笔者因为给服务器插上网线很多次没有进入boot界面,但装win10没有出现这个问题,当时感觉很困恼…
  2. 更新源
cd /etc/apt/
sudo cp sources.list sources.list.bak
sudo gedit sources.list

在sources.list 文件头部添加如下源

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

然后更新源和安装的包:

sudo apt-get update
sudo apt-get upgrade
  1. 安装NVIDIA 显卡驱动
    采用ppa安装方式,没选择最新的nvidia-370,选择nvidia-367
    Ctrl+Alt+F1进入tty命令控制台,停止lightdm,然后开始安装驱动(用tty简称各种类型的终端设备)
sudo services lightdm stopsudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get updates
sudo apt-get install nvidia-367
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
sudo reboot
  1. 安装CUDA 8.0
    到官网下载cuda_8.0.44_linux.run,复制到根目录下。
sudo sh cuda_8.0.44_linux.run --tmpdir=/tmp/

遇到问题:incomplete installation,然后执行

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
sudo sh cuda_8.0.44_linux.run -silent -driver

注:此时安装过程中提示是否要安装NVIDIA驱动时选择no。其他选择yes或默认即可。

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?
(y)es/(n)o/(q)uit: n

安装完毕后声明环境变量:

sudo gedit ~/.bashrc

在.bashrc尾部添加如下内容:

export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

测试下安装是否成功:
测试1:

cd NVIDIA_CUDA-8.0_Samples/
nvidia-smi

输出:

lab223@lab223:~$ nvidia-smi
Fri Oct  5 08:41:47 2018
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.130                Driver Version: 384.130                   |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K40c          Off  | 00000000:04:00.0 Off |                    0 |
| 23%   40C    P8    20W / 235W |      1MiB / 11439MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX TIT...  Off  | 00000000:83:00.0  On |                  N/A |
| 22%   33C    P8    16W / 250W |    149MiB / 12205MiB |      0%      Default |
+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    1      1264      G   /usr/lib/xorg/Xorg                           106MiB |
|    1      2320      G   compiz                                        40MiB |
+-----------------------------------------------------------------------------+

测试2:

cd 1_Utilities/deviceQuery
make
........
./deviceQuery

输出:

lab223@lab223:~/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery$ make
make: Nothing to be done for 'all'.
lab223@lab223:~/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery$ ./deviceQuery
./deviceQuery Starting...CUDA Device Query (Runtime API) version (CUDART static linking)Detected 2 CUDA Capable device(s)Device 0: "GeForce GTX TITAN X"CUDA Driver Version / Runtime Version          9.0 / 8.0CUDA Capability Major/Minor version number:    5.2Total amount of global memory:                 12206 MBytes (12798787584 bytes)(24) Multiprocessors, (128) CUDA Cores/MP:     3072 CUDA CoresGPU Max Clock rate:                            1076 MHz (1.08 GHz)Memory Clock rate:                             3505 MhzMemory Bus Width:                              384-bitL2 Cache Size:                                 3145728 bytesMaximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layersMaximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layersTotal amount of constant memory:               65536 bytesTotal amount of shared memory per block:       49152 bytesTotal number of registers available per block: 65536Warp size:                                     32Maximum number of threads per multiprocessor:  2048Maximum number of threads per block:           1024Max dimension size of a thread block (x,y,z): (1024, 1024, 64)Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)Maximum memory pitch:                          2147483647 bytesTexture alignment:                             512 bytesConcurrent copy and kernel execution:          Yes with 2 copy engine(s)Run time limit on kernels:                     YesIntegrated GPU sharing Host Memory:            NoSupport host page-locked memory mapping:       YesAlignment requirement for Surfaces:            YesDevice has ECC support:                        DisabledDevice supports Unified Addressing (UVA):      YesDevice PCI Domain ID / Bus ID / location ID:   0 / 131 / 0Compute Mode:< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >Device 1: "Tesla K40c"CUDA Driver Version / Runtime Version          9.0 / 8.0CUDA Capability Major/Minor version number:    3.5Total amount of global memory:                 11440 MBytes (11995578368 bytes)(15) Multiprocessors, (192) CUDA Cores/MP:     2880 CUDA CoresGPU Max Clock rate:                            745 MHz (0.75 GHz)Memory Clock rate:                             3004 MhzMemory Bus Width:                              384-bitL2 Cache Size:                                 1572864 bytesMaximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layersMaximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layersTotal amount of constant memory:               65536 bytesTotal amount of shared memory per block:       49152 bytesTotal number of registers available per block: 65536Warp size:                                     32Maximum number of threads per multiprocessor:  2048Maximum number of threads per block:           1024Max dimension size of a thread block (x,y,z): (1024, 1024, 64)Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)Maximum memory pitch:                          2147483647 bytesTexture alignment:                             512 bytesConcurrent copy and kernel execution:          Yes with 2 copy engine(s)Run time limit on kernels:                     NoIntegrated GPU sharing Host Memory:            NoSupport host page-locked memory mapping:       YesAlignment requirement for Surfaces:            YesDevice has ECC support:                        EnabledDevice supports Unified Addressing (UVA):      YesDevice PCI Domain ID / Bus ID / location ID:   0 / 4 / 0Compute Mode:< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
> Peer access from GeForce GTX TITAN X (GPU0) -> Tesla K40c (GPU1) : No
> Peer access from Tesla K40c (GPU1) -> GeForce GTX TITAN X (GPU0) : NodeviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.0, CUDA Runtime Version = 8.0, NumDevs = 2, Device0 = GeForce GTX TITAN X, Device1 = Tesla K40c
Result = PASS
lab223@lab223:~/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery$

测试3:

cd ../../5_Simulations/nbody/
make
.........
./nbody -benchmark -numbodies=256000 -device=0

输出:

lab223@lab223:~/NVIDIA_CUDA-8.0_Samples/5_Simulations/nbody$ ./nbody -benchmark -numbodies=256000 -device=0
Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance.-fullscreen       (run n-body simulation in fullscreen mode)-fp64             (use double precision floating point values for simulation)-hostmem          (stores simulation data in host memory)-benchmark        (run benchmark to measure performance) -numbodies=<N>    (number of bodies (>= 1) to run in simulation) -device=<d>       (where d=0,1,2.... for the CUDA device to use)-numdevices=<i>   (where i=(number of CUDA devices > 0) to use for simulation)-compare          (compares simulation results running once on the default GPU and once on the CPU)-cpu              (run n-body simulation on the CPU)-tipsy=<file.bin> (load a tipsy model file for simulation)NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.> Windowed mode
> Simulation data stored in video memory
> Single precision floating point simulation
> 1 Devices used for simulation
gpuDeviceInit() CUDA Device [0]: "GeForce GTX TITAN X
> Compute 5.2 CUDA device: [GeForce GTX TITAN X]
number of bodies = 256000
256000 bodies, total time for 10 iterations: 3103.036 ms
= 211.200 billion interactions per second
= 4223.992 single-precision GFLOP/s at 20 flops per interaction
lab223@lab223:~/NVIDIA_CUDA-8.0_Samples/5_Simulations/nbody$ 
  1. 安装OpenCV 3.1.0
    从官网下载zip源代码,解压到根目录下。
    安装依赖:
sudo apt-get -y remove ffmpeg x264 libx264-dev
sudo apt-get -y install libopencv-dev
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get -y install python-dev python-numpy
sudo apt-get -y install libtbb-dev
sudo apt-get -y install libqt4-dev libgtk2.0-dev
sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
sudo apt-get -y install x264 v4l-utils ffmpeg
sudo apt-get -y install libgtk2.0-devcd opencv-3.1.0
mkdir build
cd build/
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j4
sudo make install

遇到的错误:Errors

error: ‘NppiGraphcutState’ has not been declared
error: ‘NppiGraphcutState’ does not name a type
...

解决方法:(由于CUDA版本高于8.0,所以需要做如下修改。在源文件中找到“graphcuts.cpp”),此源文件自行百度在Linux中的位置。
将:

#include "precomp.hpp"
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)

改为:

#include "precomp.hpp"
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)  || (CUDART_VERSION >= 8000)

because graphcuts is not supported directly with CUDA8 anymore.
安装成功后配置环境:

sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

测试OpenCV安装是否成功:

mkdir DisplayImage
cd DisplayImage
gedit DisplayImage.cpp

添加代码:

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;  int main(int argc, char** argv)
{  if(argc!= 2)  {  printf("usage:DisplayImage.out <Image_Path>\n");  return -1;  }  Mat image;  image= imread(argv[1], 1);  if(!image.data)  {  printf("Noimage data\n");  return -1;  }  namedWindow("DisplayImage",CV_WINDOW_AUTOSIZE);  imshow("DisplayImage",image);  waitKey(0);  return 0;
}

创建CMake文件:

gedit CMakeLists.txt

添加内容:

cmake_minimum_required(VERSION 2.8)
project(DisplayImage)
find_package(OpenCV REQUIRED)
add_executable(DisplayImage DisplayImage.cpp)
target_link_libraries(DisplayImage ${OpenCV_LIBS})

编译:

cmake .
make

执行:

./DisplayImage lena.jpg

结果:

lab223@lab223:~/opencv-3.1.0/build/DisplayImage$ ./DisplayImage lean.jpg
Noimage data
  1. 安装cudnn 5.1
    从官网下载cudnn-8.0-linux-x64-v5.1.tgz for CUDA 8.0. 解压到当前目录:(账户名:WG Wang
    有可能下载的文件不是tgz文件,可以自行改文件后缀然后解压)
tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz

解压后的文件如下:

cuda/include/cudnn.h
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.5
cuda/lib64/libcudnn.so.5.1.5
cuda/lib64/libcudnn_static.a

然后执行:

sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
  1. 安装MATLAB 2014a
    需要注意的是Ubuntu16.04 LTS的gcc版本为5.4,而Matlab2014a支持的是gcc4.7。(此条没怎么注意)

用Crack文件中的install替换matlab2014安装目录下/java/jar/下的install文件,然后执行install程序
(在超级用户权限下执行此程序)

cd matlab
sudo ./install

注意:选择“不联网安装”;当出现密钥时,随意输入20个数字12345-67890-12345-67890即可;需要激活时选择不要联网激活,用Crack目录下的“license_405329_R2014a.lic”文件激活。
安装完成之后,将Crack/Linux目录下的libmwservices.so文件拷贝到/usr/local/MATLAB/R2014a/bin/glnxa64。

cd ..
cd Crack/Linux/
sudo cp libmwservices.so /usr/local/MATLAB/R2014a/bin/glnxa64

打开Matlab并激活:

cd /usr/local/MATLAB/R2014a/bin
sudo ./matlab # sudo不可缺少,否则选择激活文件后报错
  1. Python的安装

选用Ubuntu16.04默认的安装和配置,python版本2.7.12.
很多版本都推荐使用anaconda,因为anaconda里面自带很多库文件,但此文档并没有使用此方法,仅用于caffe的安装运行,此后安装anaconda遇到问题再说。

  1. BLAS安装与配置
    BLAS(基础线性代数集合)是一个应用程序接口的标准。caffe官网上推荐了三种实现:ATLAS, MKL, OpenBLAS。其中ATLAS可以直接通过命令行安装。MKL是微软开发的商业工具包,面向科研和学生免费开放。申请学生版的Parallel Studio BLAS(基础线性代数集合)是一个应用程序接口的标准。caffe官网上推荐了三种实现:ATLAS, MKL, OpenBLAS。其中ATLAS可以直接通过命令行安装。MKL是微软开发的商业工具包,面向科研和学生免费开放。申请学生版的Parallel Studio BLAS(基础线性代数集合)是一个应用程序接口的标准。caffe官网上推荐了三种实现:ATLAS, MKL, OpenBLAS。其中ATLAS可以直接通过命令行安装。MKL是微软开发的商业工具包,面向科研和学生免费开放。申请学生版的Parallel Studio BLAS(基础线性代数集合)是一个应用程序接口的标准。caffe官网上推荐了三种实现:ATLAS, MKL, OpenBLAS。其中ATLAS可以直接通过命令行安装。MKL是微软开发的商业工具包,面向科研和学生免费开放。申请学生版的Parallel Studio
    XE Cluster Edition,下载parallel_studio_xe_2017.tgz。注意接收邮件中的序列号(S4ZD-T4P7R6VF)。
tar zxvf parallel_studio_xe_2017.tgz   #解压下载文件chmod 777 parallel_studio_xe_2017 -R   #获取文件权限
cd parallel_studio_xe_2017/sudo ./install_GUI.sh

安装完成之后,进行相关文件的链接:

sudo gedit /etc/ld.so.conf.d/intel_mkl.conf

添加库文件:

/opt/intel/lib/intel64
/opt/intel/mkl/lib/intel64

编译链接使lib文件生效:

sudo ldconfig

如果选择安装ATLAS,在终端输入sudo apt-get install libatlas-base-dev即可。
(笔者使用的是MKL安装,安装极慢,有兴趣的话可以试一下使用ATLAS安装)

  1. Caffe的安装与配置
    Caffe是由BVLC开发的一个深度学习框架,主要由贾扬清在UC Berkeley攻读PhD期间完成。参考官网上的教程以及Github上针对Ubuntu15.04和16.04的教程。从官方下载caffe源包caffe-master。
    安装库文件:
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

安装依赖:

sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler   libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install --no-install-recommends libboost-all-dev

Python接口依赖:

sudo apt-get install  the python-dev
sudo apt-get install -y python-pip
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy # (Python 2.7 development files)
sudo apt-get install -y python3-dev
sudo apt-get install -y python3-numpy python3-scipy # (Python 3.5 development files)

在python文件夹内,使用root执行依赖项的检查与安装:

sudo su
cd caffe-master/python
for req in $(cat requirements.txt); do pip install $req; done

Makefile.config:

cd ~/caffe-master
cp Makefile.config.example Makefile.config

配置如下:

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!# cuDNN acceleration switch (uncomment to build with cuDNN).USE_CUDNN := 1# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1# uncomment to disable IO dependencies and corresponding data layersUSE_OPENCV := 1
# USE_LEVELDB := 0
# USE_LMDB := 0# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#    You should not set this flag if you will be reading LMDBs with any
#    possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1# Uncomment if you're using OpenCV 3OPENCV_VERSION := 3# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 lines for compatibility.
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# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := mkl
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.MATLAB_DIR := /usr/local/MATLAB/R2014a
# MATLAB_DIR := /Applications/MATLAB_R2012b.app# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \/usr/local/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \# $(ANACONDA_HOME)/include/python2.7 \# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib# Uncomment to support layers written in Python (will link against Python libs)WITH_PYTHON_LAYER := 1# Whatever else you find you need goes here.
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 /usr/local/share/OpenCV/3rdparty/lib/# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0# enable pretty build (comment to see full commands)
Q ?= @

在Makefile中配置:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs

hdf5的配置:官方说这对于Ubuntu 16.04是必须的。libhdf5的版本号需要根据实际来修改下。(可使用locate libhdf5 来查看对应版本号)

find . -type f -exec sed -i -e 's^"hdf5.h"^"hdf5/serial/hdf5.h"^g' -e 's^"hdf5_hl.h"^"hdf5/serial/hdf5_hl.h"^g' '{}' \;
cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.10.1.0 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so

编译:

cd ~/caffe-master
make clean
make all -j4
make test -j4
make runtest -j4
make pycaffe -j4
make matcaffe -j4

出现如下结果:

编译接口matcaffe时,有如下警告:

Warning: You are using gcc version '5.4.0'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '5.4.0-6ubuntu1~16.04.2)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
MEX completed successfully.

若OpenCV安装不正确则会在caffe编译过程中遇到如下错误:

/usr/bin/ld: cannot find -lopencv_imgcodecs
collect2: error: ld returned 1 exit status
Makefile:566: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

MNIST测试:

sh data/mnist/get_mnist.sh  #数据预处理
sh examples/mnist/create_mnist.sh #重建lmdb文件。Caffe支持多种数据格式: Image(.jpg, .png等),leveldb,lmdb,HDF5. 生成mnist-train-lmdb 和 mnist-train-lmdb文件夹,这里包含了lmdb格式的数据集
sh examples/mnist/train_lenet.sh #训练mnist

输出:

I1019 21:48:30.078994 20063 caffe.cpp:217] Using GPUs 0
I1019 21:48:30.092034 20063 caffe.cpp:222] GPU 0: GeForce GTX TITAN X
...
....
.....
I1019 21:48:49.415398 20063 solver.cpp:317] Iteration 10000, loss = 0.00242468
I1019 21:48:49.415410 20063 solver.cpp:337] Iteration 10000, Testing net (#0)
I1019 21:48:49.479605 20063 solver.cpp:404] Test net output #0: accuracy = 0.9914
I1019 21:48:49.479625 20063 solver.cpp:404] Test net output #1: loss = 0.0284448 (* 1 = 0.0284448 loss)
I1019 21:48:49.479629 20063 solver.cpp:322] Optimization Done.
I1019 21:48:49.479632 20063 caffe.cpp:254] Optimization Done.

(这一步的 make matcaffe 我没有做,运行失败,但前几步均运行成功,暂时发现其实没有matlab这个接口其实运行example model 也是可以的,包括下面的caffe下matlab接口demo测试其实也并没有做)
11. Caffe下Matlab接口Demo测试
在使用Matlab运行caffe库时,即运行文件”caffe-master/matlab/demo/classification_demo.m”。遇到的错误信息如下:

Invalid MEX-file 'caffe-master/matlab/+caffe/private/caffe_.mexa64': libcudart.so.8.0: cannot open shared object file: No such file or directory

错误原因是由于Matlab找不到caffe.mexa64所依赖的所有库文件的路径,此时可以使用ldd命令来查看caffe.mexa64内库文件的地址:
//1. 在Ubuntu系统的命令终端

ldd *caffe_.mexa64

结果输出的是库文件对应的地址,与下文相对的缺失的库文件的地址可在此找到:

libcudart.so.8.0 => /usr/local/cuda-8.0/lib64/libcudart.so.8.0
libcublas.so.8.0 => /usr/local/cuda-8.0/lib64/libcublas.so.8.0
libcurand.so.8.0 => /usr/local/cuda-8.0/lib64/libcurand.so.8.0
libcudnn.so.5 => /usr/local/cuda-8.0/lib64/libcudnn.so.5

//2. 在Matlab命令窗口输入

!ldd *caffe_.mexa64

结果在Matlab窗口的输出信息中发现:

libcudart.so.8.0 => not found
libcublas.so.8.0 => not found
libcurand.so.8.0 => not found
libcudnn.so.5 => not found

解决方法:通过如下命令将默认路径链接到真实路径下:

sudo ln -s /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/MATLAB/R2014a/sys/os/glnxa64/libcudart.so.8.0
sudo ln -s /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/local/MATLAB/R2014a/sys/os/glnxa64/libcublas.so.8.0
sudo ln -s /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/local/MATLAB/R2014a/sys/os/glnxa64/libcurand.so.8.0
sudo ln -s /usr/local/cuda-8.0/lib64/libcudnn.so.5 /usr/local/MATLAB/R2014a/sys/os/glnxa64/libcudnn.so.5

重新启动Matlab使之生效。
另外,运行此例需要下载CaffeNet模型(Please download CaffeNet from Model Zoo before you run this demo.)https://github.com/BVLC/caffe/wiki/Model-Zoo

https://blog.csdn.net/jzrita/article/details/72887677
http://www.cnblogs.com/xuanxufeng/p/6150593.html

Ubuntu16.04安装以及在 TitanX 下搭建 caffe框架(cuda8.0 + cudnn5.1)相关推荐

  1. VS2013+Windows+CPU下搭建caffe框架并利用mnist数据集实验

    <李凭箜篌引>--李贺 吴丝蜀桐张高秋,空山临云颓不流: 江娥啼竹素女愁,李凭中国弹箜篌: 昆山玉碎凤凰叫,芙蓉泣露香兰笑: 十二门前融冷光,二十三丝动紫皇: 女娲炼石补天处,石破天惊逗秋 ...

  2. Ubuntu16.04安装NVIDIA显卡(RTX20系列)驱动+CUDA10.0+cudnn+Pytorch1.1.0

    Ubuntu16.04,GPU: Geforce RTX 2070-Super(本博客是显卡驱动和cuda分开安装的教程). 1. Ubuntu16.04安装NVIDIA显卡驱动 1. 下载显卡驱动. ...

  3. ubuntu16.04安装cuda11.3、cudnn8.2.1、tensorrt8.0.3.4全过程

    安装前呢先说明几点,因为之前不熟悉linux 的安装方式,所以看了一下有很多种安装方式,其中包含源码编译.dpkg.apt等,这里的源码方式大家都懂通过Makefile或者cmake进行编译,然后进行 ...

  4. Ubuntu16.04 - 安装RabbitVCS,linux下的TortoiseSVN!!!

    RabbitVCS 官网:http://rabbitvcs.org/ 1,添加PPA源.在shell里面执行下面命令: sudo add-apt-repository ppa:rabbitvcs/pp ...

  5. Win10下将Ubuntu16.04安装在移动固态硬盘上的若干问题

    Win10下将Ubuntu16.04安装在移动固态硬盘上的若干问题 一.下载Ubuntu16.04系统镜像: 二.制作U盘启动盘 : 三.移动硬盘分区 : 四.安装Ubuntu系统: 1. 启动选项 ...

  6. 【转】ubuntu16.04安装配置tftp服务

    转自:ubuntu16.04安装配置tftp服务_carspiriter的博客-CSDN博客_ubuntu安装tftp 首先声明:tftp是client客户端,tftpd是server服务器端,d应该 ...

  7. ubuntu16.04 安装cuda9.0+cudnn7.0.5+tensorflow+nvidia-docker配置GPU服务

    [摘要] docker很好用,但是在GPU服务器上使用docker却比较复杂,需要一些技巧,下面将介绍一下在ubuntu16.04环境下的GPU-docker环境搭建过程. 第一步: 删除之前的nvi ...

  8. SDN入门第一篇——Ubuntu16.04安装mininet-wifi

    SDN入门第一篇--Ubuntu16.04安装mininet-wifi 最近因为项目需要,需要使用mininet搭建SDN仿真平台,mininet-wifi除了包含基本的mininet功能之外还包括引 ...

  9. ubuntu16.04安装opencv3.4.1教程

    最近opencv3.4.1发布了,想换个新的试试鲜,于是把配置的过程通过博文的方式记录下来,方便查阅.  本教程原为3.3.0,但经过博主亲测,3.4.0.3.4.1皆适用 1.去官网下载opencv ...

  10. ubuntu16.04 安装CAJViewer 以及 安装wine /deepin-wine 图标异常的解决

    ubuntu16.04 安装CAJViewer 以及 安装wine /deepin-wine 图标异常的解决 通过deepin-wine 安装 cajviewer 之前装过deepin-wine 所以 ...

最新文章

  1. “HTTP 500 - 内部服务器错误”解决办法
  2. python 操作 excel
  3. 关系 base_weather 不存在_国培教育-2020江苏公务员考试:反对关系真的好用吗?...
  4. 软考路:2021年系统架构设计师之流水账
  5. arrays合并两个数组_九章算法 | 字节跳动面试题:合并k个排序数组
  6. 分析单点登录(流程图与数据安全)
  7. 联想危险!74 岁的创始人柳传志站了出来
  8. component_春天@Component
  9. 我对hibernate的对象的3种状态的理解
  10. Redis RU330课程 Redis Security 第3周学习笔记
  11. 知群产品经理必修TOP班 学习笔记:电梯演讲和商业画布
  12. 「NFT 之王」无聊猿与品牌的跨界营销!
  13. 基于风光储能和需求响应的微电网日前经济调度(Python代码实现)【0】
  14. Load and Display an Image - 加载并显示图像
  15. python改变图像颜色_通过python改变图片特定区域的颜色详解
  16. jquery slideToggle() 效果
  17. 关键项目遇见瓶颈,你会如何应对?
  18. 小说《小城恋情》第三十三章
  19. 【SeMask】Semantically Masked Transformers for Semantic Segmentation
  20. 16.引言篇——自定义过滤器及标签

热门文章

  1. 【前端工程化】搭建vue-cli + cesium项目的脚手架及常见问题
  2. 对注册表项“HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run”的访问被拒绝。
  3. ScrollView嵌套Tablaout与ViewPager联动(标签)(ScrollView与ViewPager冲突)
  4. java基础—java由来
  5. SS00011.elasticsearch——|HadoopElasticSearch集中式日志分析系统.v11|——|Elasticsearch.v11|
  6. 《疯狂原始人》温馨而搞笑片段截图
  7. windows启用Guest用户
  8. 房贷又降,不买!还能降
  9. java list移除所有元素_Java - List集合中如何删除多个元素? remove( )方法 ?
  10. Unity 游戏实例开发集合 之 FlappyBird (像素鸟) 休闲小游戏快速实现