├── Dockerfile ├── Dockerfile.gpu ├── LICENSE └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | # Dockerfile with tensorflow gpu support on python3, opencv3.3 2 | FROM tensorflow/tensorflow:1.8.0-py3 3 | MAINTAINER Fergal Cotter 4 | 5 | # The code below is all based off the repos made by https://github.com/janza/ 6 | # He makes great dockerfiles for opencv, I just used a different base as I need 7 | # tensorflow on a gpu. 8 | 9 | RUN apt-get update 10 | 11 | # Core linux dependencies. 12 | RUN apt-get install -y \ 13 | build-essential \ 14 | cmake \ 15 | git \ 16 | wget \ 17 | unzip \ 18 | yasm \ 19 | pkg-config \ 20 | libswscale-dev \ 21 | libtbb2 \ 22 | libtbb-dev \ 23 | libjpeg-dev \ 24 | libpng-dev \ 25 | libtiff-dev \ 26 | libjasper-dev \ 27 | libavformat-dev \ 28 | libhdf5-dev \ 29 | libpq-dev 30 | 31 | # Python dependencies 32 | RUN pip3 --no-cache-dir install \ 33 | numpy \ 34 | hdf5storage \ 35 | h5py \ 36 | scipy \ 37 | py3nvml 38 | 39 | WORKDIR / 40 | ENV OPENCV_VERSION="3.4.1" 41 | RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip \ 42 | && unzip ${OPENCV_VERSION}.zip \ 43 | && mkdir /opencv-${OPENCV_VERSION}/cmake_binary \ 44 | && cd /opencv-${OPENCV_VERSION}/cmake_binary \ 45 | && cmake -DBUILD_TIFF=ON \ 46 | -DBUILD_opencv_java=OFF \ 47 | -DWITH_CUDA=OFF \ 48 | -DENABLE_AVX=ON \ 49 | -DWITH_OPENGL=ON \ 50 | -DWITH_OPENCL=ON \ 51 | -DWITH_IPP=ON \ 52 | -DWITH_TBB=ON \ 53 | -DWITH_EIGEN=ON \ 54 | -DWITH_V4L=ON \ 55 | -DBUILD_TESTS=OFF \ 56 | -DBUILD_PERF_TESTS=OFF \ 57 | -DCMAKE_BUILD_TYPE=RELEASE \ 58 | -DCMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \ 59 | -DPYTHON_EXECUTABLE=$(which python3) \ 60 | -DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ 61 | -DPYTHON_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. \ 62 | && make install \ 63 | && rm /${OPENCV_VERSION}.zip \ 64 | && rm -r /opencv-${OPENCV_VERSION} 65 | -------------------------------------------------------------------------------- /Dockerfile.gpu: -------------------------------------------------------------------------------- 1 | ## Dockerfile to build opencv from sources with CUDA support 2 | ## Based on Josip Janzic file and Thomas Herbin's work 3 | 4 | # FROM nvidia/cuda:9.0-devel 5 | FROM nvidia/cuda:9.0-cudnn7-runtime-ubuntu16.04 6 | MAINTAINER Fergal Cotter 7 | 8 | ########################### 9 | ### TENSORFLOW INSTALL ### 10 | ########################### 11 | 12 | ARG https_proxy 13 | ARG http_proxy 14 | 15 | RUN apt-get update && \ 16 | apt-get install -y \ 17 | build-essential \ 18 | cmake \ 19 | git \ 20 | wget \ 21 | unzip \ 22 | yasm \ 23 | pkg-config \ 24 | curl 25 | 26 | RUN apt-get install -y \ 27 | libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev \ 28 | libjasper-dev libavformat-dev libpq-dev libxine2-dev libglew-dev \ 29 | libtiff5-dev zlib1g-dev libjpeg-dev libpng12-dev libjasper-dev \ 30 | libavcodec-dev libavformat-dev libavutil-dev libpostproc-dev \ 31 | libswscale-dev libeigen3-dev libtbb-dev libgtk2.0-dev 32 | # libcudnn7=7.1.4.18-1+cuda9.0 33 | 34 | RUN apt-get install -y \ 35 | python3-dev \ 36 | python3-numpy \ 37 | python3-pip 38 | 39 | ## Cleanup 40 | RUN rm -rf /var/lib/apt/lists/* 41 | 42 | # Python dependencies 43 | RUN pip3 --no-cache-dir install \ 44 | numpy \ 45 | hdf5storage \ 46 | h5py \ 47 | scipy \ 48 | py3nvml 49 | 50 | # Install tensorflow 51 | RUN pip3 --no-cache-dir install tensorflow-gpu==1.8.0 52 | 53 | # Set the library path to use cuda and cupti 54 | ENV LD_LIBRARY_PATH /usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/lib64:$LD_LIBRARY_PATH 55 | 56 | ######################## 57 | ### OPENCV INSTALL ### 58 | ######################## 59 | 60 | ARG OPENCV_VERSION=3.4.1 61 | # ARG OPENCV_INSTALL_PATH=/usr/local 62 | 63 | ## Create install directory 64 | ## Force success as the only reason for a fail is if it exist 65 | 66 | # RUN mkdir -p $OPENCV_INSTALL_PATH; exit 0 67 | 68 | WORKDIR / 69 | 70 | ## Single command to reduce image size 71 | ## Build opencv 72 | RUN wget https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip \ 73 | && unzip $OPENCV_VERSION.zip \ 74 | && mkdir /opencv-$OPENCV_VERSION/cmake_binary \ 75 | && cd /opencv-$OPENCV_VERSION/cmake_binary \ 76 | && cmake -DBUILD_TIFF=ON \ 77 | -DBUILD_opencv_java=OFF \ 78 | -DBUILD_SHARED_LIBS=OFF \ 79 | -DWITH_CUDA=ON \ 80 | # -DENABLE_FAST_MATH=1 \ 81 | # -DCUDA_FAST_MATH=1 \ 82 | -DWITH_CUBLAS=1 \ 83 | -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-9.0 \ 84 | ## 85 | ## Should compile for most card 86 | ## 3.5 binary code for devices with compute capability 3.5 and 3.7, 87 | ## 5.0 binary code for devices with compute capability 5.0 and 5.2, 88 | ## 6.0 binary code for devices with compute capability 6.0 and 6.1, 89 | -DCUDA_ARCH_BIN='3.0 3.5 5.0 6.0 6.2' \ 90 | -DCUDA_ARCH_PTX="" \ 91 | ## 92 | ## AVX in dispatch because not all machines have it 93 | -DCPU_DISPATCH=AVX,AVX2 \ 94 | -DENABLE_PRECOMPILED_HEADERS=OFF \ 95 | -DWITH_OPENGL=OFF \ 96 | -DWITH_OPENCL=OFF \ 97 | -DWITH_QT=OFF \ 98 | -DWITH_IPP=ON \ 99 | -DWITH_TBB=ON \ 100 | -DFORCE_VTK=ON \ 101 | -DWITH_EIGEN=ON \ 102 | -DWITH_V4L=ON \ 103 | -DWITH_XINE=ON \ 104 | -DWITH_GDAL=ON \ 105 | -DWITH_1394=OFF \ 106 | -DWITH_FFMPEG=OFF \ 107 | -DBUILD_PROTOBUF=OFF \ 108 | -DBUILD_TESTS=OFF \ 109 | -DBUILD_PERF_TESTS=OFF \ 110 | -DCMAKE_BUILD_TYPE=RELEASE \ 111 | # -DCMAKE_INSTALL_PREFIX=$OPENCV_INSTALL_PATH \ 112 | .. \ 113 | ## 114 | ## Add variable to enable make to use all cores 115 | && export NUMPROC=$(nproc --all) \ 116 | && make -j$NUMPROC install \ 117 | ## Remove following lines if you need to move openCv 118 | && rm /$OPENCV_VERSION.zip \ 119 | && rm -r /opencv-$OPENCV_VERSION 120 | 121 | ## Compress the openCV files so you can extract them from the docker easily 122 | # RUN tar cvzf opencv-$OPENCV_VERSION.tar.gz --directory=$OPENCV_INSTALL_PATH . 123 | WORKDIR /home 124 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Josip Janžić 4 | Copyright (c) 2017 Fergal Cotter 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-tensorflow-opencv 2 | [![Docker Automated buil](https://img.shields.io/docker/automated/fbcotter/docker-tensorflow-opencv.svg)]() 3 | Automated Build for Tensorflow Docker Containter with OpenCV 3.4.1 4 | 5 | If you just want to use opencv with python, I suggest looking at the repo by 6 | [janza](https://github.com/janza/docker-python3-opencv). I have based my 7 | Dockerfile off his, just using a different base to have tensorflow working with 8 | GPU support. 9 | 10 | To access GPUs for tensorflow in the docker container, you need NVIDIA-Docker 11 | installed. Use the `docker-tensorflow-opencv:gpu` tag for the gpu enabled 12 | version. For CPU only (significantly smaller image size), use the 13 | `docker-tensorflow-opencv:latest` tag. 14 | 15 | --------------------------------------------------------------------------------