Wiki

Clone wiki

DeepDriving / InstallUbuntuCompile

Installation on Ubuntu

Compiling the C-Libraries

Introduction

For several reasons some python modules require C-Libraries, which must be compiled, before using the python modules. The following libraries are contained in this project:

  • leveldb: A version of the leveldb library, which uses CMake and can be compiled on Windows. This is simply a copy of the following project: leveldb-cmake. This library is required to read the original training data, which are provided as leveldb files.

  • datareader: A library which uses the leveldb library to read the original training data and decode it to raw data, which can be used by python.

  • situation: A library which creates an image of the nearby situation around the host car. This code is derived from the original DeepDriving project.

  • drivecontroller: A library which calculates the steering, acceleration and breaking commands for the game out of the 14 indicators from the neural network. This code is derived from the original DeepDriving project.

Pre-Requirements

The following software is needed to compile this project:

  • The following description is for Ubuntu 16.04 and GCC 4.8.5. But it should also work with different versions.

  • For cloning the repository, GIT LFS is necessary. Otherwise the media files (music, sound, graphic) are missing.

  • You need CMake (at least version 3.7).

    • If you have an older version installed, do the following:
    • Uninstall the old cmake: sudo apt-get remove cmake
    • Download the linux binary version from https://cmake.org/download/ (for example cmake-3.9.1-Linux-x86_64.sh)
    • Make this script executable: chmod +x cmake-3.9.1-Linux-x86_64.sh
    • Run this script with root rights: ./cmake-3.9.1-Linux-x86_64.sh
    • Press two times "y"
    • Add a symbolic link for the binary: sudo ln -s <install-path>/cmake-3.9.1-Linux-x86_64/bin/* /usr/local/bin/
    • check the new cmake version: cmake --version

Install OpenCV from GitHub

  • I had issues with the Python-OpenCV version from PIP and apt-get, thus I need to install my own version. The following instructions are from this thread.

  • First remove the installed OpenCV version, if there is a preinstalled version:

sudo apt-get remove libopencv-*

sudo pip3 uninstall opencv-python
  • Install dependencies:
sudo apt-get install libgtk2.0-dev pkg-config
  • Clone the OpenCV repository and checkout a stable version:
git clone https://github.com/opencv/opencv.git

git clone https://github.com/opencv/opencv_contrib.git

cd opencv_contrib

git checkout 3.3.0

cd ..

cd opencv

git checkout 3.3.0
  • Configure CMake
mkdir build

cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_PNG=True ..
  • If you want to build opencv with CUDA support (you need a Nvidia graphic card for this), use the following cmake command:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_PNG=True \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 ..
  • The output of the configuration should look like this:
...

-- General configuration for OpenCV 3.3.0 =====================================
--   Version control:               3.3.0
-- 
--   Platform:
--     Timestamp:                   2017-08-25T09:59:59Z
--     Host:                        Linux 4.4.0-92-generic x86_64
--     CMake:                       3.9.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2
--       SSE4_1 (2 files):          + SSSE3 SSE4_1
--       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (7 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 4.8.5)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          gtk-x11-2.0 gdk-x11-2.0 pangocairo-1.0 atk-1.0 cairo gdk_pixbuf-2.0 gio-2.0 pangoft2-1.0 pango-1.0 fontconfig freetype gthread-2.0 /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libtiff.so /usr/lib/x86_64-linux-gnu/libjasper.so /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so gstbase-1.0 gstreamer-1.0 gobject-2.0 glib-2.0 dc1394 avcodec-ffmpeg avformat-ffmpeg avutil-ffmpeg swscale-ffmpeg dl m pthread rt cudart nppc nppi npps cufft -L/usr/local/cuda/lib64
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 cudev core cudaarithm flann imgproc ml objdetect video cudabgsegm cudafilters cudaimgproc cudawarping dnn imgcodecs photo shape videoio cudacodec highgui ts features2d calib3d cudafeatures2d cudalegacy cudaobjdetect cudaoptflow cudastereo java stitching superres videostab python2 python3
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 viz
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 2.x:                    YES (ver 2.24.30)
--     GThread :                    YES (ver 2.48.2)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6)
--     JPEG 2000:                   /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
--     GDAL:                        NO
--     GDCM:                        NO
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.4)
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 56.60.100)
--       avformat:                  YES (ver 56.40.101)
--       avutil:                    YES (ver 54.31.100)
--       swscale:                   YES (ver 3.1.101)
--       avresample:                NO
--     GStreamer:                   NO
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     OpenNI2:                     NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     Aravis SDK:                  NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    NO/YES
--     XIMEA:                       NO
--     Xine:                        NO
--     Intel Media SDK:             NO
--     gPhoto2:                     NO
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Use Intel IPP:               2017.0.2 [2017.0.2]
--                at:               /home/aadc/opencv/opencv/build/3rdparty/ippicv/ippicv_lnx
--     Use Intel IPP IW:            prebuilt binaries (2017.0.2)
--     Use Intel IPP Async:         NO
--     Use VA:                      NO
--     Use Intel VA-API/OpenCL:     NO
--     Use Lapack:                  NO
--     Use Eigen:                   NO
--     Use Cuda:                    YES (ver 8.0)
--     Use OpenCL:                  YES
--     Use OpenVX:                  NO
--     Use custom HAL:              NO
-- 
--   NVIDIA CUDA
--     Use CUFFT:                   YES
--     Use CUBLAS:                  NO
--     USE NVCUVID:                 NO
--     NVIDIA GPU arch:             20 30 35 37 50 52 60 61
--     NVIDIA PTX archs:
--     Use fast math:               NO
-- 
--   OpenCL:                        <Dynamic loading of OpenCL library>
--     Include path:                /home/aadc/opencv/opencv/3rdparty/include/opencl/1.2
--     Use AMDFFT:                  NO
--     Use AMDBLAS:                 NO
-- 
--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.12)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
--     numpy:                       /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.12.1)
--     packages path:               lib/python2.7/dist-packages
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.5.2)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.5m.so (ver 3.5.2)
--     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.11.0)
--     packages path:               lib/python3.5/dist-packages
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Java:
--     ant:                         /usr/bin/ant (ver 1.9.6)
--     JNI:                         /usr/lib/jvm/java-8-oracle/include /usr/lib/jvm/java-8-oracle/include/linux /usr/lib/jvm/java-8-oracle/include
--     Java wrappers:               YES
--     Java tests:                  YES
-- 
--   Matlab:                        Matlab not found or implicitly disabled
-- 
--   Documentation:
--     Doxygen:                     /usr/bin/doxygen (ver 1.8.11)
-- 
--   Tests and samples:
--     Tests:                       YES
--     Performance tests:           YES
--     C/C++ Examples:              NO
-- 
--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /home/aadc/opencv/opencv/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
  • Build and Install OpenCV
make

sudo make install

Install the Boost-Library

  • Unfortunately on my system I got compatibility issues between the pre-compiled boost package from Ubuntu and my compiler. This leads to segmentations faults when using boost::filesystem::path objects. Thus I had to compile boost from source.

  • Delete any pre-installed version of boost:

sudo apt-get remove libboost-all-dev
  • Download the boost library
wget https://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.tar.bz2
  • Extract the archive:
tar --bzip2 -xf boost_1_61_0.tar.bz2
  • Configure the source compilation:
cd boost_1_61_0

./bootstrap.sh --prefix=<boost-install-path>
  • Compile boost and install it
./b2 install
  • Add the boost-library path to your LD_LIBRARY_PATH environment variable. For example with:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<boost-install-path>/lib

Install the Snappy-Library

  • Clone the snappy repository from google and checkout the version 1.1.6:
git clone https://github.com/google/snappy.git

cd snappy

git checkout 1.1.6
  • Use CMake to configure and generate the snappy makefiles:
mkdir build 

cd build 

cmake ..
  • The output should look like this:
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for include file byteswap.h
-- Looking for include file byteswap.h - found
-- Looking for include file dlfcn.h
-- Looking for include file dlfcn.h - found
-- Looking for include file inttypes.h
-- Looking for include file inttypes.h - found
-- Looking for include file memory.h
-- Looking for include file memory.h - found
-- Looking for include file stdlib.h
-- Looking for include file stdlib.h - found
-- Looking for include file strings.h
-- Looking for include file strings.h - found
-- Looking for include file string.h
-- Looking for include file string.h - found
-- Looking for include file sys/byteswap.h
-- Looking for include file sys/byteswap.h - not found
-- Looking for include file sys/endian.h
-- Looking for include file sys/endian.h - not found
-- Looking for include file sys/mman.h
-- Looking for include file sys/mman.h - found
-- Looking for include file sys/resource.h
-- Looking for include file sys/resource.h - found
-- Looking for include file sys/stat.h
-- Looking for include file sys/stat.h - found
-- Looking for include file sys/time.h
-- Looking for include file sys/time.h - found
-- Looking for include file sys/uio.h
-- Looking for include file sys/uio.h - found
-- Looking for include file unistd.h
-- Looking for include file unistd.h - found
-- Looking for include file windows.h
-- Looking for include file windows.h - not found
-- Looking for zlibVersion in z
-- Looking for zlibVersion in z - found
-- Looking for lzo1x_1_15_compress in lzo2
-- Looking for lzo1x_1_15_compress in lzo2 - not found
-- Performing Test HAVE_BUILTIN_EXPECT
-- Performing Test HAVE_BUILTIN_EXPECT - Success
-- Performing Test HAVE_BUILTIN_CTZ
-- Performing Test HAVE_BUILTIN_CTZ - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/aadc/snappy/snappy/build
  • Start compiling:
make
  • Install snappy:
sudo make install

Prepare Compiling of the DeepDriving Project

  • Clone the DeepDriving repository. The directory where the repository was cloned in, will be called <repository-path> in the upcoming instructions.
git clone https://bitbucket.org/Netzeband/deepdriving.git

cd deepdriving

git checkout v1.0
  • Open the CMake-GUI:
cmake-gui &
  • Enter the library path <repository-path>/library in the file "Where is the source code".

  • Enter a build path in the field "Where to build the binaries". I prefer to always use the path <repository-path>/library/build/linux64/debug.

Step 1

  • Press "Configure".

  • Answer "Yes" to the question, if the build directory should be created.

Step 2

  • Chose as generator "Unix Makefiles" and the option "Use default native compilers". Press "Finish".

Step 3

  • No errors should appear. However it could be, that the boost library was not found.

  • Add the variable "BOOST_ROOT" as PATH with <boost-install-path> as value.

  • Change the variable "CMAKE_BUILD_TYPE" to "Debug".

  • Change the variable "CMAKE_INSTALL_PREFIX" to a path like <repository-path>/install/linux64/debug

Step 4

  • Press again "Configure".

  • The log should look like this:

Boost version: 1.61.0
Found the following Boost libraries:
  filesystem
  date_time
  system
Compile library dd-situation-view...
 * Use Defines: 
 * Use Include-Dirs: ../common/includes;includes;src/includes
Compile library dd-drivecontroller...
 * Use Defines: 
 * Use Include-Dirs: ../common/includes;includes;src/includes
Boost version: 1.61.0
Found the following Boost libraries:
  date_time
  filesystem
  system
  thread
  chrono
  atomic
Read snappy root-directory from environment variable SNAPPY_ROOT: 
Found Snappy:
 * Snappy include path: /usr/local/include
 * Snappy library:      /usr/local/lib/libsnappy.so
Enable Posix port...
Compile library dd-datareader...
 * Use Defines: 
 * Use Include-Dirs: ../common/includes;includes;src/includes
Configuring done
  • Press "Generate" to create the makefiles.

  • Close the CMake-GUI.

Compiling

  • Change to the build directory and start compiling with make.
cd <repository-path>/library/build/linux64/debug

make
  • Install the binaries:
make install

Computer-Setup

  • You need to add the path <install-path>\python to the PYTHONPATH environment variable of your session/computer. Otherwise the deep-driving script cannot find the python modules for those libraries.

  • Example:

export PYTHONPATH=$PYTHONPATH:<repository-path>/library/install/linux64/debug/python
  • Furthermore you need to add the path <install-path>\bin to the LD_LIBRARY_PATH environment variable in order to allow python to find the libraries.

  • Example:

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<repository-path>/library/install/linux64/debug/bin
    

Testing

  • Change to the python folder of the install-directory:
cd <repository-path>\library\install\linux\debug\python
  • Here you can run several example python scripts.

  • The script example_datareader.py opens a training data leveldb directory from the original DeepDriving project and shows the images on a small window. By pressing any key the next image is shown. By pressing escape, the example application exits:

python3 example_datareader.py <original-deepdriving-training-data>
  • The script example_drivecontroller.py tests the drive-controller:
python3 example_drivecontroller.py
  • The script example_situation_view.py tests the situation view generator. By pressing escape the next mode is shown or the application exists.
python3 example_situation_view.py

Next Step

Updated