Abstract
Anomalies are ubiquitous in all scientific fields and can express an unexpected event due to incomplete knowledge about the data distribution or an unknown process that suddenly comes into play and distorts observations. Due to such events' rarity, to train deep learning models on the Anomaly Detection (AD) task, scientists only rely on "normal" data, i.e., non-anomalous samples. Thus, letting the neural network infer the distribution beneath the input data. In such a context, we propose a novel framework, named Multi-layer One-Class ClassificAtion (MOCCA), to train and test deep learning models on the AD task. Specifically, we applied it to autoencoders. A key novelty in our work stems from the explicit optimization of intermediate representations for the AD task. Indeed, differently from commonly used approaches that consider a neural network as a single computational block, i.e., using the output of the last layer only, MOCCA explicitly leverages the multi-layer structure of deep architectures. Each layer's feature space is optimized for AD during training, while in the test phase, the deep representations extracted from the trained layers are combined to detect anomalies. With MOCCA, we split the training process into two steps. First, the autoencoder is trained on the reconstruction task only. Then, we only retain the encoder tasked with minimizing the $L_2$ distance between the output representation and a reference point, the anomaly-free training data centroid, at each considered layer. Subsequently, we combine the deep features extracted at the various trained layers of the encoder model to detect anomalies at inference time. To assess the performance of the models trained with MOCCA, we conduct extensive experiments on publicly available datasets. We show that our proposed method reaches comparable or superior performance to state-of-the-art approaches available in the literature.
Introduction
Anomaly Detection (AD) is a critical task across various scientific domains, focused on identifying rare events that deviate from expected data distributions. Because anomalies are unpredictable and infrequent, researchers typically rely on One-Class Classification (OCC), training models exclusively on "normal" data.
Most current deep learning approaches treat a neural network as a single "holistic" block, making decisions based only on the final output layer. However, intermediate layers capture a hierarchy of features—from simple edges to complex semantic parts—that provide a richer definition of normality. MOCCA (Multi-layer One-Class ClassificAtion) addresses this by explicitly optimizing and combining multi-depth representations.
Methodology
MOCCA leverages the multi-layer structure of deep architectures to improve detection accuracy. Instead of relying on a single representation, it evaluates an input's distance from "normal" centroids across multiple layers of an encoder.
Training Process
The framework adapts its training strategy based on the data type:
- Single Images: Training is split into two stages. First, a standard autoencoder is pre-trained on the reconstruction task using anomaly-free images. Second, the decoder is discarded, and the encoder is specialized for AD. Small "selector" modules process intermediate features, and the model is fine-tuned to minimize the $L_2$ distance between these features and layer-specific centroids.
- Video Data: To capture temporal correlations, selectors are replaced with LSTM cells. This allows for a single-step, end-to-end training process suitable for complex video sequences.
Experimental Results
MOCCA was evaluated on three major benchmarks: CIFAR10, MVTec AD (industrial inspection), and ShanghaiTech (video anomalies).
Key findings include:
- Superior Performance: On MVTec AD, MOCCA achieved a mean max Balanced Accuracy (maxBA) of 0.83, a significant improvement over the previous state-of-the-art of 0.77. On CIFAR10, it reached an average AUC of 0.676, outperforming baselines like Deep SVDD.
- The Multi-Layer Advantage: Performance analysis confirms that incorporating intermediate layers (specifically layers 4 and 5) significantly boosts detection capabilities compared to using the final layer alone.
- Better Class Separation: The framework creates a sharper distinction between normal and anomalous samples. By pushing normal samples closer to zero distance across multiple layers, it reduces the overlap that often plagues holistic models.
Conclusion
MOCCA demonstrates that "normality" is a multi-scale concept. By moving beyond holistic network outputs and explicitly training intermediate layers for one-class classification, the framework achieves state-of-the-art results across diverse anomaly detection tasks. Future work will focus on automated layer selection and more sophisticated temporal modeling for video data.
Summary updated