|
1 | 1 | --- |
2 | | -title: Set up your environment |
| 2 | +title: Train and deploy a TinyML audio classifier with Edge Impulse |
3 | 3 | weight: 3 |
4 | 4 |
|
5 | | -### FIXED, DO NOT MODIFY |
| 5 | +# FIXED, DO NOT MODIFY |
6 | 6 | layout: learningpathall |
7 | 7 | --- |
| 8 | + |
8 | 9 | # Using Edge Impulse to Train TinyML models |
9 | 10 |
|
10 | 11 | Now that you've learned the foundational concepts of Edge AI and TinyML, it's time to move from theory to practice. |
@@ -48,131 +49,152 @@ In the following sections, you'll walk through each key page on the Edge Impulse |
48 | 49 |  |
49 | 50 |
|
50 | 51 |
|
51 | | -### Step 1: Create a New Project |
| 52 | +### Create a new project |
| 53 | + |
| 54 | +After you create your account and log in, the first step is to create a new project. Give your project a name that clearly reflects its purpose. This helps with easy identification, especially if you plan to build multiple models. |
| 55 | + |
| 56 | +For example, if you're building a keyword spotting model, you might name it `Wake word detection`. |
52 | 57 |
|
53 | | -Once you’ve created your account and logged in, the first step is to **create a new project**. Give your project a name that clearly reflects its purpose—this helps with easy identification, especially if you plan to build multiple models later on. For example, if you're building a keyword spotting model, you might name it "Wake Word Detection". You’ll also need to select the appropriate **project type** and **project setting**, as shown in the snapshot below. |
| 58 | +You'll also need to select the appropriate **project type** and **project settings**, as shown in the snapshot below. |
54 | 59 |
|
55 | | - |
| 60 | + |
56 | 61 |
|
57 | | -### Step 2: Configure the Target Device |
| 62 | +### Configure the target device |
58 | 63 |
|
59 | | -After creating your project, the next step is to **configure the target device**. Since you are using the **Arduino Nano RP2040 Connect**, click the highlighted button to begin device configuration, as shown in the snapshot below. This ensures that the data collection, model training, and deployment steps are optimized for your specific hardware. |
| 64 | +After creating your project, the next step is to configure the target device. Since you're using the **Arduino Nano RP2040 Connect**, click the highlighted button to begin the configuration process, as shown in the snapshot below. This ensures that data collection, model training, and deployment are optimized for your hardware. |
60 | 65 |
|
61 | | -The specifications of the Arduino Nano RP2040 Connect board can be found on [Arduino’s official page](https://store.arduino.cc/products/arduino-nano-rp2040-connect). |
| 66 | +You can find the full specifications for the Arduino Nano RP2040 Connect on [Arduino’s official product page](https://store.arduino.cc/products/arduino-nano-rp2040-connect). |
62 | 67 |
|
63 | | -Follow the exact settings in the attached snapshot to complete the configuration. |
| 68 | +Follow the settings shown in the screenshot to complete the configuration. |
64 | 69 |
|
65 | | - |
| 70 | + |
66 | 71 |
|
67 | | -### Step 3: Add the Dataset |
68 | 72 |
|
69 | | -With your device configured, the next step is to **add your dataset** to the project. Click on the **"Add existing data"** button and follow the configuration settings shown in the attached snapshot. This allows you to upload pre-recorded data instead of collecting it live, which can save time during the development phase. |
| 73 | +### Add the dataset |
70 | 74 |
|
71 | | -An **example repository** has been set up with some assets to be used throughout this Learning Path. You can clone it with the following command: |
| 75 | +With your device configured, the next step is to add your dataset to the project. Click **Add existing data** and follow the configuration settings shown in the screenshot. This lets you upload pre-recorded data instead of collecting it live, which can save time during development. |
| 76 | + |
| 77 | +An example repository has been prepared with assets used throughout this Learning Path. You can clone it with the following command: |
72 | 78 |
|
73 | 79 | ```bash |
74 | 80 | git clone https://github.com/e-dudzi/Learning-Path.git |
75 | 81 | ``` |
76 | 82 |
|
77 | | -The repository contains a `Dataset.zip` file containing the dataset used in the project. Extract it on your local machine. For convenience, the dataset has already been split into **training** and **testing**. |
| 83 | +The repository contains a `Dataset.zip` file with the dataset used in this project. Extract the contents to your local machine. For convenience, the dataset is already split into **training** and **testing** sets. |
| 84 | + |
| 85 | + |
78 | 86 |
|
79 | | - |
80 | 87 |
|
81 | 88 | {{% notice Note %}} |
82 | | -Do **not** check the **Green** highlighted area during upload. The dataset already includes metadata. Enabling that option may result in **much slower upload times** and is unnecessary for this project. |
| 89 | +Do not check the green highlighted area during upload. The dataset already includes metadata. Enabling that option may result in much slower upload times and is unnecessary for this project. |
83 | 90 | {{% /notice %}} |
84 | 91 |
|
85 | | - |
| 92 | + |
| 93 | + |
| 94 | +### Dataset uploaded successfully |
86 | 95 |
|
87 | | -### Dataset Uploaded Successfully |
| 96 | +After the dataset is uploaded, you'll see the samples listed in the **Data acquisition** tab, organized by their labels. You can click each sample to inspect the raw signal, view metadata, and even listen to the audio recordings directly within the Edge Impulse interface. This helps confirm that the uploaded data is accurate and ready for training. |
88 | 97 |
|
89 | | -This is what you should see after the dataset has been successfully uploaded. The data samples will appear in the **Data acquisition** tab, categorized by their respective labels. You can click on each sample to inspect the raw signal, view metadata, and even **listen to the audio recordings** directly within the Edge Impulse interface. This helps verify that the uploaded data is accurate and usable for training. |
90 | 98 |
|
91 | 99 | {{% notice Note %}} |
92 | | -This dataset is made up of **four labels**: `on`, `off`, `noise`, and `unknown`. |
| 100 | +This dataset is made up of four labels: |
| 101 | +- on |
| 102 | +- off |
| 103 | +- noise |
| 104 | +- unknown |
93 | 105 | {{% /notice %}} |
94 | 106 |
|
95 | | - |
| 107 | + |
96 | 108 |
|
97 | | -### Step 4: Create the Impulse |
| 109 | +### Create the impulse |
98 | 110 |
|
99 | | -Now that your data is ready, it's time to create the **impulse**, which defines the flow of data from input to output through processing blocks. Click on the **"Create Impulse"** button in the menu and configure it exactly as shown in the snapshot below. This typically includes setting the input data type (e.g., audio), adding a **processing block** (such as MFCC for audio), and a **learning block** (such as a neural network classifier). |
| 111 | +Now that your data is ready, it's time to create the impulse. An impulse defines the flow of data from input to output using processing and learning blocks. |
| 112 | + |
| 113 | +Click **Create impulse** in the menu and configure it as shown in the screenshot. Typically, this includes setting the input data type (such as audio), adding a **processing block** (like MFCC), and a **learning block** (such as a neural network classifier). |
| 114 | + |
| 115 | +After configuring the impulse, make sure to **save your changes**. |
100 | 116 |
|
101 | | -After configuring everything, **don’t forget to save your impulse**. |
102 | 117 |
|
103 | 118 |  |
104 | 119 |
|
105 | | -### Step 5: Configure the MFCC Block |
| 120 | +### Configure the MFCC block |
106 | 121 |
|
107 | | -Next, you'll configure the **MFCC (Mel Frequency Cepstral Coefficients)** processing block, which transforms the raw audio data into features suitable for model training. Click on **"MFCC"** in the left-hand menu under the **"Impulse Design"** section. |
| 122 | +Next, you'll configure the **MFCC (Mel Frequency Cepstral Coefficients)** processing block. This block transforms raw audio into features suitable for training your model. |
108 | 123 |
|
109 | | -Set the parameters exactly as shown in the snapshot below. These settings determine how the audio input is broken down and analyzed. Once you're done, be sure to **save the parameters**. These parameters are chosen for this path. Modifications can be made once you are familiar with Edge Impulse. |
| 124 | +Click **MFCC** in the left-hand menu under the **Impulse design** section. |
110 | 125 |
|
111 | | - |
| 126 | +Set the parameters exactly as shown in the screenshot. These settings determine how the audio input is segmented and analyzed. Once complete, make sure to **save the parameters**. |
112 | 127 |
|
113 | | -{{% notice Note %}} |
114 | | -The **green highlighted section** on the MFCC configuration page gives an estimate of how the model will perform **on the target device**. This includes information like memory usage (RAM/Flash) and latency, helping you ensure the model fits within the constraints of your hardware. |
115 | | -{{% /notice %}} |
| 128 | +These defaults are chosen for this Learning Path, but you can experiment with different values once you're more familiar with Edge Impulse. |
116 | 129 |
|
117 | | -### Step 6: Generate Features |
| 130 | + |
118 | 131 |
|
119 | | -After saving the MFCC parameters, the next step is to generate features from your dataset. Click on the **"Generate features"** button highlighted. Edge Impulse will process all your data samples using the MFCC configuration and create a set of features suitable for training a machine learning model. |
| 132 | +{{< notice Note >}} |
| 133 | +The green-highlighted section on the MFCC configuration page provides an estimate of how the model will perform on the target device. This includes memory usage (RAM and flash) and latency, helping ensure the model fits within hardware constraints. |
| 134 | +{{< /notice >}} |
120 | 135 |
|
121 | | -Once the feature generation is complete, you'll see a **2D visualization plot** that shows how the dataset is distributed across the four labels: `on`, `off`, `noise`, and `unknown`. This helps to visually confirm whether the different classes are well-separated and learnable by the model. |
| 136 | +### Generate features |
122 | 137 |
|
123 | | - |
| 138 | +After saving the MFCC parameters, the next step is to generate features from your dataset. Click **Generate features** to begin. Edge Impulse will process your data using the MFCC configuration and create a feature set for training. |
124 | 139 |
|
125 | | -### Step 7: Setting Up the Classifier |
| 140 | +When complete, you'll see a **2D feature plot** that shows how the data is distributed across the four labels: `on`, `off`, `noise`, and `unknown`. This helps visually confirm whether the classes are distinct and learnable. |
126 | 141 |
|
127 | | -Now it's time to configure the **neural network classifier**, which will learn to recognize the different audio commands. Click on the **"Classifier"** button in the left-hand menu under **Impulse Design** and set the parameters exactly as shown in the snapshot below. |
| 142 | + |
128 | 143 |
|
129 | | -{{% notice Note %}} |
130 | | -For this learning path, a learning rate of `0.002` was chosen, although the snapshot shows a value of `0.005`. You are free to experiment with different values to improve model accuracy. However, using `0.002` is recommended as a good starting point. |
131 | | -{{% /notice %}} |
| 144 | +### Set up the classifier |
| 145 | + |
| 146 | +Now it's time to configure the **neural network classifier**, which learns to recognize different audio commands. Click **Classifier** under **Impulse design** and set the parameters as shown in the screenshot. |
| 147 | + |
| 148 | +{{< notice Note >}} |
| 149 | +For this Learning Path, use a learning rate of `0.002` even though the screenshot shows `0.005`. You can experiment later, but `0.002` is a good starting point. |
| 150 | +{{< /notice >}} |
| 151 | + |
| 152 | +Once all parameters are set, click **Save and train** to begin training your model. |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +### Review model performance |
132 | 157 |
|
133 | | -Once all the parameters are set, click on **"Save and train"** to start training your model. |
| 158 | +After training is complete, Edge Impulse will show the model’s performance metrics: **accuracy**, **loss**, and a **confusion matrix**. |
134 | 159 |
|
135 | | - |
| 160 | + |
136 | 161 |
|
137 | | -### Step 8: Reviewing Model Performance |
| 162 | +- **Accuracy**: how often the model correctly predicts labels |
| 163 | +- **Loss**: how far off predictions are — lower values indicate better performance |
| 164 | +- **Confusion matrix**: shows how well the model classified each label and where errors occurred |
138 | 165 |
|
139 | | -After the training process is complete, Edge Impulse will display the **model's performance**, including its overall **accuracy**, **loss**, and a **confusion matrix**. |
| 166 | +Review these results to see how well the model learned. If needed, adjust settings or retrain. |
140 | 167 |
|
141 | | - |
| 168 | +**On-device performance (EON Compiler - RAM optimized):** |
142 | 169 |
|
143 | | -- **Accuracy** reflects how often the model predicts the correct label. |
144 | | -- **Loss** indicates how far the model’s predictions are from the actual labels during training — a lower loss generally means better performance. |
145 | | -- The **confusion matrix** shows how well the model predicted each of the four labels (`on`, `off`, `noise`, `unknown`), and can help identify patterns of misclassification. |
| 170 | +| Metric | Value | |
| 171 | +|------------------|---------| |
| 172 | +| Inference time | 6 ms | |
| 173 | +| Peak RAM usage | 12.5 KB | |
| 174 | +| Flash usage | 49.7 KB | |
146 | 175 |
|
147 | | -Review these metrics to determine if the model is learning effectively. If needed, adjust the model parameters or revisit earlier steps to improve performance. |
| 176 | + |
148 | 177 |
|
149 | | -**On-Device Performance (EON Compiler - RAM Optimized):** |
| 178 | +You can also use the pre-trained model found in `ei-edge-ai-tutorials-arduino-1.0.1.zip` from the example repository. |
150 | 179 |
|
151 | | -| Metric | Value | |
152 | | -|--------------------|-----------| |
153 | | -| Inference Time | 6 ms | |
154 | | -| Peak RAM Usage | 12.5 KB | |
155 | | -| Flash Usage | 49.7 KB | |
| 180 | +### Deploy the model |
156 | 181 |
|
157 | | - |
| 182 | +To run the trained model on your Arduino Nano RP2040 Connect, export it as an Arduino library: |
158 | 183 |
|
159 | | -You can also use the pre-trained model in the `ei-edge-ai-tutorials-arduino-1.0.1.zip` archive, from the example repository. |
| 184 | +1. Click **Deployment** in the left menu |
| 185 | +2. Search for **Arduino** and select **Arduino library** |
| 186 | +3. If the export doesn't start automatically, click **Build** |
160 | 187 |
|
161 | | -### Final Step: Deploying the Model |
| 188 | +The model will be downloaded as a `.zip` file you can import into the Arduino IDE. |
162 | 189 |
|
163 | | -To use the trained model on your Arduino Nano RP2040, follow the steps below to export it as an Arduino library. |
| 190 | + |
164 | 191 |
|
165 | | -1. Click on the **Deployment** tab from the menu. |
166 | | -2. In the **search bar**, type **"Arduino"** to filter the export options. |
167 | | -3. Select **Arduino library** from the list. |
168 | | -4. If the export process does not start automatically, click **Build**. The model will be downloaded as a `.zip` file. |
| 192 | +## Next steps |
169 | 193 |
|
170 | | - |
| 194 | +In the next section, you'll move from model training to real-world deployment. Specifically, you will: |
171 | 195 |
|
172 | | -## Next Steps |
| 196 | +- Connect an **LED** to the **Arduino Nano RP2040** board |
| 197 | +- Set up the **Arduino IDE** for development |
| 198 | +- Deploy the trained model to recognize voice commands and control the LED |
173 | 199 |
|
174 | | -In the following steps, you will move from model training to real-world deployment. Specifically, you will: |
175 | 200 |
|
176 | | -- Connect an **LED** to the **Arduino Nano RP2040** board. |
177 | | -- Set up the **Arduino IDE** for development. |
178 | | -- Program the board and **deploy the trained model** to recognize voice commands which will be used to turn `ON` and `OFF` the LED |
|
0 commit comments