安装caffe
拉取镜像
nvidia/cuda:9.0-cudnn7-devel-centos7
1,换源
安装https://blog.csdn.net/tuomen5867/article/details/94406903
yum install make 必要安装
更换 yum 源和 epel 源:
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 更换 epel 源
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
# 清理缓存并生成新的缓存
yum clean all
yum makecache
---------------------------------------
更换 pip 源和 conda 源
# Linux 下修改 pip 源:
# 修改 ~/.pip/pip.conf (没有就创建一个),添加如下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
# Linux 下修改 conda 源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
------------------------------------------
2,#####安装 Caffe 需要的依赖库
安装
yum -y install epel-release
yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
yum install gflags-devel glog-devel lmdb-devel
yum install atlas-devel
yum install python-devel
yum -y install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
yum -y install gflags-devel glog-devel lmdb-devel wget unzip
#将与 CUDA 和 CUDNN 相关路径设置成环境变量
# 将下面两行内容添加至文件 ~/.bashrc 最后:
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:/usr/local/cuda-9.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda-9.0/
# 添加成功之后执行:
source ~/.bashrc
3,安装 BLAS(可选
yum install atlas-devel -y
cd /usr/lib64/atlas
ln -sv /usr/lib64/atlas/libsatlas.so.3.10 /usr/lib64/atlas/libcblas.so
ln -sv /usr/lib64/atlas/libsatlas.so.3.10 /usr/lib64/atlas/libatlas.so
报错:
/usr/bin/ld: cannot find -lcblas
Same problem on centos 7.
commands
ln -s /usr/lib64/atlas/libtatlas.so /usr/lib64/libatlas.so
ln -s /usr/lib64/atlas/libsatlas.so /usr/lib64/libcblas.so
You should Install the libatlas-base-dev:
sudo apt-get install libatlas-base-dev
4,下载源码
从 https://github.com/BVLC/caffe.git 进行下载
wget https://github.com/BVLC/caffe/archive/master.zip
安装 Python 依赖
安装pip
yum install python-pip 安装会报错,
升级下pip
pip install --upgrade pip
# 进入 ${CAFFE_HOME}/python/,执行
unzip -d /usr/local/ /usr/local/src/master.zip
/usr/local/caffe-master/python
/usr/local/caffe-master/python/requirements.txt
for req in $(cat /usr/local/caffe-master/python/requirements.txt); do pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
还需要再跑
for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
for req in $(cat requirements.txt); do pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
这个是正确的,可以下载成功
for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
更改 Caffe 的配置文件
# 进入 Caffe 所在目录 CAFFE_HOME
cp Makefile.config.example Makefile.config # 做好备份
vi 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 layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 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 3
# OPENCV_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-9.0
# 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 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
需要注释掉 For CUDA >= 9.0, comment the *_20 and *_21 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_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
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
BLAS_INCLUDE := /usr/include/atlas
BLAS_LIB := /usr/lib64/atlas
# 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_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/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)/anaconda3
#PYTHON_INCLUDE := $(ANACONDA_HOME)/include
$(ANACONDA_HOME)/include/python3.6m
$(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include
# Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python python3.6m
# 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/local/cuda-9.0/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/cuda-9.0/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
# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1
# 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 ?= @
完整的配置文件
/usr/local/src/master.zip
解压后
/usr/local/caffe-master
/usr/local/caffe-master/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 layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 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 3
# OPENCV_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-9.0
# 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 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
#CUDA_ARCH := -gencode arch=compute_20,code=sm_20
# -gencode arch=compute_20,code=sm_21
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
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# 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
BLAS_INCLUDE := /usr/include/atlas
BLAS_LIB := /usr/lib64/atlas
# 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_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/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/local/cuda-9.0/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/cuda-9.0/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
# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1
# 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 ?= @
编译
编译 Caffe
make all
make test
make runtest
4. 测试 Caffe
运行 Caffe
进入Caffe 安装目录,执行./build/tools/caffe,可以根据caffe命令选项使用
2.MNIST 例子
进入Caffe目录,执行如下命令
# 下载数据集:
./data/mnist/get_mnist.sh
# 转换数据集:
./examples/mnist/create_mnist.sh
# 训练例子:
./examples/mnist/train_lenet.sh
5. Caffe 的 Python 接口
执行一下命令即可得到 Caffe 的 Python 接口
# 进入 CAFFE_HOME
make pycaffe
# 在 ~/.bahsrc 添加以下内容,之后执行 source ~/.bashrc
export PATH=/root/caffe/python:$PATH
其他方案
centos7+cuda+cudnn+caffe环境安装
https://blog.csdn.net/u010344264/article/details/86558031
https://www.cnblogs.com/platero/p/3993877.html
操作:
安装 wget unzip
编译pycaffe
报错
make pycaffe时遇到致命错误,找不到Python.h文件
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpppython/caffe/_caffe.cpp:1:52: fatal error: Python.h:
找不到Python.h文件,其实是caffe的Makefile.config中anaconda路径不对,也就是Python路径。
我从这个网页中找到了解决方法:make pycaffe fatal error: ‘Python.h’ file not found
在这篇博文中找到解决办法
因为我没有使用anaconda,所以手动添加路径
export CPLUS_INCLUDE_PATH=/usr/local/src/Python-3.6.4/Include/:$CPLUS_INCLUDE_PATH
然后make pycaffe就可以了。
-----------------------------------------
find Python.h 添加起父目录到变量CPLUS_INCLUDE_PATH
CentOS 7 安装Python3以及pip3
一、添加epel源
yum install epel-release
二、安装Python3.4,装完再升级吧
yum install python34
三、安装pip3
yum install python34-setuptools
easy_install-3.4 pip
之后就可以使用pip3了,如:
pip3 install numpy
-----------------------------
安装setuptools
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python3 setup.py build
python3 setup.py install
设置软链接
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
如软链接设置错误,删除软链接命令
rm -rf /usr/bin/pip3(后面/usr/bin/pip为软链接名称,切记不能加结尾/ 如:/usr/bin/pip3/则表示删除软连接及真实文件)
回到根目录
cd /
输入pip3 -V查看pip版本,安装成功则正确显示版本
问题
Caffe-GPU编译问题:nvcc fatal : Unsupported gpu architecture 'compute_20'
NVCC src/caffe/layers/bnll_layer.cu
nvcc fatal : Unsupported gpu architecture 'compute_20'
Makefile:594: recipe for target '.build_release/cuda/src/caffe/layers/bnll_layer.o' failed
make: *** [.build_release/cuda/src/caffe/layers/bnll_layer.o] Error 1
make: *** Waiting for unfinished jobs....
CUDA9.0所以把下面这两行删除就可以了
-gencode arch=compute_20,code=sm_20
-gencode arch=compute_20,code=sm_21
安装过程简版
完整的操作
1 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2 yum install wget
3 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
4 wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
5 yum clean all
6 yum makecache
7 yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
8 yum install gflags-devel glog-devel lmdb-devel
9 echo $LD_LIBRARY_PATH
10 nvcc -v
11 nvcc -V
12 export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:/usr/local/cuda-9.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
13 echo $LD_LIBRARY_PATH
14 export CUDA_HOME=/usr/local/cuda-9.0/
15 yum install atlas-devel
16 cd /usr/lib64/atlas
17 ln -sv libsatlas.so.3.10 libcblas.so
18 ln -sv libsatlas.so.3.10 libatlas.so
19 cd /usr/local/src/
20 ll
21 wget https://github.com/BVLC/caffe/archive/master.zip
22 ll
23 unzip master.zip
24 yum -y install unzip
25 yum-complete-transaction --cleanup-only
26 unzip master.zip
27 cd caffe-master/
28 ll
29 cd python/
30 ll
31 for req in $(cat requirements.txt); do pip -i https://pypi.tuna.tsinghua.edu.cn/simple install $req; done
32 yum install python-pip
33 for req in $(cat requirements.txt); do pip -i https://pypi.tuna.tsinghua.edu.cn/simple install $req; done
34 for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
35 pip install --upgrade pip
36 for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
37 yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
38 cd /usr/local/src/
39 wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
40 yum install xz
41 xz -d Python-3.6.4.tar.xz
42 tar -xf Python-3.6.4.tar
43 cd Python-3.6.4
44 ./configure prefix=/usr/local/python3
45 make && make install
46 #进入解压后的目录,依次执行下面命令进行手动编译
47 mv /usr/bin/python /usr/bin/python.bak
48 ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
49 python -V
50 vi /usr/bin/yum
51 vi /usr/libexec/urlgrabber-ext-down
52 cd ../caffe-master/python/
53 ll
54 for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
55 for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
56 for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
57 python
58 for req in $(cat requirements.txt); do pip install $req; done
59 whereis python
60 mv /usr/bin/python2.7{,bak}
61 for req in $(cat requirements.txt); do pip install $req; done
62 pip
63 ll
64 cd /usr/local/src/
65 ll
66 wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
67 tar -zxvf setuptools-19.6.tar.gz
68 cd setuptools-19.6
69 python setup.py build
70 python setup.py install
71 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
72 cd -
73 cd /usr/local/src/caffe-master/python/
74 pip3
75 for req in $(cat requirements.txt); do pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
76 history
77 cp Makefile.config.example Makefile.config
78 cd ..
79 ll
80 cp Makefile.config.example Makefile.config
81 vim Makefile.conig
82 vi Makefile.conig
83 vi Makefile.config
84 make all
85 yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
86 mv /usr/bin/python2.7bak /usr/bin/python2.7
87 yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
88 yum install gflags-devel glog-devel lmdb-devel
89 make all
90 make test
91 make runtest
92 history
dockerfile
FROM nvidia/cuda:9.0-cudnn7-devel-centos7
MAINTAINER yon@Dxa.com
ENV LD_LIBRARY_PATH /usr/local/cuda-9.0/lib64:/usr/local/cuda-9.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
ENV CUDA_HOME /usr/local/cuda-9.0/
RUN yum -y install make wget
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
&& wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
&& yum clean all && yum makecache
RUN yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc
RUN wget -O /usr/local/src/Python-3.6.4.tar.xz https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
&& cd /usr/local/src/ && xz -d Python-3.6.4.tar.xz && tar -xf Python-3.6.4.tar
&& cd /usr/local/src/Python-3.6.4 && ./configure prefix=/usr/local/python3 && make && make install
RUN mv /usr/bin/python /usr/bin/python.bak
&& ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
修改pip3 链接
rm -rf /usr/bin/pip*
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
ln -s /usr/bin/pip3 /usr/bin/pip
-------------------------------------------------------------------------------------------
#caffe 依赖
yum -y install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
yum -y install gflags-devel glog-devel lmdb-devel unzip
#BLAS
yum install atlas-devel -y
cd /usr/lib64/atlas
ln -sv /usr/lib64/atlas/libsatlas.so.3.10 /usr/lib64/atlas/libcblas.so
ln -sv /usr/lib64/atlas/libsatlas.so.3.10 /usr/lib64/atlas/libatlas.so
-----------------------------------------
wget -O /usr/local/src/master.zip https://github.com/BVLC/caffe/archive/master.zip
unzip -d /usr/local/ /usr/local/src/master.zip
for req in $(cat /usr/local/caffe-master/python/requirements.txt); do pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
配置文件
/usr/local/caffe-master/Makefile.config
make all
make test
make runtest
完整的dockefile
cat /gputest/caffe/Dockerfile
FROM nvidia/cuda:9.0-cudnn7-devel-centos7
MAINTAINER yon@D
ENV LD_LIBRARY_PATH /usr/local/cuda-9.0/lib64:/usr/local/cuda-9.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
ENV CUDA_HOME /usr/local/cuda-9.0/
RUN yum -y install make wget
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
&& wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
&& yum clean all && yum makecache
RUN yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc
RUN wget -O /usr/local/src/Python-3.6.4.tar.xz https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
&& cd /usr/local/src/ && xz -d Python-3.6.4.tar.xz && tar -xf Python-3.6.4.tar
&& cd /usr/local/src/Python-3.6.4 && ./configure prefix=/usr/local/python3 && make && make install
RUN mv /usr/bin/python /usr/bin/python.bak
&& ln -s /usr/local/python3/bin/python3.6 /usr/bin/python && rm -rf /usr/bin/pip*
&& ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
&& ln -s /usr/bin/pip3 /usr/bin/pip
#caffe 依赖
RUN sed -i 's@/usr/bin/python@/usr/bin/python2@' /usr/bin/yum
&& sed -i 's@/usr/bin/python@/usr/bin/python2@' /usr/libexec/urlgrabber-ext-down
&& yum -y install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel gflags-devel glog-devel lmdb-devel unzip atlas-devel
&& ln -sv /usr/lib64/atlas/libsatlas.so.3.10 /usr/lib64/atlas/libcblas.so
&& ln -sv /usr/lib64/atlas/libsatlas.so.3.10 /usr/lib64/atlas/libatlas.so
RUN wget -O /usr/local/src/master.zip https://github.com/BVLC/caffe/archive/master.zip
&& unzip -d /usr/local/ /usr/local/src/master.zip
#Python 依赖
RUN for req in $(cat /usr/local/caffe-master/python/requirements.txt); do pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
COPY Makefile.config /usr/local/caffe-master/Makefile.config
RUN cd /usr/local/caffe-master/ && make all && make test && make runtest
容器内安装
2 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3 yum install wget
4 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
5 yum clean all
6 yum makecache
7 yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
8 yum install gflags-devel glog-devel lmdb-devel bzip2 unzip
9 ll
10 mv caffe-master.zip /usr/local/src/
11 ll
12 cd /usr/local/src/
13 ll
14 unzip caffe-master.zip
15 ll
16 ln -sv /usr/local/src/caffe-master /usr/local/caffe
17 cd /usr/local/caffe/
18 ll
19 yum install gcc make
20 yum install atlas-devel
21 cd /usr/lib64/atlas
22 ll
23 ln -sv libsatlas.so.3.10 libcblas.so
24 ln -sv libsatlas.so.3.10 libatlas.so
25 cd /usr/local/caffe/
26 ll
27 cp Makefile.config.example Makefile.config
28 vi Makefile.config
29 yum install gcc gcc-c++
30 yum install opencv-devel
31 yum install opencv
32 find / -name "*opencv*"
33 vi Makefile.confi
34 vi Makefile.config
35 make all
36 yum install gflags-devel glog-devel lmdb-devel
37 yum install epel-release
38 yum install gflags-devel glog-devel lmdb-devel
39 make clean
40 make all
41 yum install hdf5-devel
42 make clean
43 make all
44 yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
45 yum install gflags-devel glog-devel lmdb-devel
46 yum install atlas-devel
47 make clean
48 make all
49 yum install atlas-devel
50 find / -name lcblas
51 find / -name "*lcblas*"
52 yum install atlas
53 yum install cblas
54 cd /usr/lib64/atlas
55 ll
56 ln -sv /usr/lib64/atlas/libsatlas.so.3.10 /usr/lib64/atlas/libcblas.so
57 ldconfig
58 ln -s /usr/lib64/atlas/libtatlas.so /usr/lib64/libatlas.so
59 ln -s /usr/lib64/atlas/libsatlas.so /usr/lib64/libcblas.so
60 cd -
61 ll
62 make clean
63 make all
64 make install
65 make test
66 make runtest
67 cd /root/
68 ll
69 ll
70 export PATH=/root/anaconda3/bin:$PATH
71 vi .bashrc
72 cd /
73 ll
74 vi python_service.py
75 echo $PATH
76 history
安装后测试
1.准备数据
cd caffe
sudo ./data/mnist/get_mnist.sh #下载数据集
sudo ./examples/mnist/create_mnist.sh #转换格式
2.训练
sudo ./examples/mnist/train_lenet.sh
nvidia-docker run -d --name ckernel -p 5002:8888 -v /home:/data jupyter_ckernel_v1
c++测试
class Rectangle {
private:
double w;
double h;
public:
Rectangle(double w_, double h_) {
w = w_;
h = h_;
}
double area(void) {
return w * h;
}
double perimiter(void) {
return 2 * (w + h);
}
};
Rectangle r = Rectangle(5, 4);
r.area();
jupyter安装c++
conda install -c conda-forge jupyterlab
conda install -c conda-forge xeus-cling
cpu only 安装
最初的命令:
1 yum -y isntall wget bzip2
2 yum -y install wget bzip2
3 wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
4 wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
5 chmod + x
6 chmod + x Anaconda3-5.1.0-Linux-x86_64.sh
7 chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
8 rm -rf Anaconda3-5.3.1-Linux-x86_64.sh
9 ll
10 ./Anaconda3-5.1.0-Linux-x86_64.sh -h
11 ./Anaconda3-5.1.0-Linux-x86_64.sh -b
12 yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel openblas-devel gflags-devel glog-devel lmdb-devel
13 yum install epel-release
14 yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel openblas-devel gflags-devel glog-devel lmdb-devel
15 yum install git
16 cd
17 ll
18 git clone https://github.com/bvlc/caffe.git
19 ll
20 cd caffe/
21 ll
22 yum install gcc-c++
23 ll
24 cp Makefile.config.example Makefile.config
25 vi Makefile.config
26 vi Makefile.config
27 make
28 yum install make
29 make all
30 yum install atlas-devel
31 make clean
32 make all
33 vi Makefile.config
34 make clean
35 make all
36 make test
37 make runtest
38 history
## 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 layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 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 3
# OPENCV_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 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 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_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
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := open
# 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_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/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/anaconda3
PYTHON_INCLUDE := $ANACONDA_HOME/include
$ANACONDA_HOME/include/python3.6m
$ANACONDA_HOME/lib/python3.6/site-packages/numpy/core/include
# Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python3 python3.6m
# 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
LIBRARY_DIRS := $PYTHON_LIB /usr/local/lib /usr/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
# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1
# 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 ?= @