7.9.30. Anomaly Detection Examples Overview
In 1.4.0 this page was a walkthrough of the DC arc fault anomaly detection example. In 1.5.0 the anomaly detection configs are part of several example folders, so this page is an overview that lists all of them and collects the common workflow: normal-only training, thresholds and how to read the outputs.
For a minimal first run use Generic Timeseries Anomaly Detection. For the theory and dataset format see Anomaly Detection and Anomaly Detection Dataset Format.
7.9.30.1. Anomaly Detection Configs in 1.5.0
All of them use task_type: generic_timeseries_anomalydetection and are run from the tinyml-modelzoo
folder with ./run_tinyml_modelzoo.sh examples/<folder>/<config>.yaml (Windows: see
Running Examples).
Config |
Device |
Model |
Page |
|---|---|---|---|
|
F29H85 |
|
|
|
F28P55 |
|
|
|
F28P55 |
|
|
|
F28P55 |
|
|
|
F28P55 |
|
|
|
MSPM0G5187 |
|
|
|
F28P55 |
|
|
|
F28P55 |
|
In the automated 1.5.0 config test run the generic config.yaml, the DC arc fault DSI config, the ECG,
fan blade and motor bearing (F28P55) configs completed. The DC arc fault DSK config stopped with a NaN/Inf
loss at epoch 0, the motor bearing MSPM0 config failed with a quantization scale/zero-point dimension error,
and the generic config_NPU.yaml failed with a CUDA device mismatch. Check the page of each example for
its status.
7.9.30.2. Workflow
The autoencoder is trained on the
Normalclass only. TheAnomalyclass is used for testing and threshold evaluation.After training, the mean and standard deviation of the reconstruction error on normal training data are computed and thresholds
threshold = mean_train + k * std_trainare generated for a range ofk.At inference time a window with a reconstruction error above the threshold is an anomaly.
A typical anomaly detection config (the DC arc fault DSK variant keeps the same structure) has these elements:
common:
task_type: generic_timeseries_anomalydetection
target_device: F28P55
dataset:
dataset_name: <name>
input_data_path: <zip url or path> # classes/Normal and classes/Anomaly
data_processing_feature_extraction:
data_proc_transforms: [...] # or feature_extraction_name: <preset>
variables: 1
training:
model_name: AD_17k
quantization: 1
output_int: false # must be false for anomaly detection
testing:
enable: True
compilation:
enable: True
7.9.30.3. Available Models
The anomaly detection models enabled in tinyml_modelzoo/model_descriptions/anomalydetection.py are:
AD_500_NPU, AD_1k, AD_2k_NPU, AD_4k, AD_6k_NPU, AD_8k_NPU, AD_10k_NPU,
AD_11k_NPU, AD_16k, AD_17k, AD_20k_NPU, AD_Linear and
Ondevice_Trainable_AD_Linear (used by the on-device learning example, see
On-Device Training Documentation). Models with the _NPU suffix are designed for devices with an NPU.
Start with a small model for simple, repetitive patterns and move to a larger one for complex signals.
7.9.30.4. Threshold Selection
Lower
kdetects more anomalies but raises more false alarms.Higher
kreduces false alarms but may miss subtle anomalies.threshold_performance.csvinpost_training_analysis/lists threshold, accuracy, precision, recall, F1 score and false positive rate for eachk. Pick the row that balances them for your application.reconstruction_error.pngandreconstruction_error_log_scale.pngin the same folder show the reconstruction error distributions of normal and anomaly data. Well separated distributions mean good detection capability; overlapping ones call for different features or a different model.
7.9.30.5. Anomaly Detection versus Classification
Aspect |
Classification |
Anomaly detection |
|---|---|---|
Training data |
All classes needed |
Normal data only |
Unknown faults |
Cannot be detected |
Detected as anomalies |
Fault identification |
Identifies the fault type |
Only flags abnormality |
7.9.30.6. Troubleshooting
High false positive rate: increase
k, or add more diverse normal training data.Missed anomalies: decrease
k, increase model size, or use features that expose the anomaly.Unstable reconstruction error: train longer, check preprocessing, and compare with the float model.