Skip to content

Instantly share code, notes, and snippets.

@christian-lanius
Last active November 30, 2019 05:49
Show Gist options
  • Save christian-lanius/fd6846d44eeee63719858c2291c559ba to your computer and use it in GitHub Desktop.
Save christian-lanius/fd6846d44eeee63719858c2291c559ba to your computer and use it in GitHub Desktop.
# ==================================================================
# module list
# ------------------------------------------------------------------
# python 3.5 (apt)
# tensorflow latest (pip)
# opencv latest (git)
# caffe latest (git)
# openpose latest (git)
# pyopenpose latest (git)
# custom_dependencies latest (apt)
# ==================================================================
FROM nvidia/cuda:9.0-cudnn7-devel
RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
PIP_INSTALL="pip --no-cache-dir install --upgrade" && \
GIT_CLONE="git clone --depth 10" && \
rm -rf /var/lib/apt/lists/* \
/etc/apt/sources.list.d/cuda.list \
/etc/apt/sources.list.d/nvidia-ml.list && \
apt-get update && \
# ==================================================================
# tools
# ------------------------------------------------------------------
DEBIAN_FRONTEND=noninteractive $APT_INSTALL \
build-essential \
ca-certificates \
cmake \
wget \
git \
vim \
&& \
# ==================================================================
# python
# ------------------------------------------------------------------
DEBIAN_FRONTEND=noninteractive $APT_INSTALL \
python3-pip \
python3-dev \
&& \
ln -s /usr/bin/python3 /usr/local/bin/python && \
pip3 --no-cache-dir install --upgrade pip && \
$PIP_INSTALL \
setuptools \
&& \
$PIP_INSTALL \
numpy \
scipy \
pandas \
scikit-learn \
matplotlib \
Cython \
&& \
# ==================================================================
# boost
# ------------------------------------------------------------------
wget -O ~/boost.tar.gz https://sourceforge.net/projects/boost/files/boost/1.66.0/boost_1_66_0.tar.gz && \
tar -zxf ~/boost.tar.gz -C ~ && \
cd ~/boost_* && \
./bootstrap.sh --with-python=python3.5 && \
./b2 install --prefix=/usr/local && \
# ==================================================================
# tensorflow
# ------------------------------------------------------------------
$PIP_INSTALL \
tensorflow-gpu \
tensorboard \
&& \
# ==================================================================
# opencv
# ------------------------------------------------------------------
DEBIAN_FRONTEND=noninteractive $APT_INSTALL \
libatlas-base-dev \
libgflags-dev \
libgoogle-glog-dev \
libhdf5-serial-dev \
libleveldb-dev \
liblmdb-dev \
libprotobuf-dev \
libsnappy-dev \
protobuf-compiler \
libgtk2.0-dev \
pkg-config \
&& \
$GIT_CLONE https://github.com/opencv/opencv ~/opencv && \
mkdir -p ~/opencv/build && cd ~/opencv/build && \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_IPP=OFF \
-D WITH_CUDA=OFF \
-D WITH_OPENCL=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
.. && \
make -j"$(nproc)" install && \
# ==================================================================
# caffe
# ------------------------------------------------------------------
$GIT_CLONE https://github.com/NVIDIA/nccl ~/nccl && \
cd ~/nccl && \
make -j"$(nproc)" install && \
$GIT_CLONE https://github.com/BVLC/caffe ~/caffe && \
cp ~/caffe/Makefile.config.example ~/caffe/Makefile.config && \
sed -i 's/# USE_CUDNN/USE_CUDNN/g' ~/caffe/Makefile.config && \
sed -i 's@#define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported. Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."@//#define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported. Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."@g' /usr/local/cuda/include/common_functions.h && \
sed -i 's/# PYTHON_LIBRARIES/PYTHON_LIBRARIES/g' ~/caffe/Makefile.config && \
sed -i 's/# WITH_PYTHON_LAYER/WITH_PYTHON_LAYER/g' ~/caffe/Makefile.config && \
sed -i 's/# OPENCV_VERSION/OPENCV_VERSION/g' ~/caffe/Makefile.config && \
sed -i 's/# USE_NCCL/USE_NCCL/g' ~/caffe/Makefile.config && \
sed -i 's/-gencode arch=compute_20,code=sm_20//g' ~/caffe/Makefile.config && \
sed -i 's/-gencode arch=compute_20,code=sm_21//g' ~/caffe/Makefile.config && \
sed -i 's/2\.7/3\.5/g' ~/caffe/Makefile.config && \
sed -i 's/\/usr\/lib\/python/\/usr\/local\/lib\/python/g' ~/caffe/Makefile.config && \
sed -i 's/\/usr\/local\/include/\/usr\/local\/include \/usr\/include\/hdf5\/serial/g' ~/caffe/Makefile.config && \
sed -i 's/hdf5/hdf5_serial/g' ~/caffe/Makefile && \
cd ~/caffe && \
make -j"$(nproc)" -Wno-deprecated-gpu-targets distribute && \
# fix ValueError caused by python-dateutil 1.x
sed -i 's/,<2//g' ~/caffe/python/requirements.txt && \
$PIP_INSTALL \
-r ~/caffe/python/requirements.txt && \
cd ~/caffe/distribute/bin && \
for file in *.bin; do mv "$file" "${file%%.bin}"; done && \
cd ~/caffe/distribute && \
cp -r bin include lib proto /usr/local/ && \
cp -r python/caffe /usr/local/lib/python3.5/dist-packages/
# ==================================================================
# openpose
# ------------------------------------------------------------------
RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
PIP_INSTALL="pip --no-cache-dir install --upgrade" && \
GIT_CLONE="git clone --depth 10" && \
$GIT_CLONE https://github.com/CMU-Perceptual-Computing-Lab/openpose.git /software/openpose && \
sed -i 's/set(Caffe_known_gpu_archs "20 21(20) 30 35 50 52 60 61")/set(Caffe_known_gpu_archs "30 35 50 52 60 61 70")/g' /software/openpose/cmake/Cuda.cmake && \
mkdir -p /software/openpose/build && cd /software/openpose/build && \
cmake -DBUILD_CAFFE=OFF \
-DCaffe_INCLUDE_DIRS=/usr/local/include \
-DCaffe_LIBS=/usr/local/lib/libcaffe.so \
-DOpenCV_INCLUDE_DIRS=/usr/local/include \
-DOpenCV_LIBS_DIR=/usr/local/lib \
-DDOWNLOAD_HAND_MODEL=ON \
-DDOWNLOAD_FACE_MODEL=ON \
-DDOWNLOAD_COCO_MODEL=ON .. && \
make -j"$(nproc)" && \
make install && \
# ==================================================================
# pyopenpose
# ------------------------------------------------------------------
$GIT_CLONE https://github.com/christian-lanius/PyOpenPose.git /software/pyopenpose && \
export OPENPOSE_ROOT=/software/openpose && \
cd /software/pyopenpose && \
mkdir build && \
cd build && \
cmake .. && \
make && \
export PYTHONPATH=$PYTHONPATH:/software/pyopenpose/build/PyOpenPoseLib && \
# ==================================================================
# custom_dependencies
# ------------------------------------------------------------------
DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive $APT_INSTALL \
python3-tk \
&& \
$PIP_INSTALL tflearn \
&& \
# ==================================================================
# config & cleanup
# ------------------------------------------------------------------
ldconfig && \
apt-get clean && \
apt-get autoremove && \
rm -rf /var/lib/apt/lists/* /tmp/* ~/*
EXPOSE 6006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment