Skip to content

Instantly share code, notes, and snippets.

@naviocean
Last active October 16, 2018 10:09
Show Gist options
  • Save naviocean/48422ffa643902be902bcfd4257983cb to your computer and use it in GitHub Desktop.
Save naviocean/48422ffa643902be902bcfd4257983cb to your computer and use it in GitHub Desktop.
Caffe cuda9 relu6
#https://github.com/RuiminChen/Caffe-MobileNetV2-ReLU6
FROM nvidia/cuda:9.0-devel-ubuntu16.04
MAINTAINER NaviOcean <navi.ocean@outlook.com>
#install Cuda & Cudnn
ENV CUDNN_VERSION 7.2.1.38
LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}"
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils \
libcudnn7=$CUDNN_VERSION-1+cuda9.0 \
libcudnn7-dev=$CUDNN_VERSION-1+cuda9.0 && \
apt-mark hold libcudnn7 && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
wget \
libatlas-base-dev \
libboost-all-dev \
libgflags-dev \
libgoogle-glog-dev \
libhdf5-serial-dev \
libleveldb-dev \
liblmdb-dev \
libopencv-dev \
libprotobuf-dev \
libsnappy-dev \
protobuf-compiler \
python-dev \
python-numpy \
python-pip \
python-setuptools \
python-scipy && \
rm -rf /var/lib/apt/lists/*
ENV CAFFE_ROOT=/opt/caffe
WORKDIR $CAFFE_ROOT
# FIXME: use ARG instead of ENV once DockerHub supports this
# https://github.com/docker/hub-feedback/issues/460
ENV CLONE_TAG=1.0
# upgrade pip
RUN pip install --upgrade pip
RUN hash -r
# Download caffe
RUN git clone -b ${CLONE_TAG} --depth 1 https://github.com/BVLC/caffe.git .
# Download Caffe-MobileNetV2-ReLU6
RUN git clone https://github.com/RuiminChen/Caffe-MobileNetV2-ReLU6
RUN cp Caffe-MobileNetV2-ReLU6/*.c* ./src/caffe/layers/
RUN cp Caffe-MobileNetV2-ReLU6/*.hpp ./include/caffe/layers/
# Edit Caffe.proto
RUN sed -i -e 's/optional WindowDataParameter window_data_param = 129;/optional WindowDataParameter window_data_param = 129;\r\n optional ReLU6Parameter relu6_param = 100000;/g' ./src/caffe/proto/caffe.proto
RUN echo "\nmessage ReLU6Parameter {" >> ./src/caffe/proto/caffe.proto
RUN echo " optional float negative_slope = 1 [default = 0];" >> ./src/caffe/proto/caffe.proto
RUN echo "}" >> ./src/caffe/proto/caffe.proto
# Copy to Makefile.config
RUN cp Makefile.config.example Makefile.config
# Edit Makefile.config
RUN echo "PYTHON_INCLUDE := /usr/include/python2.7 /usr/lib/python2.7/dist-packages/numpy/core/include" >> Makefile.config && \
echo "WITH_PYTHON_LAYER := 1" >> Makefile.config && \
echo "INCLUDE_DIRS := \$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial" >> Makefile.config && \
echo "LIBRARY_DIRS := \$(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial" >> Makefile.config
RUN sed -i -e 's/# USE_CUDNN := 1/ USE_CUDNN := 1/g' Makefile.config
RUN sed -i -e 's/-gencode arch=compute_20,code=sm_20/#-gencode arch=compute_20,code=sm_20/g' Makefile.config
RUN sed -i -e 's/-gencode arch=compute_20,code=sm_21/#-gencode arch=compute_20,code=sm_21/g' Makefile.config
# Edit Makefile
RUN sed -i -e 's/NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)/NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)/g' Makefile
RUN cat Makefile.config
# Install Caffe python requirements
RUN cd python && for req in $(cat requirements.txt) pydot; do pip install $req; done
RUN pwd
# Complie Caffe
RUN make all -j"$(nproc)"
RUN make test
RUN make pycaffe
ENV PYCAFFE_ROOT $CAFFE_ROOT/python
ENV PYTHONPATH $PYCAFFE_ROOT:$PYTHONPATH
ENV PATH $CAFFE_ROOT/build/tools:$PYCAFFE_ROOT:$PATH
RUN echo "$CAFFE_ROOT/build/lib" >> /etc/ld.so.conf.d/caffe.conf && ldconfig
WORKDIR /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment