caffe 安装
安装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 ?= @
caffe 安装的更多相关文章
- 71 mac boook pro 无 gpu 下caffe 安装
71 mac boook pro 无 gpu 下caffe 安装 1.首先安装homebrew工具,相当于Mac下的yum或apt ruby -e "$(curl -fsSL https:/ ...
- [Caffe]史上最全的caffe安装过程
Linux下的GPU版Caffe安装方法 系统环境:Ubuntu 14.04LTS + NV TitanX 1.1 (可选)显卡驱动的安装(有风险) 如果需要重装,需要先卸载已有版本 sudo apt ...
- 深度学习框架-caffe安装-环境[Mac OSX 10.12]
深度学习框架-caffe安装 [Mac OSX 10.12] [参考资源] 1.英文原文:(使用GPU) [http://hoondy.com/2015/04/03/how-to-install-ca ...
- 深度学习框架-caffe安装-Mac OSX 10.12
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ".PingFang SC"; color: #454545 } p.p2 ...
- windows环境Caffe安装配置步骤(无GPU)及mnist训练
在硕士第二年,义无反顾地投身到了深度学习的浪潮中.从之前的惯性导航转到这个方向,一切从头开始,在此,仅以此文记录自己的打怪之路. 最初的想法是动手熟悉Caffe,考虑到直接上手Ubuntu会有些难度, ...
- caffe+CPU︱虚拟机+Ubuntu16.04+CPU+caffe安装笔记
由于本机是window10系统,所以想尝试caffe就在自己电脑上整了一个虚拟机(详情可见:win10系统搭建虚拟机:VMware Workstation Player 12环境+Ubuntu Kyl ...
- caffe安装教程(Ubuntu14+GPU+pycaffe+anaconda2)
caffe安装教程 本文所使用的底层环境配置:cuda8.cudnn6.OpenCV2.4.5.anaconda2(Python2.7).如使用其他版本的环境,如cuda,可安装自己的版本,但须在相应 ...
- win10下caffe安装与mnist测试实验注意点
caffe安装 安装内容:win10教育版+anaconda2+python(无gpu版本) 安装教程:主要依照三年一梦教程:https://www.cnblogs.com/king-lps/p/65 ...
- windows下caffe安装配置、matlab接口
一.CommonSettings.props caffe下载后解压.源代码文件夹caffe-master,到该文件夹下的windows文件夹下,将CommonSettings.props.exampl ...
- caffe安装编译问题-ImportError: No module named skimage.io
问题描述 >>> import caffe Traceback (most recent call last): File , in <module> File , in ...
随机推荐
- python 一周总结
从7月27前就开始了Djangoj框架的学习到今天一个项目实战已经过了一半了, django给我的感觉就像一个成熟的mov 首先是是数据模型层,Django已经成熟的加入了很多的数据模型供我们所使用 ...
- CF1187E Tree Painting【换根dp】
题目传送门 题意 一棵$N$个节点的树,初始时所有的节点都是白色,第一次可以选择任意一个把它涂成黑色.接下来,只能把与黑色节点原来相连的白色节点涂成黑色(涂成黑色的点视为被删去,与其它节点不相连).每 ...
- 引用dll出现了黄色感叹号
今天引用一个dll的时候出现了一个小感叹号,重新生成也无济于事,如下图 原因是,被引用的项目使用的是.NET2.0版本,而当前项目使用的是.NET3.5版本,所以出现了错误 解决办法把当前项目和引用项 ...
- DataGridView中EnditCommit()调用之后,单元格的内容被全选了,每次输入都要鼠标点击定位到最后才能继续输入
因为某些需求,DataGridView在输入一次内容,就要调用ECommitEdit(DataGridViewDataErrorContexts.Commit)来将内容提交,但是这样做之后,控件就会当 ...
- break和continue关键字的使用
一,break和continue关键字的使用 public class BreakContinueTest { public static void main(String args[]) { for ...
- C#静态调用带有SoapHeader验证的WebServices
转自:http://blog.csdn.net/u012995964/article/details/54562111 本文记录带有SoapHeader验证的WebServices服务创建.部署及C# ...
- 微软宣布加入 OpenJDK,打不过就改变 Java 未来!
近日,微软的 Bruno Borges 在 OpenJDK 邮件列表中发布了一条消息,内容包含接下来发生的事情以及微软如何开始将其团队整合到 OpenJDK 社区. 在邮件中,Bruno Borges ...
- Python 描述符 (descriptor)
1.什么是描述符? 描述符是Python新式类的关键点之一,它为对象属性提供强大的API,你可以认为描述符是表示对象属性的一个代理.当需要属性时,可根据你遇到的情况,通过描述符进行访问他(摘自Pyth ...
- SQL注入的一些技巧分享
先上一道简单的ctf注入题: 一道利用order by进行注入的ctf题 很不错的一道利用order by的注入题,之前不知道order by除了爆字段还有这种操作. 原题地址:http://chal ...
- 手把手带你了解sass
sass的使用 减少重复的工作 1.变量的声明: 是以$开头给变量命名; $height-color: #F30 2.变量的使用范围: 变量可以在多个地方存在,不一定限制在代码块中.但是如果定义在了代 ...