NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Memory Defense: More Robust Classification via a Memory-Masking Autoencoder

Eashan Adhikarla, Dan Luo, Brian D. DavisonarXiv 2022

Abstract

Many deep neural networks are susceptible to minute perturbations of images that have been carefully crafted to cause misclassification. Ideally, a robust classifier would be immune to small variations in input images, and a number of defensive approaches have been created as a result. One method would be to discern a latent representation which could ignore small changes to the input. However, typical autoencoders easily mingle inter-class latent representations when there are strong similarities between classes, making it harder for a decoder to accurately project the image back to the original high-dimensional space. We propose a novel framework, Memory Defense, an augmented classifier with a memory-masking autoencoder to counter this challenge. By masking other classes, the autoencoder learns class-specific independent latent representations. We test the model's robustness against four widely used attacks. Experiments on the Fashion-MNIST & CIFAR-10 datasets demonstrate the superiority of our model. We make available our source code at GitHub repository: https://github.com/eashanadhikarla/MemDefense

Introduction

Deep Neural Networks (DNNs) are notoriously fragile. A "carefully crafted" but nearly invisible change to an image—known as an adversarial perturbation—can trick a state-of-the-art model into misclassifying a "coat" as a "sandal." While researchers have tried using autoencoders to "denoise" these images, standard autoencoders often struggle with "inter-class mingling." In other words, the latent representations of different classes get tangled together in the model's internal feature space. If a model cannot clearly separate the concept of a "coat" from a "shirt," it cannot effectively reconstruct an image that has been strategically corrupted to look like something else.

The Memory Defense Framework

The proposed Memory Defense is a multi-stage pipeline designed to disentangle these representations. The system consists of three main components:

  1. Memory Selector (Classifier-A): A pre-trained classifier (e.g., ResNet-50) that takes the initial input and predicts its class. This prediction acts as a "gatekeeper" for the subsequent reconstruction.
  2. Memory-Masking Autoencoder: This core innovation includes an Encoder that compresses the input into a latent vector, a Memory Module storing prototypical features for every class, and a Masking Mechanism. Based on the prediction from Classifier-A, the model masks all memory slots except those belonging to the predicted class. This forces the Decoder to reconstruct the image using only the "clean" features associated with that specific class.
  3. Target Classifier (Classifier-B): This final model receives the "cleaned" reconstruction and provides the final classification.
Figure 2: Detailed architecture of the Memory Defense framework, illustrating the flow from input image through the memory-masking attention mechanism to the final classification.

To further reduce noise, a "hard-shrink" operation is applied to the attention weights, keeping only the most significant memory features. The model is trained using a Dual Loss Function that minimizes reconstruction error for the target class while actively penalizing the use of features from non-target classes.

Latent Space Disentanglement

A key insight of this work is that class-specific reconstruction prevents adversarial noise from "bleeding" into the output. By masking out "foreign" class features, the model essentially filters the input through a class-specific lens. The effectiveness of this approach is visible in the latent space.

Figure 3: t-SNE visualizations comparing standard latent representations (a) vs. the proposed memory-masking approach (b).

As shown in Figure 3, the memory module creates much tighter, more distinct clusters for each class compared to a standard encoder. This disentanglement is critical for robustness, as it prevents small perturbations from pushing a sample into the latent territory of another class.

Experimental Results

Memory Defense was evaluated on the Fashion-MNIST and CIFAR-10 datasets against four major adversarial attacks: FGSM, BIM, PGD, and CW.

  • Fashion-MNIST: The model maintained approximately 90% accuracy across all attack types. In contrast, existing defenses like ComDefend saw accuracy drops to 70% under certain BIM attack settings.
  • CIFAR-10: The framework achieved 86-89% accuracy against all attacks, significantly outperforming standard ResNet-50 models trained with PGD adversarial training.
  • Efficiency: The memory module adds negligible overhead, approximately 0.004 seconds per batch of 10 images, making it suitable for real-time applications.

Discussion and Limitations

While Memory Defense shows significant promise, it faces a "Selector" bottleneck: if the initial Memory Selector (Classifier-A) is successfully fooled into picking the wrong class, the masking mechanism will force an incorrect reconstruction. Furthermore, scaling this approach to high-resolution datasets like ImageNet remains a challenge due to the memory requirements for storing class prototypes. Future work will explore joint training strategies to generate robust predictions and attack-detection flags simultaneously.

Summary updated

BibTeX
@misc{adhikarla2022memory,
  author = {Eashan Adhikarla and Dan Luo and Brian D. Davison},
  title = {{Memory Defense: More Robust Classification via a Memory-Masking Autoencoder}},
  year = {2022},
  eprint = {2202.02595},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2202.02595},
}
Figure