Skip to content

BillMousta/Detecting-and-Mitigating-Training-Anomalies-in-Deep-Neural-Networks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Detecting and Mitigating Training Anomalies in Deep Neural Networks

This repository provides a research-grade PyTorch framework for detecting and mitigating training anomalies in deep neural networks using gradient-based signals. The system monitors training dynamics through gradient deltas (∂L/∂z) and applies online anomaly detection to dynamically filter harmful samples during learning.

The codebase is designed for reproducible experimentation, large-scale dataset support, and extensibility to multiple anomaly types and learning scenarios.

Core Idea

Instead of detecting anomalies at the data or activation level, the framework operates in gradient space:

  • Extracts layer-wise gradient deltas during training
  • Models normal training dynamics using Autoencoders (AEs)
  • Detects deviations via reconstruction error
  • Applies adaptive thresholding
  • Filters anomalous samples online during training

This produces a closed-loop learning system:

Train → Extract Gradients → Model Normality → Detect Anomalies → Filter Data → Continue Training


Key Features

  • ✅ Gradient-based anomaly detection (δ = ∂L/∂z)
  • ✅ Online training-time filtering
  • ✅ Adaptive thresholding (percentile-based)
  • ✅ No clean subset assumption
  • ✅ Model-agnostic (ResNet, MobileNet, etc.)
  • ✅ Multi-dataset support
  • ✅ Multi-anomaly support
  • ✅ DDP / multi-GPU ready
  • ✅ Offline and online anomaly detection modes
  • ✅ Modular experiment pipeline

Supported Anomaly Types

The framework supports multiple training anomaly scenarios:

  • Label noise / label flipping
  • Occlusion-based corruption
  • Backdoor poisoning
  • Mixed anomalies
  • Synthetic noise injection
  • PGD-based adversarial poisoning

All anomalies are handled through a unified detection pipeline operating on training dynamics.


Project Structure

.
├── scripts/
│   ├── proposed_training.py      # Main training pipeline
│   └── ...
├── experiments/
│   ├── experiment.sh             # Automated sweeps
│   └── ...
├── data/
│   ├── data_extraction.py
│   └── ...
├── utils/
│   ├── net_utils.py
│   ├── utils.py
│   └── ...
├── train_ae.py                   # Autoencoder training
├── cold_start.py                 # Cold-start bootstrap AD
├── configs/
│   └── config.yaml
├── logs/                         # Generated results
└── README.md

Installation

1. Clone repository

git clone <repo-url>
cd Detecting-and-Mitigating-Training-Anomalies-in-Deep-Neural-Networks

2. Create environment

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

CUDA version is managed via PyTorch installation.


Data Layout

Expected data structure:

project_root/
└── data/
    └── <dataset_name>/
        └── <model_name>/
            ├── poison_dataset/
            └── normal_training/

Paths are resolved relative to project root.


Running Experiments

Single run

python scripts/proposed_training.py \
  --type_of_model resnet34 \
  --dataset_name CIFAR100 \
  --seed 5 \
  --num_anomalies 0.4 \
  --use_ad true \
  --percentile 85 \
  --epochs 300

Automated sweeps

bash experiments/experiment.sh

Main Configuration Options

Parameter Description
--use_ad Enable anomaly detection
--ad_method online / offline
--aggregation_layers Layers for delta extraction
--percentile Detection threshold percentile
--type_anomalies anomaly type
--num_anomalies anomaly ratio
--anomaly_detection_check AD frequency (epochs)
--epochs_ae AE retraining epochs

Detection Pipeline

  1. Train model
  2. Extract deltas (∂L/∂z)
  3. Train/update Autoencoders
  4. Compute reconstruction errors
  5. Adaptive thresholding
  6. Filter anomalous samples
  7. Rebuild clean training set
  8. Continue training

This loop runs throughout training.


Autoencoder Design

  • Layer-wise AEs
  • Sparse Autoencoders supported
  • Reconstruction-based detection
  • Sliding-window delta collection
  • Online retraining

Distributed Training

Supported via PyTorch DDP:

torchrun --nproc_per_node=2 scripts/proposed_training.py ...

Logging

Outputs:

  • TensorBoard logs
  • CSV metrics
  • Model checkpoints
  • AE checkpoints
  • Detection statistics

Directory structure:

logs/<dataset>/<model>/<experiment>/

Research Orientation

This repository is designed for:

  • Training dynamics analysis
  • Robust learning research
  • Data poisoning defense
  • Continual filtering systems
  • Adaptive training pipelines
  • Gradient-based monitoring

Acknowledgments

The work presented here is supported by the RoboSAPIENS project funded by the European Commission’s Horizon Europe programme under grant agreement number 101133807. This publication reflects the authors’ views only. The European Commission is not responsible for any use that may be made of the information it contains.

Funded by the European Union

Learn more about RoboSAPIENS.

RoboSAPIENS

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors