How gathierry/fastflow works
Project Type & Purpose
• This is a research-oriented machine-learning pipeline (not a web app or microservice).
• Purpose: train and evaluate the FastFlow 2D normalizing-flow model on MVTec-AD to detect anomalies.
Top-Level Components
a. External Data
• MVTec-AD dataset (local filesystem directory for train/test/ground_truth)
b. Configuration Manager
• configs/*.yaml + CLI flags in main.py
c. Data Ingestion & Preprocessing
• dataset.py defines PyTorch Dataset/Transforms
d. Model Definition
• fastflow.py implements the FastFlow architecture
e. Training & Evaluation Engine
• main.py orchestrates train vs. eval, loads config, instantiates model & data loader, loops epochs, computes losses, AUROC
f. Utilities & Constants
• utils.py: helper functions (logging, metrics, checkpoint naming)
• constants.py: shared constants (e.g., normalization stats)
g. Checkpoint & Logging Storage
• _fastflow_experiment_checkpoints/… for model .pt files and logs
Interactions & Data Flow
1. Startup: CLI (main.py) reads a YAML config from configs/ → passes hyperparameters.
2. Data Loader: Configuration → dataset.py builds PyTorch DataLoader → yields batches.
3. Model Instantiation: fastflow.py reads model-specific params from config → constructs flow layers.
4. Training Loop:
– Input batch → forward through FastFlow → compute anomaly score & loss → backward pass → optimizer step.
– Every N epochs: save checkpoint to filesystem.
5. Evaluation Mode (––eval flag): load checkpoint → run inference on test set → call utils.py to compute AUROC and localization maps.
6. Output: metrics printed to console and optionally saved.
Architectural Patterns & Principles
• Modular separation: config, data, model, training, utils
• Single entry point: main.py handles both train & eval modes
• Config-driven: YAML files drive hyperparameters, model selection (ResNet18, WideResNet, DeiT, CaiT)
• Reproducibility: checkpointing, seed control (via constants or utils)