Anomaly Detection

Classification asks "which of these known faults is it?". Anomaly detection asks a different and often more practical question: does this unit sound like a normal one? It is trained on normal samples only, so you can put it to work on a line where defects are rare, where nobody can list the failure modes in advance, or where the faults you will meet next month have not happened yet.

When to use anomaly detection

SituationClassificationAnomaly detection
Fault types are known and can be labelledPreferredPossible, but gives less information
Defective samples are very rareHard — too few examples to learn fromPreferred
Unknown or new failure modes must be caughtMisses anything not in the training setPreferred — flags anything unlike normal
You need to name the fault, not just detect itPreferredOnly reports "abnormal"
The two approaches combine well: anomaly detection screens every unit and pulls suspicious ones aside; a classifier then names the fault for those that already have known labels. As flagged anomalies accumulate and get diagnosed, they become the labelled data for a future classifier.

How it works — reconstruction error

An autoencoder is a network trained to compress a sound into a small internal representation and rebuild it again. Trained exclusively on normal recordings, it becomes very good at rebuilding normal sounds and stays clumsy at everything else. The mismatch between input and rebuild — the reconstruction error — is therefore small for normal units and large for abnormal ones.

MSE = (1/N) Σ ( xi − x̂i )2   →   anomaly if MSE > threshold

Because normal units are not all identical, their errors form a distribution rather than a single number. The threshold is placed on the upper tail of that distribution: everything to the right of it is reported as an anomaly.

Threshold mean + 3 × std of training errors Anomalies Normal samples Reconstruction error (MSE) Number of samples Only the teal distribution is seen during training — the red samples are what the model must catch

Training an autoencoder on normal samples only

Go to Step 2 — Train Model, choose Python (deep learning) and press Export Autoencoder Template. Point the script at a folder of normal recordings, set the output .onnx path and the number of epochs (100 is a reasonable starting point for an autoencoder), and start the run.

data\
  Normal\
    unit_0001.wav
    unit_0002.wav
    unit_0003.wav
    ...

Each recording is converted into a Mel spectrogram (64 Mel bands × 128 frames) which the network learns to reproduce. Because there is only one class, no labelling work is needed at all — collecting known-good units is the entire data preparation.

Every recording in the training folder is treated as normal. A single defective unit that slips into the folder teaches the model that its sound is acceptable, and similar defects will pass unnoticed afterwards. Verify the training set before you train, and re-verify it whenever you extend it.

The threshold and its metadata file

At the end of training the script measures the reconstruction error of every training sample and derives a threshold as mean + 3 × standard deviation. This is written next to the model as a small JSON file with the same name plus .meta.json:

{
  "threshold":  0.004120,
  "mean_error": 0.001850,
  "std_error":  0.000757,
  "n_samples":  240
}

When the model is loaded, this file is picked up automatically, so the detector arrives already calibrated to your line. Keep the two files together when you copy a model to another machine. The threshold can be adjusted afterwards to trade the two kinds of mistake against each other:

AdjustmentEffectChoose when
Lower threshold (e.g. mean + 2σ)Catches more defects, raises false alarmsAn escaped defect is expensive; re-checking is cheap
Default (mean + 3σ)Balanced starting pointFirst deployment, before real data is available
Higher threshold (e.g. mean + 4σ)Fewer false alarms, more escapesOperators are ignoring alarms because there are too many

Reading the result

Each analysed sample returns:

The z-score is the number to trend. A unit at z = 3.1 has barely crossed the line and is worth a listen; a unit at z = 15 is grossly different from anything seen in training. Plotting the z-score of every unit produced during a shift often reveals drift long before individual units start failing.

Alternative: statistical baseline anomaly score

A second, lighter-weight detector is available as a normal analysis in the Insert catalogue: AI Anomaly Score. It needs no neural network and no training run. Instead it computes a 14-dimensional feature vector per frame — eight time-domain descriptors (RMS, kurtosis, crest, shape, impulse and margin factors, energy entropy, zero-crossing rate) and six spectral ones (centroid, spread, flatness, crest, entropy, roll-off) — and measures how far each frame deviates from a baseline in units of standard deviation.

score(t) = √( meani [ ( xi(t) − μi ) / σi ]2 )

The scale is intuitive: a frame that matches the baseline exactly scores 0, and a frame that sits one standard deviation away in every feature scores exactly 1. The result is a score curve over time, with alarms where the threshold is exceeded, so you see when in the recording the abnormality occurs — not just whether it is present.

The baseline can come from three places, in order of precedence:

Baseline sourceMeaningUse for
Baseline statistics fileA saved baseline previously fitted on known-good unitsProduction screening against a fixed reference
First N seconds of the recordingThe start of the file defines "normal"Run-in monitoring, degradation during a test
Whole file (default)The recording is its own referenceFinding the relatively most unusual passage in one recording

A fitted baseline can be exported to a JSON file and re-loaded later, which is how you keep a whole test bench — or several benches — judging against the same reference. Frames are analysed with a 2048-point window, 1024-sample hop and a Hann window by default; the reported single value is the 95th percentile of the score curve, so a short transient does not dominate the summary.

A production line workflow

  1. Collect known-good recordings from a stable period of production — several dozen units at minimum, covering different shifts and operators.
  2. Train an autoencoder on them, or fit and export a statistical baseline.
  3. Run the held-back good units through the detector and confirm they all land below the threshold.
  4. Run whatever defective units you have; check that their errors sit clearly above it. Adjust the threshold if the two groups are not separated where you want them.
  5. Deploy: screen production with Batch Classify or the pipeline node, and export the results.
  6. Review the flagged units, record what was actually wrong, and use those recordings to build a classifier that can name the fault next time.
  7. Retrain the baseline after any deliberate process change — a new supplier, tooling or fixture shifts what "normal" sounds like.

Practical tips

Related: AI Acoustic Classification (overview) · Annotation & Training · ONNX Inference

© 2026 Deepsona. All Rights Reserved.