Last active
November 6, 2015 01:24
-
-
Save haje01/7edb8b25f4c9a3b9c9d7 to your computer and use it in GitHub Desktop.
Dockerfile for Caffe - original from https://github.com/tleyden/docker/tree/master/caffe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:14.04 | |
ENV PYTHONPATH /opt/caffe/python | |
# Add caffe binaries to path | |
ENV PATH $PATH:/opt/caffe/.build_release/tools | |
# Get dependencies | |
RUN apt-get update && apt-get install -y \ | |
bc \ | |
cmake \ | |
curl \ | |
gcc-4.6 \ | |
g++-4.6 \ | |
gcc-4.6-multilib \ | |
g++-4.6-multilib \ | |
gfortran \ | |
git \ | |
libprotobuf-dev \ | |
libleveldb-dev \ | |
libsnappy-dev \ | |
libopencv-dev \ | |
libboost-all-dev \ | |
libhdf5-serial-dev \ | |
liblmdb-dev \ | |
libjpeg62 \ | |
libfreeimage-dev \ | |
libatlas-base-dev \ | |
pkgconf \ | |
protobuf-compiler \ | |
python-dev \ | |
python-pip \ | |
unzip \ | |
wget | |
# Use gcc 4.6 | |
RUN update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-4.6 30 && \ | |
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-4.6 30 && \ | |
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 30 && \ | |
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 30 | |
# Clone the Caffe repo | |
RUN cd /opt && git clone https://github.com/BVLC/caffe.git | |
# Glog | |
RUN cd /opt && wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz && \ | |
tar zxvf glog-0.3.3.tar.gz && \ | |
cd /opt/glog-0.3.3 && \ | |
./configure && \ | |
make && \ | |
make install | |
# Workaround for error loading libglog: | |
# error while loading shared libraries: libglog.so.0: cannot open shared object file | |
# The system already has /usr/local/lib listed in /etc/ld.so.conf.d/libc.conf, so | |
# running `ldconfig` fixes the problem (which is simpler than using $LD_LIBRARY_PATH) | |
# TODO: looks like this needs to be run _every_ time a new docker instance is run, | |
# so maybe LD_LIBRARY_PATh is a better approach (or add call to ldconfig in ~/.bashrc) | |
RUN ldconfig | |
# Gflags | |
RUN cd /opt && \ | |
wget https://github.com/schuhschuh/gflags/archive/master.zip && \ | |
unzip master.zip && \ | |
cd /opt/gflags-master && \ | |
mkdir build && \ | |
cd /opt/gflags-master/build && \ | |
export CXXFLAGS="-fPIC" && \ | |
cmake .. && \ | |
make VERBOSE=1 && \ | |
make && \ | |
make install | |
# Build Caffe core | |
RUN cd /opt/caffe && \ | |
cp Makefile.config.example Makefile.config && \ | |
echo "CPU_ONLY := 1" >> Makefile.config && \ | |
echo "CXX := /usr/bin/g++-4.6" >> Makefile.config && \ | |
sed -i 's/CXX :=/CXX ?=/' Makefile && \ | |
WITH_PYTHON_LAYER=1 make all | |
# Add ld-so.conf so it can find libcaffe.so | |
RUN echo '/opt/caffe/.build_release/lib/' > /etc/ld.so.conf.d/caffe-ld-so.conf | |
# Run ldconfig again (not sure if needed) | |
RUN ldconfig | |
# Install python deps | |
RUN cd /opt/caffe && \ | |
(pip install -r python/requirements.txt; easy_install numpy; cat python/requirements.txt | xargs -L 1 sudo pip install) && \ | |
easy_install pillow | |
# Numpy include path hack - github.com/BVLC/caffe/wiki/Setting-up-Caffe-on-Ubuntu-14.04 | |
RUN NUMPY_EGG=`ls /usr/local/lib/python2.7/dist-packages | grep -i numpy` && \ | |
ln -s /usr/local/lib/python2.7/dist-packages/$NUMPY_EGG/numpy/core/include/numpy /usr/include/python2.7/numpy | |
# Build Caffe python bindings | |
RUN cd /opt/caffe && make pycaffe | |
# Make + run tests | |
RUN cd /opt/caffe && make test && make runtest | |
# export PYTHONPATH | |
RUN echo "export PYTHONPATH=/opt/caffe/python" > ~/.bash_profile | |
# Patch buggy io.py & classify.py | |
RUN cd /opt/caffe && wget https://gist.githubusercontent.com/haje01/d268b745acd532849722/raw/a96835cb6aac1b70d0c51b9d09a282f5748bed6c/caffe_test.diff && patch -p1 < caffe_test.diff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment