Skip to content

Commit 28200f4

Browse files
committed
Application note content update
1 parent bfaf056 commit 28200f4

File tree

1 file changed

+41
-36
lines changed
  • content/hardware/04.pro/boards/portenta-x8/tutorials/16.edge-ai-docker-container

1 file changed

+41
-36
lines changed

content/hardware/04.pro/boards/portenta-x8/tutorials/16.edge-ai-docker-container/content.md

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The complete project files can be downloaded here:
7979

8080
Machine learning enables industrial systems to analyze sensor data, recognize patterns and make data-driven decisions. This application implements a machine learning model to classify flow patterns in real-time, detecting anomalies that may indicate leaks, blockages or irregular pressure fluctuations.
8181

82-
By leveraging Edge Impulse, the model is trained to distinguish between normal and abnormal flow conditions based on real-time sensor data, allowing for predictive maintenance and operational efficiency.
82+
By leveraging Edge Impulse, the model is trained to distinguish between normal and abnormal flow conditions based on present sensor data, allowing for predictive maintenance and operational efficiency.
8383

8484
IMAGE
8585

@@ -156,9 +156,9 @@ The raw sensor data is preprocessed using digital signal processing (DSP) techni
156156

157157
### Data Acquisition
158158

159-
Sensor data needs to be collected across different flow conditions to build a reliable machine learning model. This ensures that the model can accurately distinguish between normal and abnormal flow states based on real-time measurements.
159+
Sensor data needs to be collected across different flow conditions to build a reliable machine learning model. This ensures that the model can accurately distinguish between normal and abnormal flow states based on continuous measurements.
160160

161-
The flow sensor connected to the Portenta X8 captures flow rate readings and sends the data to Edge Impulse using the Edge Impulse Data Forwarder. This process allows real-time monitoring and labeling of flow patterns under different operating conditions.
161+
The flow sensor connected to the Portenta X8 captures flow rate readings and sends the data to Edge Impulse using the Edge Impulse Data Forwarder. This process allows active monitoring and labeling of flow patterns under different operating conditions.
162162

163163
To collect training data, the Portenta X8 (or compatible Portenta family) continuously measures the real-time flow rate (L/min) from the sensor. It streams it to Edge Impulse via the Data Forwarder.
164164

@@ -168,7 +168,7 @@ Once enough labeled data is collected, it is split into training and testing dat
168168

169169
#### Capturing Flow Sensor Data on the Portenta X8
170170

171-
The Portenta X8’s M4 microcontroller reads real-time flow sensor data and transmits it via serial output in CSV format, making it compatible with Edge Impulse for model training.
171+
The Portenta X8’s M4 microcontroller reads flow sensor data and sends it via serial output in CSV format, making it compatible with Edge Impulse for model training.
172172

173173
The following Arduino sketch (`sensor-data-generation.ino`) configures the Portenta X8 to read and send flow rate values at one second intervals.
174174

@@ -283,12 +283,14 @@ These extracted features form the input dataset used to train the machine learni
283283
The *Impulse Design* in Edge Impulse structures the feature extraction pipeline, ensuring data is properly preprocessed before being passed to the learning model.
284284

285285
**Time-Series Data Block:**
286-
- Window size: 10,000 ms (10 seconds)
287-
- Window increase (stride): 1,000 ms (1 second)
288-
- Frequency: 1 Hz
289-
- Zero-padding enabled: Ensures consistency in data length.
286+
| **Parameter** | **Value** |
287+
|---------------------|----------------------------------------------|
288+
| **Window size** | 10,000 ms (10 seconds) |
289+
| **Window increase** | 1,000 ms (1 second) |
290+
| **Frequency** | 1 Hz |
291+
| **Zero-padding** | Enabled (Ensures consistency in data length) |
290292

291-
This configuration allows real-time flow rate sampling at one second intervals, providing a detailed view of flow dynamics. The following image shows how the flow rate input is structured before processing:
293+
This configuration allows flow rate sampling at one second intervals, providing a detailed view of flow dynamics. The following image shows how the flow rate input is structured before processing:
292294

293295
![Impulse Creation](assets/edge-impulse-impulse-creation.png)
294296

@@ -385,23 +387,28 @@ The network uses *ReLU activation functions* in hidden layers and *Softmax activ
385387

386388
The Neural Network Training Configuration is as follows:
387389

388-
- **Training cycles:** 150
389-
- **Learning rate:** 0.0005
390-
- **Processor:** CPU-based training
391-
- **Validation set size:** 30% of the dataset
392-
- **Batch size:** 32 (not enabled in this run)
390+
| **Parameter** | **Value** |
391+
|-------------------------|------------------------------|
392+
| **Training cycles** | 150 |
393+
| **Learning rate** | 0.0005 |
394+
| **Processor** | CPU based training |
395+
| **Validation set size** | 30% of the dataset |
396+
| **Batch size** | 32 (not enabled in this run) |
397+
393398

394399
The model's *quantized (int8) version* is used for deployment to optimize inference speed and reduce memory usage.
395400

396401
#### Performance Metrics
397402

398403
Once training is complete, the model's accuracy is evaluated using a confusion matrix and performance scores. The key results include:
399404

400-
- **Overall Model Accuracy:** 73.3%
401-
- **Weighted Average Precision:** 0.87
402-
- **Weighted Average Recall:** 0.73
403-
- **Weighted Average F1 Score:** 0.77
404-
- **Area Under ROC Curve (AUC):** 0.86
405+
| **Metric** | **Value** |
406+
|--------------------------------|-----------|
407+
| **Overall Model Accuracy** | 73.3% |
408+
| **Weighted Average Precision** | 0.87 |
409+
| **Weighted Average Recall** | 0.73 |
410+
| **Weighted Average F1 Score** | 0.77 |
411+
| **Area Under ROC Curve (AUC)** | 0.86 |
405412

406413
The confusion matrix provides insights into model performance across different categories:
407414

@@ -412,19 +419,18 @@ The confusion matrix provides insights into model performance across different c
412419

413420
#### Interpreting Training Results
414421

415-
The trained model successfully detects high flow and anomalous conditions, achieving comforting accuracy in these categories. Additionally, the quantized model maintains a balance between accuracy and computational efficiency, making it appropriate for embedded deployment on the Portenta X8. The model is capable to reduce false positives with a precision score of 0.87, allowing reliable anomaly detection.
422+
The trained model is capable of detecting high flow and anomalous conditions, performing accurate recognition in these categories. Additionally, the quantized model keeps a balance between accuracy and computational efficiency, making it appropriate for embedded deployment on the Portenta X8. The model is capable of reducing false positives with a precision score of 0.87, allowing reliable anomaly detection.
416423

417-
However, low flow conditions present the most significant challenge, with the highest misclassification rate. The model occasionally misclassifies low flow as normal, indicating difficulty distinguishing borderline cases. To address this, additional training cycles, adjustments in feature selection and further data augmentation may be required to improve recall. Integrating feature scaling techniques could also help refine classification accuracy, particularly for subtle variations in flow conditions.
424+
However, low flow conditions present the most significant challenge, with the highest misclassification rate. The model occasionally misclassifies low flow as normal, indicating difficulty distinguishing borderline cases. To address this, additional training cycles, adjustments in feature selection and further data augmentation may be required to improve recognition. Integrating feature scaling techniques could also help refine classification accuracy, particularly for subtle variations in flow conditions.
418425

419-
Here, it is possible to look into following details:
426+
Here, it is possible to look into the following details:
420427

421428
- **Hyperparameter tuning:** Adjust the learning rate and number of neurons to improve classification.
422429
- **Data balancing:** Ensure equal representation of all flow conditions to reduce bias.
423-
- **Edge deployment:** Convert the trained model for real-time inference on the Portenta X8.
424430

425431
Refining the model can improve classification accuracy and improve real-time flow anomaly detection.
426432

427-
### Deployment and Real-Time Inference
433+
### Deployment and Onboard Inference
428434

429435
Once trained, the machine learning model will be used to deploy to the Portenta X8 inside a Docker container, allowing real-time inference directly at the edge. Instead of pulling the container directly, we will use the container image, arguments and ports provided by Edge Impulse to build a custom Docker container for the Portenta X8.
430436

@@ -464,7 +470,7 @@ For deployment on the Portenta X8, we use the provided container image, argument
464470

465471
The inference workflow consists of the following steps:
466472

467-
- **Sensor Data Acquisition:** The flow rate sensor measures real-time values.
473+
- **Sensor Data Acquisition:** The flow rate sensor measures present values.
468474
- **Feature Extraction:** DSP and spectral analysis are applied to structure data.
469475
- **Model Prediction:** The trained model classifies the current flow condition.
470476
- **Response Actions:** If an anomaly is detected, the system takes corresponding action.
@@ -495,25 +501,24 @@ The flow anomaly detection system has real-time sensor data acquisition, machine
495501

496502
- **Data Collection Layer:** The Portenta X8 reads flow sensor data, capturing variations in fluid movement.
497503
- **Processing & Inference Layer:** The Edge Impulse trained model runs inside a Docker container on the Portenta X8, classifying flow patterns and detecting anomalies.
498-
- **Cloud & Visualization Layer:** The system forwards classification results to Arduino Cloud, allowing remote monitoring, notifications and real-time dashboards.
504+
- **Cloud & Visualization Layer:** The system forwards classification results to Arduino Cloud, allowing remote monitoring with visualized information.
499505

500506
### Data Flow Overview
501507

502-
The flow sensor measures fluid movement and sends data to the Portenta X8. The M4 core collects and processes this data before making it accessible to the Linux side of the Portenta X8 using **Remote Procedure Call (RPC)**.
508+
The flow sensor will measure fluid movement continuously and send data to the Portenta X8’s M4 core. The M4 core processes this data and makes it accessible to the Linux layer using **Remote Procedure Call (RPC)**.
503509

504510
***For more details about Remote Procedure Call (RPC) and its implementation, refer to the [dedicated tutorial](https://docs.arduino.cc/tutorials/portenta-x8/python-arduino-data-exchange/).***
505511

506-
A Python script on the Linux side receives flow data from the M4 core. It sends to the Edge Impulse inference model, which runs inside the Docker container. The model classifies the flow condition as **Normal, Low, High, or Anomalous**.
507-
508-
The system logs an alert and records the classification results if an anomaly is detected. The data is stored locally on the Portenta X8 and sent to Arduino Cloud for visualization and anomaly tracking. This combined edge cloud processing approach allows real-time response while allowing for historical analysis and remote monitoring.
512+
A Python script on the Linux side receives sensor data from the M4 core. It forwards it to the Edge Impulse inference model, which runs inside a Docker container. The model classifies the flow condition as **Normal, Low, High or Anomalous**.
509513

510-
### Edge AI and Cloud Integration for Flow Monitoring
514+
The system logs an alert and records classification results if an anomaly is detected. These results are stored locally for quick decision making and sent to Arduino Cloud for remote monitoring, historical analysis and anomaly tracking.
511515

512-
The Portenta X8 performs onboard inference on the device, providing low-latency anomaly detection and reducing dependency on cloud connectivity. The system reduces bandwidth usage by processing data locally, as only classification results are sent instead of raw sensor data. This allows for quick responses to anomalies, making it ideal for applications requiring real-time monitoring.
516+
This integration optimizes performance by balancing edge processing with cloud integration:
513517

514-
While edge processing ensures fast decision-making, Arduino Cloud can help extend the system capabilities by allowing long-term data storage, historical trend analysis and alert triggering. Classification results are saved in the cloud, allowing for predictive maintenance and anomaly tracking over time.
518+
- **Onboard Inference:** The Portenta X8 processes sensor data locally, working on low-latency anomaly detection while reducing bandwidth usage.
519+
- **Cloud Based Monitoring:** Arduino Cloud stores classification results, enabling long-term data tracking, predictive maintenance and real-time alerts if configured.
515520

516-
This integration provides benefits of edge inference and cloud based monitoring, providing both on-time detection of irregularities and long-term system analysis for optimized performance and maintenance planning.
521+
The system performs on demand anomaly detection by combining active edge inference with cloud analytics while providing historical insights for predictive maintenance and system optimization.
517522

518523
## Running Flow Rate Inference with Docker
519524

@@ -753,7 +758,7 @@ The system will now collect flow sensor data, process it with the Edge Impulse m
753758

754759
### Arduino Cloud Integration
755760

756-
Now that the Portenta X8 is running the Docker container with the trained inference model, the next step is integrating Arduino Cloud for real-time monitoring and logging of anomaly detection results.
761+
Now that the Portenta X8 is running the Docker container with the trained inference model, the next step is integrating Arduino Cloud for active monitoring and logging of anomaly detection results.
757762

758763
***To register and configure the Portenta X8 with Arduino Cloud, please refer to [this user manual section](https://docs.arduino.cc/tutorials/portenta-x8/user-manual/#portenta-x8-with-arduino-cloud).***
759764

@@ -901,7 +906,7 @@ The following command can be used to verify the inference engine is running:
901906
docker compose logs -f -n 10
902907
```
903908

904-
Once deployed, the system will begin to get flow sensor data, classify it using the trained model and send the results to Arduino Cloud for real-time monitoring and anomaly tracking.
909+
Once deployed, the system will begin to get flow sensor data, classify it using the trained model and send the results to Arduino Cloud for monitoring and anomaly tracking.
905910

906911
This integration allows real-time anomaly detection and cloud-based monitoring, combining edge inference on Portenta X8 with Arduino Cloud analytics. Users can remotely track flow rate anomalies, set up alerts and analyze historical trends to improve predictive maintenance of the system's point of interest.
907912

0 commit comments

Comments
 (0)