Commit c1472c4f authored by Cresson Remi's avatar Cresson Remi

Merge branch 'develop' of gitlab-ssh.irstea.fr:remi.cresson/otbtf into develop

parents e64deb97 5a0bb5f4
# OTBTF
# ![OTBTF](doc/images/logo.png) OTBTF
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
## Orfeo ToolBox meets TensorFlow
This remote module of the [Orfeo ToolBox](https://www.orfeo-toolbox.org) provides a generic, multi purpose deep learning framework, targeting remote sensing images processing.
It contains a set of new process objects that internally invoke [Tensorflow](https://www.tensorflow.org/), and a bunch of user-oriented applications to perform deep learning with real-world remote sensing images.
Applications can be used to build OTB pipelines from Python or C++ APIs.
*Main highlights*
### Highlights
- Sampling,
- Training, supporting save/restore/import operations (a model can be trained from scratch or fine-tuned),
- Serving models with support of OTB streaming mechanism. Meaning (1) not limited by images sizes, (2) can be used as a "lego" in any OTB pipeline and preserve streaming, (3) MPI support available (use multiple processing unit to generate one single output image)
*Portfolio*
### Portfolio
Below are some screen captures of deep learning applications performed at large scale with OTBTF.
- Image to image translation (Spot-7 image --> Wikimedia Map using CGAN)
......@@ -31,11 +35,15 @@ For now you have two options: either use the existing **docker image**, or build
Use the latest image from dockerhub:
```
docker pull mdl4eo/otbtf1.6
docker run -u otbuser -v $(pwd):/home/otbuser mdl4eo/otbtf1.6 otbcli_PatchesExtraction -help
docker pull mdl4eo/otbtf1.7
docker run -u otbuser -v $(pwd):/home/otbuser mdl4eo/otbtf1.7 otbcli_PatchesExtraction -help
```
Please note that for now, TensorFlow and OTB are built with the minimal optimization flags, no CUDA/OpenCL enabled, no AVX and such for CPU. **Contributions are welcome: add more Dockerfiles, e.g. with OpenCL or CUDA support, CPU optimisations, etc.**
For now, there is two docker images available.
- **mdl4eo/otbtf1.7:cpu** : Ubuntu Xenial, Python3, Orfeo ToolBox 7.0 and TensorFlow 1.14 with no optimization flags
- **mdl4eo/otbtf1.7:gpu** : Ubuntu Xenial, Python3, Orfeo ToolBox 7.0 and TensorFlow 1.14 with CUDA/CUDNN support (built with compute capabilities 6.1, 5.2, 3.5). **Suited for NVIDIA GPUs**.
The dockerfiles corresponding to the images available on dockerhub are provided in the `tools/dockerfiles/` path of this repository.
You can find more details on the **GPU docker image** and some **docker tips and tricks** on [this blog](https://mdl4eo.irstea.fr/2019/10/15/otbtf-docker-image-with-gpu/)
## Build from sources
......
......@@ -185,7 +185,7 @@ TensorflowSampler<TInputImage, TVectorData>
// If not, reject this sample
hasBeenSampled = false;
}
// Check if it contains no-data values
// Check if the sampled patch contains a no-data value
if (m_RejectPatchesWithNodata && hasBeenSampled)
{
IndexType outIndex;
......@@ -201,7 +201,6 @@ TensorflowSampler<TInputImage, TVectorData>
if (pix[band] == m_NoDataValues[i])
hasBeenSampled = false;
}
}
} // Next input
if (hasBeenSampled)
......
FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
MAINTAINER Remi Cresson <remi.cresson[at]irstea[dot]fr>
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
sudo \
ca-certificates \
curl \
make \
cmake \
g++ \
gcc \
git \
libtool \
swig \
xvfb \
wget \
autoconf \
automake \
pkg-config \
zip \
zlib1g-dev \
unzip \
&& rm -rf /var/lib/apt/lists/*
# ----------------------------------------------------------------------------
# OTB and TensorFlow dependencies
# ----------------------------------------------------------------------------
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
freeglut3-dev \
libboost-date-time-dev \
libboost-filesystem-dev \
libboost-graph-dev \
libboost-program-options-dev \
libboost-system-dev \
libboost-thread-dev \
libcurl4-gnutls-dev \
libexpat1-dev \
libfftw3-dev \
libgdal-dev \
libgeotiff-dev \
libglew-dev \
libglfw3-dev \
libgsl-dev \
libinsighttoolkit4-dev \
libkml-dev \
libmuparser-dev \
libmuparserx-dev \
libopencv-core-dev \
libopencv-ml-dev \
libopenthreads-dev \
libossim-dev \
libpng-dev \
libqt5opengl5-dev \
libqwt-qt5-dev \
libsvm-dev \
libtinyxml-dev \
qtbase5-dev \
qttools5-dev \
default-jdk \
python3-pip \
python3.6-dev \
python3.6-gdal \
python3-setuptools \
libxmu-dev \
libxi-dev \
qttools5-dev-tools \
bison \
software-properties-common \
dirmngr \
apt-transport-https \
lsb-release \
gdal-bin \
&& rm -rf /var/lib/apt/lists/*
# ----------------------------------------------------------------------------
# Python packages
# ----------------------------------------------------------------------------
RUN ln -s /usr/bin/python3 /usr/bin/python \
&& python3 -m pip install --upgrade pip \
&& python3 -m pip install pip six numpy wheel mock keras future
# ----------------------------------------------------------------------------
# Build TensorFlow
# ----------------------------------------------------------------------------
RUN export TF_ROOT=/work/tf \
&& mkdir -p ${TF_ROOT}/bazel \
&& cd ${TF_ROOT}/bazel \
&& wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel-0.24.1-installer-linux-x86_64.sh \
&& chmod +x bazel-0.24.1-installer-linux-x86_64.sh \
&& ./bazel-0.24.1-installer-linux-x86_64.sh
RUN export TF_ROOT=/work/tf \
&& export PATH="$PATH:$HOME/bin" \
&& cd $TF_ROOT \
&& git clone https://github.com/tensorflow/tensorflow.git \
&& cd tensorflow \
&& git checkout r1.14 \
&& export PYTHON_BIN_PATH=$(which python) \
&& export PYTHON_LIB_PATH="$($PYTHON_BIN_PATH -c 'import site; print(site.getsitepackages()[0])')" \
&& export PYTHONPATH=/usr/lib/ \
&& export PYTHON_ARG=/usr/lib/ \
&& export CUDA_TOOLKIT_PATH=/usr/local/cuda-10.1/ \
&& export CUDNN_INSTALL_PATH=/usr/ \
&& export TF_NEED_GCP=0 \
&& export TF_NEED_CUDA=1 \
&& export TF_CUDA_VERSION="$($CUDA_TOOLKIT_PATH/bin/nvcc --version | sed -n 's/^.*release \(.*\),.*/\1/p')" \
&& export TF_CUDA_COMPUTE_CAPABILITIES=6.1,5.2,3.5 \
&& export TF_NEED_HDFS=0 \
&& export TF_NEED_OPENCL=0 \
&& export TF_NEED_JEMALLOC=1 \
&& export TF_ENABLE_XLA=0 \
&& export TF_NEED_VERBS=0 \
&& export TF_CUDA_CLANG=0 \
&& export TF_CUDNN_VERSION="$(sed -n 's/^#define CUDNN_MAJOR\s*\(.*\).*/\1/p' $CUDNN_INSTALL_PATH/include/cudnn.h)" \
&& export TF_NEED_MKL=0 \
&& export TF_DOWNLOAD_MKL=0 \
&& export TF_NEED_AWS=0 \
&& export TF_NEED_MPI=0 \
&& export TF_NEED_GDR=0 \
&& export TF_NEED_S3=0 \
&& export TF_NEED_OPENCL_SYCL=0 \
&& export TF_SET_ANDROID_WORKSPACE=0 \
&& export TF_NEED_COMPUTECPP=0 \
&& export GCC_HOST_COMPILER_PATH=$(which gcc) \
&& export CC_OPT_FLAGS="-march=native" \
&& export TF_NEED_KAFKA=0 \
&& export TF_NEED_TENSORRT=0 \
&& export TF_NCCL_VERSION=2.4 \
&& export GCC_HOST_COMPILER_PATH=$(which gcc) \
&& export CC_OPT_FLAGS="-march=native" \
&& ./configure \
&& bazel build //tensorflow:libtensorflow_framework.so //tensorflow:libtensorflow_cc.so //tensorflow/tools/pip_package:build_pip_package
RUN export TF_ROOT=/work/tf \
&& cd $TF_ROOT/tensorflow \
&& bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg \
&& pip3 install $(find /tmp/tensorflow_pkg/ -type f -iname "tensorflow*.whl") \
&& ./tensorflow/contrib/makefile/build_all_linux.sh \
&& mkdir -p /work/tf/installdir/lib \
&& mkdir -p /work/tf/installdir/include \
&& cp bazel-bin/tensorflow/libtensorflow_cc.so /work/tf/installdir/lib \
&& cp bazel-bin/tensorflow/libtensorflow_framework.so /work/tf/installdir/lib \
&& cp tensorflow/contrib/makefile/gen/protobuf/lib/libprotobuf.a /work/tf/installdir/lib \
&& cp tensorflow/contrib/makefile/downloads/nsync/builds/default.linux.c++11/*.a /work/tf/installdir/lib \
&& cp -r bazel-genfiles/* /work/tf/installdir/include/ \
&& cp -r tensorflow/cc /work/tf/installdir/include/tensorflow/ \
&& cp -r tensorflow/core /work/tf/installdir/include/tensorflow/ \
&& cp -r third_party /work/tf/installdir/include/ \
&& cp -r tensorflow/contrib/makefile/gen/protobuf/include/* /work/tf/installdir/include/ \
&& cp -r tensorflow/contrib/makefile/downloads/eigen/Eigen /work/tf/installdir/include/ \
&& cp -r tensorflow/contrib/makefile/downloads/eigen/unsupported /work/tf/installdir/include/ \
&& cp -r tensorflow/contrib/makefile/downloads/eigen/signature_of_eigen3_matrix_library /work/tf/installdir/include/ \
&& cd ${TF_ROOT}/tensorflow/tensorflow/contrib/makefile/downloads/absl \
&& find absl/ -name '*.h' -exec cp --parents \{\} /work/tf/installdir/include/ \; \
&& find absl/ -name '*.inc' -exec cp --parents \{\} /work/tf/installdir/include/ \; \
&& find /work/tf/installdir/ -name "*.cc" -type f -delete \
&& echo "Create symlinks for tensorflow libs" \
&& ln -s /work/tf/installdir/lib/libtensorflow_cc.so /work/tf/installdir/lib/libtensorflow_cc.so.1 \
&& ln -s /work/tf/installdir/lib/libtensorflow_framework.so /work/tf/installdir/lib/libtensorflow_framework.so.1
# ----------------------------------------------------------------------------
# Build OTB: Stage 1 (clone)
# ----------------------------------------------------------------------------
RUN mkdir -p /work/otb \
&& cd /work/otb \
&& git clone https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git otb \
&& cd otb \
&& git checkout release-7.0
# ----------------------------------------------------------------------------
# Build OTB: Stage 2 (superbuild)
# ----------------------------------------------------------------------------
RUN mkdir -p /work/otb/build \
&& cd /work/otb/build \
&& cmake /work/otb/otb/SuperBuild \
-DUSE_SYSTEM_BOOST=ON \
-DUSE_SYSTEM_CURL=ON \
-DUSE_SYSTEM_EXPAT=ON \
-DUSE_SYSTEM_FFTW=ON \
-DUSE_SYSTEM_FREETYPE=ON \
-DUSE_SYSTEM_GDAL=ON \
-DUSE_SYSTEM_GEOS=ON \
-DUSE_SYSTEM_GEOTIFF=ON \
-DUSE_SYSTEM_GLEW=ON \
-DUSE_SYSTEM_GLFW=ON \
-DUSE_SYSTEM_GLUT=ON \
-DUSE_SYSTEM_GSL=ON \
-DUSE_SYSTEM_ITK=ON \
-DUSE_SYSTEM_LIBKML=ON \
-DUSE_SYSTEM_LIBSVM=ON \
-DUSE_SYSTEM_MUPARSER=ON \
-DUSE_SYSTEM_MUPARSERX=ON \
-DUSE_SYSTEM_OPENCV=ON \
-DUSE_SYSTEM_OPENTHREADS=ON \
-DUSE_SYSTEM_OSSIM=ON \
-DUSE_SYSTEM_PNG=ON \
-DUSE_SYSTEM_QT5=ON \
-DUSE_SYSTEM_QWT=ON \
-DUSE_SYSTEM_TINYXML=ON \
-DUSE_SYSTEM_ZLIB=ON \
-DUSE_SYSTEM_SWIG=OFF \
-DOTB_WRAP_PYTHON=OFF \
&& make -j $(grep -c ^processor /proc/cpuinfo)
# ----------------------------------------------------------------------------
# Build OTB: Stage 3 (bindings)
# ----------------------------------------------------------------------------
RUN cd /work/otb/otb/Modules/Remote \
&& git clone https://github.com/remicres/otbtf.git \
&& cd /work/otb/build/OTB/build \
&& cmake /work/otb/otb \
-DOTB_WRAP_PYTHON=ON \
-DPYTHON_EXECUTABLE=/usr/bin/python3.6 \
-Dopencv_INCLUDE_DIR=/usr/include \
-DModule_OTBTensorflow=ON \
-DOTB_USE_TENSORFLOW=ON \
-DTENSORFLOW_CC_LIB=/work/tf/installdir/lib/libtensorflow_cc.so \
-DTENSORFLOW_FRAMEWORK_LIB=/work/tf/installdir/lib/libtensorflow_framework.so \
-Dtensorflow_include_dir=/work/tf/installdir/include/ \
&& cd /work/otb/build/ \
&& make -j $(grep -c ^processor /proc/cpuinfo)
# ----------------------------------------------------------------------------
# Add important environment variables
# ----------------------------------------------------------------------------
ENV PATH="$PATH:/work/otb/superbuild_install/bin/"
ENV PYTHONPATH="/work/otb/superbuild_install/lib/otb/python:$PYTHONPATH"
ENV OTB_APPLICATION_PATH="/work/otb/superbuild_install/lib/otb/applications"
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/work/otb/superbuild_install/lib/:/work/tf/installdir/lib/"
# ----------------------------------------------------------------------------
# Exemple :
# docker build --tag otbtf_image
# docker run -v /path/to/host/:/path/to/mount/ otbtf_image otbcli_ExtractROI
# docker run -ti -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY otbtf_image otbgui_ExtractROI
# ----------------------------------------------------------------------------
......@@ -138,7 +138,7 @@ RUN mkdir -p /work/otb \
&& cd /work/otb \
&& git clone https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git otb \
&& cd otb \
&& git checkout 7.0.0-rc1
&& git checkout release-7.0
# ----------------------------------------------------------------------------
# Build OTB: Stage 2 (superbuild)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment