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      [email protected]
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      [email protected]
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  '[email protected]/usr/bin/[email protected]/usr/bin/[email protected]'  /usr/bin/yum          &&    sed  -i  '[email protected]/usr/bin/[email protected]/usr/bin/[email protected]'  /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 ?= @

原文地址:https://www.cnblogs.com/g2thend/p/11699888.html

时间: 2024-10-31 03:43:07

caffe 安装的相关文章

windows环境Caffe安装配置步骤(无GPU)及mnist训练

在硕士第二年,义无反顾地投身到了深度学习的浪潮中.从之前的惯性导航转到这个方向,一切从头开始,在此,仅以此文记录自己的打怪之路. 最初的想法是动手熟悉Caffe,考虑到直接上手Ubuntu会有些难度,所以首先在windows环境下打个基础.有个插曲,台式机由于某些原因只能保持在32位系统,编译caffe.cpp时才发现系统不兼容,然后才换到64位的笔记本上进行操作. 前期准备:1.VS 2013   2. windows版的Caffe(https://github.com/BVLC/caffe/

caffe安装2

洋洋洒洒一大篇,就没截图了,这几天一直在折腾这个东西,实在没办法,不想用Linux但是,为了Caffe,只能如此了,安装这些东西,遇到很多问题,每个问题都要折磨很久,大概第一次就是这样的.想想,之后应用,应该还会遇到很多问题吧,不过没办法了,骑虎难下!!这里有个建议是,如果将来要做大数据集,最好事先给Linux留多点空间,比如Imagenet,估计500G都不为过.另外,请阅读完,至少一个部分再进行动手操作,避免多余的工作,写作能力有限,尽请见谅.        这篇安装指南,适合零基础,新手操

Windows下caffe安装详解(仅CPU)

本文大多转载自 http://blog.csdn.net/guoyk1990/article/details/52909864,加入部分自己实战心得. 1.环境:windows 7\VS2013 2.caffe-windows准备 (1)下载官方caffe-windows并解压,将 .\windows\CommonSettings.props.example备份,并改名为CommonSettings.props.如图4所示: 图 4:修改后的CommonSettings.props文件 附带说明

[转]Caffe安装过程记录(CentOS,无独立显卡,无GPU)

Caffe安装过程记录(CentOS,无独立显卡,无GPU) 原文地址:http://www.aiuxian.com/article/p-2410195.html 参考资料: http://www.tuicool.com/articles/uiuA3e Caffe 安装配置(CentOS + 无GPU) http://blog.sina.com.cn/s/blog_990865340102vewt.html caffe 安装配置(CentOS 6.5 + 无GPU) http://www.cnb

caffe安装笔记

caffe安装笔记: 环境及安装前检查 硬件: T630 CPU32核 64G内存4G硬盘 显卡: [email protected]:~# lspci |grep -i nvidia 02:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20Xm] (rev a1) 软件: Ubuntu14.04 server64bit版本:ubuntu-14.04.5-server-amd64.iso Python 2.7.12 [email p

ubuntu14.04+cuda8.0(GTX1080)+caffe安装

1. ubuntu14.04安装 分区:usr/local 300G boot 200M / 根目录 300G 交换空间 20G (内存16G) 其余都是/home 重装之后,下载NVIDIA-Linux-x86_64-367.27.run,下载地址为:http://www.geforce.cn/drivers/results/104314 将其与cuda_8.0.27_linux.run(下载地址为:https://developer.nvidia.com/cuda-toolkit 不过需要注

ubuntu 14.04 cuda7.5 caffe安装

最近新接触深度学习就从入门开始吧:新安装cuda,caffe安装流程很简单,网上到处都有 1:安装cuda前要禁用nouveau驱动 按Ctrl+Alt+F1进入命令提示符,新建一个黑名单文件 # sudo vi /etc/modprobe.d/blacklist-nouveau.conf 输入 blacklist nouveau options nouveau modset=0 保存退出(:wq) 然后执行 # sudo update-initramfs -u 执行 lspci | grep

Ubuntu16.04 Caffe 安装步骤记录(超详尽)

"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Ubuntu16.04 Caffe 安装步骤记录(超详尽) - yhao的博客 - 博客频道 - CSDN.NET yhao的博客 最怕庸碌无为,还安慰自己平凡可贵 目录视图 摘要视图 订阅 [活动]2017 CSDN博客专栏评选 &nbsp [5月书讯]流畅的Pyt

Ubuntu16.04+matlab2014a+anaconda2+OpenCV3.1+caffe安装

本次安装caffe是在新的笔记本上,感觉与之前在台式机上的安装还是有一定的区别.加之是在新的ubuntu16.04系统上安装的,可参考教程较少.而且其中添加了不少库,修改的一些错误,难免会有遗漏.如果发现本文未提及错误,欢迎一起讨论学习.另外,看到有的人说安装了半个多月,多次重装,希望有问题还是先把问题查清楚,不要盲目重装系统;其次,安装的时候最好记录自己安装的过程和内容,避免遗漏和重复,出问题了也可以与别人的教程相对比. 首先介绍安装条件和软件准备: - 联想笔记本电脑Y700-15ISK,双

Caffe安装笔记二:Caffe安装过程

下面开始正题,caffe的安装过程.因为出问题很多,所以实际上我是尝试了python2和python3两种python的接口.下面一并放出来. 1. 安装build-essential sudo apt-get install build-essential 这个是一些基本的库,具体包括哪些,安装前确认时会显示,印象中有gcc等等. 2. boost安装 caffe官网给出的是sudo apt-get install --no-install-recommends libboost-all-de