How jasonkyng/nagl works
NAGL is a PyTorch few-shot anomaly-detection research implementation. Its main workflow prepares benchmark data and metadata, samples query images with normal and abnormal reference shots, trains the NAGL model, then evaluates anomaly scores and segmentation results on target datasets. The model combines pretrained image features with normal- and abnormal-guided scoring; README documents RM/AFL as central capabilities. Source excerpts establish key training, sampling, detection, and metric interactions; some evaluation and preparation wiring is documented only at a higher level.
Main entry points: train.py Training entry · model.py NAGL model · detection.py Anomaly detection · dataset_preparation Dataset metadata
Components 17
Data preparation
- VisA conversion
dataset_preparation/convert_visa_to_mvtec.py - Dataset metadata
dataset_preparation - Few-shot episodes
utils/dataset.py
Model and training
- Training entry
train.py - NAGL model
models/model.py - Attention layers
models/attention_layer.py - Training losses
utils/loss.py
Evaluation
- Training metrics
utils/metrics.py - Testing entry
test.py - Anomaly detection
utils/detection.py - Image metrics
utils/post_eval.py - Segmentation metrics
utils/post_eval_process.py
Results
- Saved metrics
Other components
- Researcher
- Benchmark datasets
- DINOv2 backbone
- Pretrained model service
Connections 20
- Researcher → Training entry: configures training
README.md - Researcher → Testing entry: starts testing
README.md - Benchmark datasets → VisA conversion: provides VisA data
README.md - VisA conversion → Dataset metadata: reorganizes data
README.md - Benchmark datasets → Dataset metadata: provides benchmark data
README.md - Dataset metadata → Few-shot episodes: supplies meta.json
README.md - Few-shot episodes → Training entry: supplies episodes
train.py - Training entry → NAGL model: trains model
train.py - Training entry → Training metrics: updates metrics
train.py - Training entry → Training losses: combines losses
train.py - NAGL model → Attention layers: uses attention layers
models/model.py - NAGL model → Training losses: uses loss functions
models/model.py - NAGL model → DINOv2 backbone: extracts features
models/model.py - DINOv2 backbone → Pretrained model service: loads pretrained weights
- Testing entry → Anomaly detection: runs detection
- Anomaly detection → NAGL model: scores query images
utils/detection.py - Anomaly detection → Image metrics: evaluates predictions
utils/detection.py - Anomaly detection → Segmentation metrics: evaluates maps
- Image metrics → Saved metrics: writes metrics
utils/post_eval.py - Segmentation metrics → Saved metrics: produces scores