# Model building (Your First Edge AI Project)

Note: This page is a part of the tutorial Your First Edge AI Project

# Background

We have divided our labelled data into different data sets and put it all in a database. Now it's time to configure and build AI models and train them using this database.

An AI model typically consists of a chain of two or three different steps/components which have to be configured:

  1. Pre-processing
  2. Model
  3. Post-processing (optional)

(1.) Data can typically be processed in a way that makes it easier to understand for the AI model.

(2.) The actual model that will operate on the processed data in order to make classifications/predictions.

(3.) Sometimes we can improve the output of the model by also processing the output of the network. This is not covered in this tutorial.

Let's configure the necessary components necessary for model training.

Note: Your directory structure and file names might be different from the examples in the pictures below.

# Input

The first step of the model building is to configure the Pre-processor.

An empty preprocessor, ready to be configured

Note: Our accelerometer sensor is a 3-axis accelerometer that generates data in the format of [x,y,z]. Where x/y/z is the acceleration in the x/y/z-axis respectively. Data of the form [x,y,z] is said to have the shape of 3 or [3].

The pre-processor automatically detects the data shape from the data track we selected when importing segments in the Data tab.

# Pre-processing

# Sliding Window

The pre-processing that we will use in this guide will consist of a single Sliding Window layer.

The purpose of the sliding window layer is to group several sensor readings together (into a window) and let the AI model classify these readings together. This gives the AI model context which it wouldn't have if we tried to classify an individual data point/sensor reading.

We will set our Sliding Window shape to [50,3], meaning that we will group 50 readings of shape [3] and make a classification of those 50 readings together. The sensor that we used during data collection has a sampling rate of 50 Hz, meaning that a window of 50 readings will cover a time period of 1 second.

Tip: As a rule of thumb, your sliding window should be big enough to fit the length of the longest label in your dataset.

# Pre-processor Layers list

Let's add the Sliding Window to the Pre-processor by clicking (+).

The Sliding Window layer is located under Queues -> Sliding Window. Select it and configure your sliding window as above. Then click "OK".

# Window dimensions

This setting controls the dimension of the window. The shape [50,3] means that the window will fit 50 data points of size 3 (x,y,z from the accelerometer sensor).

# Window stride

The window stride parameter controls how far the window will be moved before we start filling the window up again with new data. A setting of 30 in the current context means that we will move the window 10 time steps. Each time step contains one data point of size 3 (x,y,z from the accelerometer sensor).

The sum becomes 10 * 3 = 30 data points.

# Buffer size multiplier

Our final AI application will need an internal memory buffer to store this sliding window. The size of this buffer is computed by Imagimob Studio. However, the computed memory is the minimum required memory during runtime.

Setting this value to 1 means that all calculations needed for the pre-processing layers plus the AI model itself must occur before a new data point is inputted again. If this value is set to 2, a new, full window can be input while calculating the output from the AI model for the previous window.

If set too low, your AI application might crash at runtime. Recommended value: 2.00.

# Generate pre-processor tracks

Before building models, we can look at the data after pre-processing by clicking on the button Create Track from Preprocessor....

After naming the pre-processor tracks and naming the output directory, click "OK".

We can track the progress in the open console. A new folder with your selected name (PreprocessorTrack in our example) is generated inside your project.

Now we can expand one segment to see the pre-processing result. This is very useful for evaluating the pre-processing pipeline.

Note: The data in the plot panel can be viewed both as a line plot and as a heatmap. This setting is exposed by right-clicking on the name of the data track "Preprocessor" or "accel" in the example above.

# Model building/Model generation

Now that we are done with the pre-processing configuration, it's time to move on to configure a list of models that will be sent to our AI Training Service for training. For that, move to the Training tab and click on "Generate Model List...".

In the next section of the configuration, we will select a label strategy and define the size of the model list.

As you can see, in the Model Wizard, there are four parameters for us to tune.

The Number Of Model Structures defines the number of different model structures to generate, and the Number Of Hyper Parameters defines the number of different hyperparameters for each model structure. The product of these two values gives the number of models that will be generated.

The Epochs parameter defines the number of iterations for training one model, the Batch Size is the number of windows to send to update the model.

Read about Model parameters here.

After we fix all the parameters in the Model Wizard, we are ready to click "OK" to generate a list of models and all existing models will be replaced. Finally, we click Start New Training Job... to start the model training.

In the next dialog, you can name your training job and input a description of it. When you're ready, press Start.

Note: Depending on the size of your database, transferring the job to the AI Training Service might take a while.

Once the job is sent, you will see the dialog above. Select "OK" and your job will open up in a new tab.

Note: Save your progress at any time by pressing 'Ctrl + S' in Imagimob Studio

# Errors/Pitfalls

Double-check your data labelling and database before starting your training job. If you have a large database and/or a large training job, you might have to wait a long time for the results just to see that you missed label parts of the data or had an uneven data split between your train/validation/test sets.

Next Section - Model Evaluation