Filter results by

TensorFlow Lite Machine Learning

TensorFlow is the most widely used tool for Machine Learning applications. Though training a network is computationally very intensive, this article serves to demonstrate that the real world inference is not computationally overloading.

Prerequisites

The article describes the steps to run TensorFlow Lite v1.9 on the ARTIK 530s-1G (such as the module used on the Eagleye-530s board). The -1G version is required; base ARTIK 530s modules do not have sufficient memory to run the current version. For ARTIK 710 modules, you can install the standard TensorFlow package (not described here).

You'll need extra storage space (8GB min) on a USB flash drive attached to the board.

Installation

  1. Install the required tools for building TensorFlow Lite on ARTIK the 530s-1G.

    apt update
    apt install build-essential unzip git

  2. Get the source or binary. Download TensorFlow source code on A530s1G. Note, the default code in the TensorFlow repo does not build directly on ARTIK due to floating instruction mismatch. ARTIK530 uses floating point co-processor version 3 and the correct ARM version. The modified versions can be accessed from this repository.

    git clone https://github.com/SamsungARTIK/tensorflow.git

  3. Download Eigen library dependencies. The Eigen library contains the linear algebra and vector multiplication related supporting functions.

    ./tensorflow/contrib/lite/download_dependencies.sh

  4. To avoid RAM space limitations, create additional swap space from a USB drive as follows.

    1. Identify the USB device name.

      fdisk -l

    2. Make the swap partition.

      mkswap /dev/sda1

    3. Turn on the swap partition.

      swapon -p 32767 /dev/sda1

    4. Check whether it is working.

      cat /proc/swaps

  5. Compile TensorFlow Lite. The makefile and build script have all the ARTIK-related customizations; just run the build script.

    ./tensorflow/contrib/lite/build_artik_lib.sh

    This will generate the tensorflow-lite.a library in
       ./tensorflow/contrib/lite/gen/lib/artik530_armv7
    and the sample test application (label_image) in
       ./tensorflow/contrib/lite/gen/bin/artik530_armv7

Copy Application Files

Run the following commands to download the models into a test directory.

1
2
3
4
5
6
7
8
mkdir test
cd test
cp ../tensorflow/contrib/lite/gen/bin/artik530_armv7/label_image .
wget http://download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224.tgz
tar zxvf mobilenet_v1_1.0_224.tgz
wget http://download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224_quant.tgz
tar zxvf mobilenet_v1_1.0_224_quant.tgz
cp ../tensorflow/contrib/lite/java/ovic/src/testdata/labels.txt .

Operation

Run TFLite. The test application, label_image is built using the tensorflow-lite library generated earlier. Execute the application as follows.

Command line format

The general command line for this application is as shown.

./label_image -v 1 -m ./<model> -i ./<image> -l ./labels.txt

Param Description
-v Refers to verbose option
-m Convolutional neural network model on which computation is performed. The pre-trained version of various TensorFlow models can be downloaded from the repository. mobileNet 1.0 (using float operators) and its quant variant (without float operators) are used for this exercise.
-i Input image file that needs to be detected. You can use a sample test image from the testdata folder, or take a new picture directly.
-l Labels file used for training the model. There are about 1000 objects that can be detected using this model in the application discussed here.

Examples

Try out the application first using the provided image file. Copy it to your test directory as shown.

1
cp ../tensorflow/contrib/lite/examples/label_image/testdata/banana.bmp .

To run the test application, not using float operators:

1
./label_image -v 1 -m ./mobilenet_v1_1.0_224_quant.tflite -i ./banana.bmp -l ./labels.txt

To run the test application using float operators:

1
./label_image -v 1 -m ./mobilenet_v1_1.0_224.tflite -i ./banana.bmp -l ./labels.txt

Input image format

When you're ready, test the program using your own photo. Take a picture of a banana or strawberry from your mobile phone.

Convert the image to bmp format with 517x606 pixel resolution, then reference that image file in your command line. The resolution conversion is required as all the images in this model were trained with that resolution. See this site to convert an image.

Send the converted file to your ARTIK module using scp. For example, from the host machine:

scp banana.bmp root@<ip address>:/location/of/test/folder

Last updated on: