0 引言
今天花了一天,完成了整个caffe的dockerfile编写,其支持python3.6.6,这里主要的注意点是protobuf的版本(在3.6.0之后,只支持c11),还有在制作镜像的时候注意,尽可能少的创建镜像层,并且及时在当前层删除不要的数据,以减少镜像本身大小。
FROM nvidia/cuda:9.0-cudnn7-devel-centos7
COPY ./caffe /caffe # 将官网github项目下下来,并只修改里面的Makefile.config(下面列出)
COPY ./Centos-7.repo /etc/yum.repos.d # 下载163或者阿里云的yum源,以方便加速
ENV LANG=en_US.UTF-8
ARG PYINSTALL=/usr/local/python3
ENV PATH=$PYINSTALL/bin:$PATH
ARG http_proxy=http://xxxxxxxx:xxxx # 记得修改成你的代理,我们机器需要代理才能上网
ARG https_proxy=https://xxxxxxx:xxxx
RUN rm -f /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-CR.repo /etc/yum.repos.d/CentOS-Debuginfo.repo /etc/yum.repos.d/CentOS-Media.repo /etc/yum.repos.d/CentOS-Sources.repo /etc/yum.repos.d/CentOS-Vault.repo /etc/yum.repos.d/CentOS-fasttrack.repo && \
yum clean all && yum makecache && \
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && \
# 安装python numpy
yum -y install make zlib-devel openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel && \
yum -y install libSM libXrender libXext wget && \
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz -O /home/Python-3.6.6.tgz && \
tar -xvf /home/Python-3.6.6.tgz -C /home && \
cd /home/Python-3.6.6 && \
./configure --prefix=$PYINSTALL && \
make -j32 && make install && \
ln -s $PYINSTALL/bin/python3 $PYINSTALL/bin/python && \
/usr/local/python3/bin/pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com numpy && \
/usr/local/python3/bin/pip3 install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com scikit-image && \
# 准备caffe依赖
yum -y install leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel gflags-devel glog-devel lmdb-devel && \
yum -y install gflags-devel glog-devel lmdb-devel && \
yum -y install openblas-devel python36-devel && \
yum -y groupinstall "Development Tools" "Development Libraries" && \
# 编译boost 修复libboost_python3.so找不到的问题
wget https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.gz -O /home/boost_1_67_0.tar.gz && \
tar -xvf /home/boost_1_67_0.tar.gz -C /home && \
cd /home/boost_1_67_0 && ./bootstrap.sh --with-libraries=python --with-toolset=gcc && \
./b2 cflags='-fPIC' cxxflags='-fPIC' --with-python include=/usr/include/python3.6m && \
./b2 install && \
ln -s /usr/local/lib/libboost_python36.so /usr/lib64/libboost_python3.so && \
echo /usr/local/lib >> /etc/ld.so.conf.d/caffe.conf && ldconfig && \
# 安装protobuf
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.5.1/protobuf-cpp-3.5.1.zip -O /home/protobuf-cpp-3.5.1.zip && \
cd /home && unzip protobuf-cpp-3.5.1.zip && \
cd /home/protobuf-3.5.1 && \
./configure && make -j32 && make install && ldconfig && \
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.5.1/protobuf-python-3.5.1.zip -O /home/protobuf-python-3.5.1.zip && \
cd /home && rm -rf protobuf-3.5.1 && \
unzip protobuf-python-3.5.1.zip && \
cd /home/protobuf-3.5.1 && \
cd python && /usr/local/python3/bin/python3 setup.py build && /usr/local/python3/bin/python3 setup.py install && \
# 安装caffe
cd /caffe && \
make -j32 && make pycaffe -j32 && \
# 清空缓存和无用数据
yum clean all &&\
rm -rf /home/*
# docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --runtime=nvidia -tid --name zzc_caffe_demo ImageName /bin/bash
其中caffe中的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 # 支持cudnn
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1
# uncomment to disable IO dependencies and corresponding data layers
USE_OPENCV := 1 # 使用opencv
# 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 9.0,所以删除前面2个,让其从30开始
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 := 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 := /usr/include/openblas
BLAS_LIB := /usr/lib64
# 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的路径
PYTHON_LIBRARIES := boost_python3 python3.6m
PYTHON_INCLUDE := /usr/include/python3.6m \
/usr/local/python3/lib/python3.6/site-packages/numpy/core/include
# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib64
# 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 ?= @
renference:
docker[caffe&&pycaffe]的更多相关文章
-
Docker Caffe部署
Caffe是一个清晰而高效的深度学习框架,纯粹的C++/CUDA架构,支持命令行.Python和MATLAB接口:可以在CPU和GPU直接无缝切换 Caffe的优势 上手快:模型与相应优化都是以文本形 ...
-
基于Anaconda编译caffe+pycaffe+matcaffe in Ubuntu[不用sudo权限]
目录 caffe 编译 环境 github下载caffe源码 依赖 修改源码的编译配置 报错 测试使用 pycaffe caffe matcaffe caffe 编译 环境 Ubuntu16.04 C ...
-
[深度学习] centos7上搭建基于Anaconda3的caffe+pycaffe环境(python3.6)
本文记录从零开始在CentOS7.x系统上搭建Caffe深度学习平台,并配置pycaffe环境.(由于在虚拟机上搭建,所以为CPU_ONLY模式) 1.选择CentOS7 mini版镜像安装虚拟机 镜 ...
-
Ubuntu 16.04 使用docker资料汇总与应用docker安装caffe并使用Classifier(ros kinetic+usb_cam+caffe)
Docker是开源的应用容器引擎.若想简单了解一下,可以参考百度百科词条Docker.好像只支持64位系统. Docker官网:https://www.docker.com/ Docker - 从入门 ...
-
caffe 无GPU 环境搭建
root@k-Lenovo:/home/k# sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-d ...
-
[转]caffe的配置过程
caffe的配置过程 转:http://blog.csdn.net/brightming/article/details/51106629 版权声明:本文为博主原创文章,欢迎转载!转载请写明原文链 ...
-
深度学习框架Caffe —— Deep learning in Practice
因工作交接需要, 要将caffe使用方法及整体结构描述清楚. 鉴于也有同学问过我相关内容, 决定在本文中写个简单的tutorial, 方便大家参考. 本文简单的讲几个事情: Caffe能做什么? 为什 ...
-
Caffe —— Deep learning in Practice
因工作交接须要. 要将caffe用法及总体结构描写叙述清楚. 鉴于也有同学问过我相关内容, 决定在本文中写个简单的tutorial, 方便大家參考. 本文简单的讲几个事情: Caffe能做什么? 为什 ...
-
CAFFE在win10+VS2017下的安装笔记
老版的caffe在BVLC的github上已经找不到,如果要想下载老版caffe可以下载微软的caffe版本:https://github.com/Microsoft/caffe 网上的大多安装caf ...
随机推荐
-
SIMLock锁卡功能解析
一.锁卡背景介绍 锁卡即SIMLock,当手机开机启动或者插入SIM卡时,手机modem侧预置在NV项中的配置信息会与SIM卡中的信息做比对,检测是否匹配.若匹配,则SIM卡可以正常使用.若不匹配,则 ...
-
【夯实PHP基础】PHP发送邮件(PHPMailer)
本文地址 参考地址 分享提纲: 1. 概述 2. 编写代码发送邮件 3. 参考文档 1. 概述 本文是讲利用邮件类库 PHPMailer来发送邮件方法. 我们在做project的时候常常需要邮件的功能 ...
-
Node.js 学习资源
这篇文章编译整理自Stack Overflow的一个如何开始学习Node.js的Wiki帖,这份资源列表在SO上面浏览接近60万次,数千个收藏和顶.特意整理发布到这里,其中添加了部分中文参考资料. 学 ...
-
String与StringBuilder之间区别(转)
当我们在初学使用C#时,常常会不知道该用StringBuilder合适还是用String高效,下面是我在学习当中对StringBuilder和String的区别总结,分享给大家. String类有不可 ...
-
POOL
#ifndef POOL_HHH #define POOL_HHH #include "common.h" /* simple and fast obj pool without ...
-
webkit之滚动条美化
由于公司的产品改用webkit内核,在写公共css的时候,不想使用插件模拟,顺便网上查阅了下css3的滚动条美化. 首先,先上一副示意图. 从网络上盗图的(来源 http://zhangyaochun ...
-
vue的过滤器语发及应用案例
1.使用地方: 双花括号插值处或 组件属性处 例: {{ message | capitalize }} <div v-bind:id="rawId | formatId&quo ...
-
linux c使用socket进行http 通信,并接收任意大小的http响应(四)
终于说到SOCKET 这里了.SOCKET进行http通信的实际就是利用socket将http请求信息发送给http服务器,然后再利用socket接收http响应. 由于本文与之通信的服务器是ip已知 ...
-
linux的一个find命令配合rm删除某天前的文件
语句写法: find 对应目录 -mtime +天数 -name "文件名" -exec rm -rf {} \; 例1: 将/usr/local/backups目录下所有10天前 ...
-
java的struts2项目实现网站首页只显示域名不显示index.do的做法
自己的网站快做完了,发现首页显示的时候总是跳转到http://www.xxxxxx.com/index.do 而我想让http://www.xxxxxx.com/ 这样的方式来访问,不想带有后边的in ...