Setting up a Deep learning library on i.MX6 UDOO board

Showing results for 
Search instead for 
Did you mean: 

Setting up a Deep learning library on i.MX6 UDOO board

Setting up a Deep learning library on i.MX6 UDOO board


Host machine with Ubuntu 14.04

UDOO Quad/Dual Board

uSD card with at least 8 GB

Download documentation and install latest Official Udoobuntu OS (at the moment of writing: UDOObuntu 2.1.2),



This document describes how to install and test Keras (Open source neural network library) and Theano (numerical computation library for python ) for deep learning library usage on i.MX6QD UDOO board.


$ sudo apt-get update && sudo apt-get upgrade

update your date system: e.g.

$ sudo date -s “07/08/2017 12:00”

First satisfy the run-time and build time dependencies:

$ sudo apt-get install python-software-properties software-properties-common make unzip zlib1g-dev git pkg-config autoconf automake libtool curl  python-pip python-numpy libblas-dev liblapack-dev python-dev libatlas-base-dev gfortran libhdf5-serial-dev libhdf5-dev python-setuptools libyaml-dev libpython2.7-dev

$ sudo easy_install scipy

The last step is installing scipy through pip, and can take several hours.


First, we have a few more dependencies to get:

$sudo pip install scikit-learn

$sudo pip install pillow

$sudo pip install h5py

With these dependencies met, we can install a stable Theano release from the git source:

$ git clone

$ cd Theano

Numpy 1.9 cause conflicts with armv7, so we need to change the configuration:

$ sudo nano

Remove line

   #       install_requires=['numpy>=1.9.1', 'scipy>=0.14', 'six>=1.9.0'],

And add



Then install it:

$ sudo python install


The installation can occur with the command: (this could take a lot of time!!!)

$ cd ..

$ git clone

$ cd keras

$ sudo python install


$sudo pip install --upgrade keras

After Keras is installed, you will want to edit the Keras configuration file ~/.keras/keras.json to use Theano instead of the default TensorFlow backend. If it isn't there, you can create it. This requires changing two lines. The first change is:

"image_dim_ordering": "tf"  --> "image_dim_ordering": "th"

and the second:

"backend": "tensorflow" --> "backend": "theano"

(The final file should look like the example below)

sudo nano ~/.keras/keras.json


    "image_dim_ordering": "th",

    "epsilon": 1e-07,

    "floatx": "float32",

    "image_data_format": "channels_last",

    "backend": "theano"


You can also define the environment variable KERAS_BACKEND and this will override what is defined in your config file :

$ KERAS_BACKEND=theano python -c "from keras import backend"


Quick test:

udooer@udoo:~$ python

Python 2.7.6 (default, Oct 26 2016, 20:46:32)

[GCC 4.8.4] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import keras

Using Theano backend.


Test 2:

Be aware this test take some time (~1hr on udoo dual):

$ curl -sSL -k | python



For demonstration, deep-learning-models repository provided by pyimagesearch and from fchollet git, and also have three Keras models (VGG16, VGG19, and ResNet50) online — these networks are pre-trained on the ImageNet dataset, meaning that they can recognize 1,000 common object classes out-of-the-box.

$ cd keras

$ git clone

$ Cd deep-learning-models

$ ls -l


Notice how we have four Python files. The , , and  files correspond to their respective network architecture definitions. The imagenet_utils  file, as the name suggests, contains a couple helper functions that allow us to prepare images for classification as well as obtain the final class label predictions from the network

Classify ImageNet classes with ResNet50

ResNet50 model, with weights pre-trained on ImageNet. This model is available for both the Theano and TensorFlow backend, and can be built both with "channels_first" data format (channels, height, width) or "channels_last" data format (height, width, channels). The default input size for this model is 224x224.

We are now ready to write some Python code to classify image contents utilizing  convolutional Neural Networks (CNNs) pre-trained on the ImageNet dataset. For udoo Quad/Dual use ResNet50 due to avoid space conflict. Also we are going to use ImageNet ( that is an image database organized according to the WordNet hierarchy, in which each node of the hierarchy is depicted by hundreds and thousands of images.

from keras.applications.resnet50 import ResNet50

from keras.preprocessing import image

from keras.applications.resnet50 import preprocess_input, decode_predictions

import numpy as np


model = ResNet50(weights='imagenet')


#for this sample I download the image from:

 img_path = 'elephant.jpg'

img = image.load_img(img_path, target_size=(224, 224))

x = image.img_to_array(img)

x = np.expand_dims(x, axis=0)

x = preprocess_input(x)


preds = model.predict(x)

# decode the results into a list of tuples (class, description, probability)

# (one such list for each sample in the batch)

print('Predicted:', decode_predictions(preds, top=3)[0])

Save the file an run it.

Results for elephant image:


Top prediction was 0.8890 for African Elephant

Testing with this image:




Top prediction was: 0.7799 for golden_retriever.

Now your Udoo is ready to use Keras and Theano as Deep Learning libraries, next time we are going to show some usage example for image classification models with OpenCV.


GitHub - fchollet/keras: Deep Learning library for Python. Runs on TensorFlow, Theano, or CNTK. 

GitHub - Theano/Theano: Theano is a Python library that allows you to define, optimize, and evaluate... 

GitHub - fchollet/deep-learning-models: Keras code and weights files for popular deep learning model... 

Installing Keras for deep learning - PyImageSearch 

Labels (5)

Hello Bio_TICFSL, the document looks very interesting. I haven't tested yet (but I want to, as it looks great) but I would recommend maybe adding links to more in depth documentation for reference and maybe you could even create another document as introduction to machine learning.

I would also actually add the image of the elephant to prior or after the elephant tests just to make it more clear (similar to the example of the golden retriever).


can we do it on Udoo Neo? I tried but it seem not work.

Version history
Revision #:
1 of 1
Last update:
‎07-12-2017 01:02 PM
Updated by: