Installation of OpenCV, Keras and Tensorflow On Ubuntu 14.04

Reference: http://www.pyimagesearch.com/2016/11/14/installing-keras-with-tensorflow-backend/
step-by-step instructions to install Keras using a TensorFlow backend for machine learning.

Keras is simply a wrapper around more complex numerical computation engines such as TensorFlow and Theano.

When it comes to Keras you have two choices for a backend engine — either TensorFlow or Theano. Theano is older than TensorFlow and was originally the only choice when selecting a backend for Keras.

So why might you want to use TensorFlow over Theano?

The short version is that TensorFlow is extremely flexible, allowing you to deploy network computation to multiple CPUs, GPUs, servers, or even mobile systems without having to change a single line of code.

This makes TensorFlow an excellent choice for training distributed deep learning networks in an architecture agnostic way, something that Theano does not (currently) provide.

Installation:

  1. Use Python virtual environments.

    You can quit the virtualenv with command ‘deactivate’

    And go back the virtualenv with command ‘workon opencv_keras_tf’

    Check python version:

     
  2. Install TensorFlow
    NOTE: Read this about CUDA compute capability : http://stackoverflow.com/questions/10961476/what-are-the-differences-between-cuda-compute-capabilities
    IT SEEMS DEPEND ON THE HARDWARE! NOTHING CAN DO TO IMPROVE THE COMPUTE CAPABILITY!
    AFTER READING THIS https://www.tensorflow.org/versions/r0.10/get_started/os_setup#installing_from_sources AND http://stackoverflow.com/questions/38542763/how-can-i-make-tensorflow-run-on-a-gpu-with-capability-2-0, I GOT SAD NEWS THAT
    In order to build or run TensorFlow with GPU support, both NVIDIA’s Cuda Toolkit (>= 7.0) and cuDNN (>= v3) need to be installed.
    TensorFlow GPU support requires having a GPU card with NVidia Compute Capability >= 3.0.
    SO MY GPU GeForce GT 520M THAT ONLY HAS CUDA COMPUTE CAPABILITY 2.1 (REF: https://en.wikipedia.org/wiki/CUDA) CAN’T BE USED FOR TENSORFLOW!!!I ONLY CAN USE CPU!!!To install TensorFlow, refer to this page: https://www.tensorflow.org/versions/r0.11/get_started/os_setup.
    Currently I have CUDA 7.5 toolkit installed

    The tensorflow page need CUDA toolkit 8.0 and CuDNN v5. I already installed them. I go to ‘Pip installation’ and choose this binary option:

    SO let’s begin:

    Install TensorFlow:

    Test the installation

     
  3. Install Keras
    Install a few Python dependencies:
    Install numpy scify

    Install scikit-learn

    Install pillow

    Install h5py

    Install keras

    Then run ‘import keras’ in python console to create keras.json file (http://stackoverflow.com/questions/40310035/how-to-change-keras-backend-wheres-the-json-file)

    keras.json file would be created in ~/.keras/ (~/.keras/keras.json file)

    Specifically, you’ll want to ensure that image_dim_ordering  is set to tf  (indicating that the TensorFlow image dimension ordering is used rather than th  for Theano).

    You’ll also want to ensure that the backend  is properly set to tensorflow  (rather thantheano ).

  4. Symlink with OpenCV
    My opencv binding file for python 3 is in /usr/local/lib/python3.4/site-packages/cv2.cpython-34m.so. I need to symlink it with the virtualenv ‘opencv_keras_tf’ like this:
    Go into this directory:

    Then symlink it (HERE I CHANGE THE FILE TO ‘cv2.so’)

    Test it

    OK. NO ERROR

Leave a Reply

Your email address will not be published. Required fields are marked *