Xnor.ai released the AI2GO platform which provides access to deep learning models that can be easily embedded in your Toradex board with Xnor SDK Samples. This article shows a step-by-step how to use the platform and put a model downloaded from AI2GO to running on an Apalis iMX6.
You must have:
Firstly, to access the available model settings and options, you must log in to the AI2GO platform. Sign in: https://ai2go.xnor.ai/login
Read and accept the terms of service:
After accepting the terms of service, the LOG IN
button will be enabled. To create an account you can use the sign up services of Github, Google, Linkedin or an email with password.
After login, click on DOWNLOAD BUNDLE
to access the AI2GO platform options.
Click on Toradex
option:
In this section you can choose among 4 types of industry. Each industry has several use cases that can be chosen. For the example of this article choose Smart Home
:
Just below in the page you can still filter the models by tasks
: Detection, Multi-Class or Classification. For the example of this article select the Multi-Class filter:
With the selected filter click on the Indoor Object Classifier
option and click on the CONTINUE
button:
In this session you can choose and download models that were pretuned according to the options selected in the previous steps. The first option that the platform gives is the QUICK START
model, this will be the one chosen for the example of this article:
The platform also allows the download of other models with customized options, the user can select latency time response and memory for better adaptation of your application in the ADVANCED MODE
:
The last step inside the AI2GO platform is the download of the Xnor model and SDK:
With this we can use the samples from the Xnor SDK with the pretuned model downloaded from AI2GO.
Install pre-requisite packages:
$ sudo apt-get install unzip openssh-client
Unzip the downloaded files and configure your linux host to cross compile with the Toradex SDK toolchain.
$ unzip sdk_v1.0.0.zip $ cd xnor-sdk xnor-sdk/$ . /usr/local/oecore-x86_64/environment-setup-armv7at2hf-neon-angstrom-linux-gnueabi
In the Xnor SDK folder we have the following structure:
xnor-sdk/$ ls docs include lib LICENSE.txt README.txt samples
The samples for Apalis iMX6 will be inside the samples/toradex-apalis-imx6/c
folder with the following structure:
xnor-sdk/samples/toradex-apalis-imx6/c/$ ls classify_image_file.c model_benchmark.c common_util object_detector.c detect_and_print_objects_in_image.c qt-demo json_dump_objects_in_image.c README.md Makefile segmentation_mask_of_image_file_to_file.c
In this folder compile the examples with the command:
xnor-sdk/samples/toradex-apalis-imx6/c/$ make
If everything builds correctly we will have the samples compiled for Apalis iMX6 in the build
folder:
xnor-sdk/samples/toradex-apalis-imx6/c/build/$ ls classify_image_file libxnornet.so common_util model_benchmark detect_and_print_objects_in_image object_detector json_dump_objects_in_image segmentation_mask_of_image_file_to_file
During the build the Xnor SDK generates a generic model for use with the samples, the libxnornet.so
file. To use the pretuned model downloaded from AI2GO, copy and override the libxnornet.so
file extracted from bundle:
~$ unzip indoor-object-classifier-large-200.zip ~$ cp indoor-object-classifier-large-200/libxnornet.so xnor-sdk/samples/toradex-apalis-imx6/c/build/
With Ixora plugged in and connected to the network, copy the build
folder generated during compile to the board using SSH:
Warning: Remember to change <board ip>
from the command below to the ip address assigned to the board.
xnor-sdk/samples/toradex-apalis-imx6/c/$ scp -r build/ root@<board ip>:/home/root
For the correct execution of the example you also need to copy some libs from the local Linux host toolchain to the board, run the command:
xnor-sdk/samples/toradex-apalis-imx6/c/$ scp /usr/local/oecore-x86_64/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/usr/lib/libatomic.so* root@<board ip>:/usr/lib/
On linux running on the board, open a new terminal and go to the /home/root/build/
folder, the folder where we copied the cross compiled programs:
/home/root/build/# ls classify_image_file libxnornet.so common_util model_benchmark detect_and_print_objects_in_image object_detector json_dump_objects_in_image segmentation_mask_of_image_file_to_file
For the example of this article we selected the Indoor Object Classifier
model, which is pretuned to classify people, cats and dogs into images. Therefore, the executable classify_image_file
sample will be used:
/home/root/build/# ./classify_image_file Usage: ./classify_image_file <image.jpg>
This sample expects a JGP image as input for classify. To do this, download an image that you want to classify and put as input to the program. Examples:
/home/root/build/# wget https://docs.toradex.cn/106280-dog-on-library.jpg /home/root/build/# ./classify_image_file 106280-dog-on-library.jpg .------------------------. .----------------( Xnor.ai Evaluation Model )-----------------. | '------------------------' | | You're using an Xnor.ai model for evaluation purposes only. | | This evaluation version has a limit of 10000 inferences per | | startup, after which an error will be returned. Commercial | | Xnor.ai models do not contain this limit or this message. | | Please contact Xnor.ai for commercial licensing options. | '-------------------------------------------------------------' This looks like... dog
/home/root/build/# wget https://docs.toradex.cn/106281-balaio-de-gato.jpg /home/root/build/# ./classify_image_file 106281-balaio-de-gato.jpg .------------------------. .----------------( Xnor.ai Evaluation Model )-----------------. | '------------------------' | | You're using an Xnor.ai model for evaluation purposes only. | | This evaluation version has a limit of 10000 inferences per | | startup, after which an error will be returned. Commercial | | Xnor.ai models do not contain this limit or this message. | | Please contact Xnor.ai for commercial licensing options. | '-------------------------------------------------------------' This looks like... cat
/home/root/build/# wget https://docs.toradex.cn/106282-people.jpg /home/root/build/# ./classify_image_file 106282-people.jpg .------------------------. .----------------( Xnor.ai Evaluation Model )-----------------. | '------------------------' | | You're using an Xnor.ai model for evaluation purposes only. | | This evaluation version has a limit of 10000 inferences per | | startup, after which an error will be returned. Commercial | | Xnor.ai models do not contain this limit or this message. | | Please contact Xnor.ai for commercial licensing options. | '-------------------------------------------------------------' This looks like... person