How junghwamin/nmfc-plan5-from-scratch-ablation works
Purpose and Entrypoints
This is a PyTorch NMFC ablation repo testing whether the shrb score/energy/reference-bank variant depends on ImageNet-pretrained features. It compares random-init ResNet-50 NMFC against softmax on closed-set CIFAR-100 and open-set 80/100 CIFAR-100.
Primary CLI entry point: python -m src.train --config ..., implemented in src/train.py. Main experiment specs are configs/cifar100_scratch.yaml and configs/cifar100_openset_scratch.yaml.
Experiment Orchestration
src/train.py owns runner dispatch, shared image training setup, two-phase optimization, reference-bank fitting, metric collection, and result persistence. run_image handles 100-class closed-set evaluation; run_openset reuses the same image core for train-on-80/evaluate-on-100.
The defining plan5 boundary is encoder initialization: _run_image_core passes config pretrained into ResNet50Encoder, defaulting to True for compatibility. Scratch configs set pretrained: false.
Paths: src/train.py, configs/cifar100_scratch.yaml, configs/cifar100_openset_scratch.yaml.
Data and Batch Construction
Image data flows through CIFAR-100 loading and resize/augmentation logic, then PK sampling for metric/energy-oriented batches. Open-set training filters the training split to 80 seen classes while retaining the full evaluation label space; this is the key train/evaluation distribution boundary.
Paths: src/datasets/image.py, src/datasets/samplers.py, configs/cifar100_openset_scratch.yaml.
Encoder and Method Assembly
ResNet50Encoder wraps torchvision ResNet-50, selecting ImageNet weights only when pretrained=True, replacing the classifier with a 128-dimensional embedding projection, and leaving embeddings unnormalized for Euclidean energy calculations.
src/variants.py maps the configured four-axis variant specification into the NMFC head. shrb selects softmin energy, temperature-hinge logits, reciprocal APT behavior, and minibatch bank behavior; softmax is the control path.
Paths: src/models/encoders.py, src/variants.py, src/models/heads_v3.py.
Two-Phase NMFC Training
Training begins with linear MFA warmup, then transitions automatically to full NMFC loss. APTController detects a Fisher-ratio plateau subject to configured warmup bounds; scratch runs permit up to 20 warmup epochs because the embedding geometry must form from random initialization.
The NMFC mathematical layer computes affinity, local positive/negative energies, softmin aggregation, geometric logits, and losses. This layer is reused rather than modified by plan5.
Paths: src/nmfc/losses.py, src/nmfc/apt.py, src/nmfc/energy.py.
Reference Banks and Evaluation
After training, embeddings populate reference/core-set banks used for inference and open-set transfer. The open-set path reconstructs evaluation behavior over seen and novel classes, allowing shrb to assign novel classes through reference-bank geometry while softmax remains restricted to trained output classes.
Evaluation reports classification accuracy, embedding silhouette, and open-set/OOD AUC.
Paths: src/models/banks.py, src/evaluate.py, src/train.py.
Runtime, Dependencies, and Outputs
The material runtime is Python/PyTorch with torchvision ResNet-50 and CIFAR-100 data access; pretrained mode may require ImageNet weight download, while scratch mode explicitly avoids it. Runs are GPU-oriented and configuration-driven; no orchestration scripts or web service exist.
Cached histories and metrics are stored under 산출물/, including closed and open scratch result directories. Checkpoints are intentionally excluded from the repository.
Paths: 산출물/c100s_shrb/metrics.json, 산출물/c100s_shrb_open/metrics.json, tests/test_encoder_pretrained.py.
Main entry points: train.py Training CLI · evaluate.py Closed and open evaluation · losses.py NMFC energy losses · cifar100_openset_scratch.yaml 80-seen-class split
Components 17
Experiment specs
- Training CLI · Primary config-driven experiment entry point.
src/train.py - Closed-set scratch config · Sets pretrained false for CIFAR-100 scratch ablations.
configs/cifar100_scratch.yaml - Open-set scratch config · Trains on 80 classes and evaluates across 100.
configs/cifar100_openset_scratch.yaml
Data pipeline
- CIFAR-100 loader · Loads, resizes, and augments image splits.
src/datasets/image.py - PK batch sampler · Builds metric and energy-oriented training batches.
src/datasets/samplers.py - 80-seen-class split · Filters training classes while retaining the full evaluation label space.
configs/cifar100_openset_scratch.yaml
Model assembly
- ResNet-50 encoder · Projects images to unnormalized 128-dimensional embeddings; pretrained is config-controlled.
src/models/encoders.py - Variant mapping · Builds shrb or softmax behavior from the four-axis specification.
src/variants.py - NMFC head · Implements the configured affinity and logit head.
src/models/heads_v3.py
Training core
- Linear MFA warmup · Initial phase for forming scratch embedding geometry.
src/train.py - APT controller · Uses Fisher-ratio plateau and warmup bounds to transition training.
src/nmfc/apt.py - NMFC energy losses · Computes affinity, local energies, softmin aggregation, geometric logits, and losses.
src/nmfc/losses.py - Energy functions · Provides reusable energy calculations for NMFC.
src/nmfc/energy.py
Evaluation and outputs
- Reference/core-set banks · Fits post-training references used during inference and transfer.
src/models/banks.py - Closed and open evaluation · Reports accuracy, silhouette, and open-set/OOD AUC.
src/evaluate.py - Closed scratch metrics
산출물/c100s_shrb/metrics.json - Open scratch metrics
산출물/c100s_shrb_open/metrics.json
Connections 20
- Closed-set scratch config → Training CLI: configures
- Open-set scratch config → Training CLI: configures
- Open-set scratch config → 80-seen-class split: defines
- Training CLI → CIFAR-100 loader: loads images
- CIFAR-100 loader → PK batch sampler: feeds batches
- 80-seen-class split → PK batch sampler: filters training
- Training CLI → ResNet-50 encoder: sets pretrained flag
- Training CLI → Variant mapping: selects variant
- Variant mapping → NMFC head: constructs
- ResNet-50 encoder → Linear MFA warmup: produces embeddings
- PK batch sampler → Linear MFA warmup: supplies batches
- Linear MFA warmup → APT controller: monitors progress
- APT controller → NMFC energy losses: transitions to full loss
- NMFC head → NMFC energy losses: provides head behavior
- Energy functions → NMFC energy losses: supports
- NMFC energy losses → Reference/core-set banks: trained embeddings fit
- Reference/core-set banks → Closed and open evaluation: reference inference
- 80-seen-class split → Closed and open evaluation: seen/novel evaluation
- Closed and open evaluation → Closed scratch metrics: persists closed results
- Closed and open evaluation → Open scratch metrics: persists open results