Introduction

This example aims to design a classification system deployed in Arduino Nano (https://store.arduino.cc/usa/arduino-nano) that can classify all 3 different IRIS flowers.

Figure 4.51: Three IRIS flowers.

Data preparation and feature extraction


In order to classify three IRIS flowers, common features such petal length, petal width, sepal length and sepal width are used. The IRIS flowers' dataset can be obtained via Wikipedia (https://en.wikipedia.org/wiki/Iris_flower_data_set). The dataset contains a set of 150 records under five attributes as follows:


Figure 4.52: IRIS flowers' dataset under 5 attributes: Sepal Length, Sepal Width, Petal Length, Petal Width and Species.


Since 3 types of IRIS flowers being classified, the Neural Network classifier will contain 3 outputs as shown in Figure 4.53.


Figure 4.53: Neural Network Classifier for IRIS flowers.



The IRIS dataset will be separated into training set (106 samples) and test set (44 samples) as following format (csv extension).

Figure 4.54: IRIS flower training set.


Three outputs are mapped by binary code that is [1 0 0] will be Setosa, [0 1 0] will be Versicolor and [0 0 1] will be Virginica.


Design Bayesian Neural Network Classifier using ANNHub

First the ANNHub is used to design the Neural Network classifier in 4 steps. The Bayesian Neural Network is used in this case as the dataset is small.



Figure 4.55: Design Bayesian Neural Network Classifier for IRIS classification.



Test Bayesian Neural Network Classifier with test dataset (44 data samples)

Figure 4.56: Evaluate Bayesian Neural Network Classifier with test dataset.




Export trained Neural Network Classifier into Arduino source code.




Figure 4.57: Export trained Neural Network Classifier into Arduino Sketch format

Import Arduino source code into Arduino IDE



Figure 4.58: Load Arduino Sketch format into Arduino IDE.


This Arduino source code (sketch) can be compiled and uploaded directly to Arduino device (Arduino Nano).

Figure 4.59: Compile and upload Arduino Sketch into Arduino device (Arduino Nano) via USB port.


Test Arduino Nano based Neural Network Classifier

Figure 4.60:Communication between Laptop PC and Arduino device (Arduino Nano) via USB port.



To demonstrate the prediction capability of the trained Neural Network deployed in Arduino Nano, the hardware setup is shown in Figure 4.60. In this setup, the Laptop PC sends inputs (sepal length, sepal width, petal length, petal width) to Arduino Nano via USB (serial communication), the Arduino Nano then interprets these inputs to give prediction based on trained Neural Network in its firmware. This prediction result will be sent back to PC via USB (serial communication).

Figure 4.51:Serial communication interface between Laptop PC and Arduino device (Arduino Nano) via USB port.




1. Prediction of Setosa


2. Prediction of Versicolor


3. Prediction of Virginica

Conclusion

In this example, Bayesian Neural Network is used to classify three types of IRIS flowers. This Bayesian Neural Network then is deployed directly to Arduino Nano (with limited RAM memory - 2kB only). The Arduino Nano based AI device can handle classification task that can successfully recognise different types of IRIS flowers based on theirs sepal length, sepal width, petal length and petal width.


This example also demonstrates the capability of ANNHub that allows designers deploying a Neural Network on embedded system easily.