Deep Learning Environment Setup for Linux

Environment Setup | 04 February 2017

In this tutorial, we will setup the environment for Deep Learning and Computer Vision in Linux. This tutorial assumes that you have knowledge about using Linux Environment such as Ubuntu and basic knowledge of Linux commands.

Update: If you use Windows, I would suggest you to download Virtual Box (which is open-source) and install Ubuntu in it (which is also open-source). But if you really want to work in a Windows machine, then check out this post for setting up Deep Learning environment in Windows 10.

  • Install python (high-level programming language)
    The first step is to download and install Python from this website. Download Python 2.7 version as it is the most stable release of Python. Python 3.0 and above versions are good to download, but there are some backwards-incompatible changes which might produce some errors. So, better use Python 2.7 version.

  • Install pip (python package manager)

1
2
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
  • Install all the other necessary packages.
1
2
3
4
5
6
7
8
9
10
11
sudo pip install numpy
sudo pip install scipy
sudo apt-get install python-tk
sudo pip install seaborn
sudo pip install matplotlib
sudo pip install pandas
sudo pip install librosa
sudo pip install scikit-learn
sudo pip install tensorflow
sudo pip install theano
sudo pip install keras

Dependencies for Computer Vision

  • Developer tools
1
sudo apt-get install build-essential cmake git pkg-config
  • Image I/O packages
1
sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev
  • GTK Development Library
1
sudo apt-get install libgtk2.0-dev
  • Accessing frames and video processing
1
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
  • Optimize routines in OpenCV
1
sudo apt-get install libatlas-base-dev gfortran
  • Install OpenCV 3.1
1
2
3
4
cd ~ 
git clone https://github.com/Itseez/opencv.git 
cd opencv 
git checkout 3.1.0 
  • Install OpenCV contrib 3.1
1
2
3
4
cd ~
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv_contrib
git checkout 3.1.0
  • Build OpenCV
1
2
3
4
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
  • Compile OpenCV
1
make
  • Install OpenCV
1
2
sudo make install 
sudo ldconfig

Note: If you install librosa in Windows, you will need FFmpeg which could be downloaded here. Extract the .zip file and add bin folder of FFmpeg to PATH in system environment variables.

After installing all these libraries, open up a terminal and type python. After that, import all the packages using import (package-name) (for example, import numpy) and verfiy the version of each package. In case if you get any error, uninstall that package using sudo pip uninstall (package-name), and then reinstall that package again with pip. Sometimes I faced this issue and solved it using this simple method.

In case if you found something useful to add to this article or you found a bug in the code or would like to improve some points mentioned, feel free to write it down in the comments. Hope you found something useful here.