You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/04.pro/boards/portenta-x8/tutorials/16.edge-ai-docker-container/content.md
+41-36Lines changed: 41 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ The complete project files can be downloaded here:
79
79
80
80
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.
81
81
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.
83
83
84
84
IMAGE
85
85
@@ -156,9 +156,9 @@ The raw sensor data is preprocessed using digital signal processing (DSP) techni
156
156
157
157
### Data Acquisition
158
158
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.
160
160
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.
162
162
163
163
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.
164
164
@@ -168,7 +168,7 @@ Once enough labeled data is collected, it is split into training and testing dat
168
168
169
169
#### Capturing Flow Sensor Data on the Portenta X8
170
170
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.
172
172
173
173
The following Arduino sketch (`sensor-data-generation.ino`) configures the Portenta X8 to read and send flow rate values at one second intervals.
174
174
@@ -283,12 +283,14 @@ These extracted features form the input dataset used to train the machine learni
283
283
The *Impulse Design* in Edge Impulse structures the feature extraction pipeline, ensuring data is properly preprocessed before being passed to the learning model.
284
284
285
285
**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.
|**Zero-padding**| Enabled (Ensures consistency in data length) |
290
292
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:
The model's *quantized (int8) version* is used for deployment to optimize inference speed and reduce memory usage.
395
400
396
401
#### Performance Metrics
397
402
398
403
Once training is complete, the model's accuracy is evaluated using a confusion matrix and performance scores. The key results include:
399
404
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 |
405
412
406
413
The confusion matrix provides insights into model performance across different categories:
407
414
@@ -412,19 +419,18 @@ The confusion matrix provides insights into model performance across different c
412
419
413
420
#### Interpreting Training Results
414
421
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.
416
423
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.
418
425
419
-
Here, it is possible to look into following details:
426
+
Here, it is possible to look into the following details:
420
427
421
428
-**Hyperparameter tuning:** Adjust the learning rate and number of neurons to improve classification.
422
429
-**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.
424
430
425
431
Refining the model can improve classification accuracy and improve real-time flow anomaly detection.
426
432
427
-
### Deployment and Real-Time Inference
433
+
### Deployment and Onboard Inference
428
434
429
435
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.
430
436
@@ -464,7 +470,7 @@ For deployment on the Portenta X8, we use the provided container image, argument
464
470
465
471
The inference workflow consists of the following steps:
466
472
467
-
-**Sensor Data Acquisition:** The flow rate sensor measures real-time values.
473
+
-**Sensor Data Acquisition:** The flow rate sensor measures present values.
468
474
-**Feature Extraction:** DSP and spectral analysis are applied to structure data.
469
475
-**Model Prediction:** The trained model classifies the current flow condition.
470
476
-**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
495
501
496
502
-**Data Collection Layer:** The Portenta X8 reads flow sensor data, capturing variations in fluid movement.
497
503
-**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.
499
505
500
506
### Data Flow Overview
501
507
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)**.
503
509
504
510
***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/).***
505
511
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**.
509
513
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.
511
515
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:
513
517
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.
515
520
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.
517
522
518
523
## Running Flow Rate Inference with Docker
519
524
@@ -753,7 +758,7 @@ The system will now collect flow sensor data, process it with the Edge Impulse m
753
758
754
759
### Arduino Cloud Integration
755
760
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.
757
762
758
763
***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).***
759
764
@@ -901,7 +906,7 @@ The following command can be used to verify the inference engine is running:
901
906
docker compose logs -f -n 10
902
907
```
903
908
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.
905
910
906
911
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.
0 commit comments