How junghwamin/nmfc-plan3-v4-sphere-negj works
Purpose and Entry Points
This is a PyTorch NMFC experiment repository for validating a v4 change to Phase-I Fisher discriminant warmup: compute −J on unit-normalized embeddings to prevent scale-driven embedding expansion. Primary execution is python -m src.train --config ...; evaluation is invoked from training and implemented in src/evaluate.py. Experiment definitions live in configs/cifar100_variants_wave3.yaml and configs/ood_cifar10_variants_wave3.yaml.
Configuration and Variant Assembly
src/variants.py centralizes a four-axis experiment vocabulary: energy, logit, APT/warmup, and bank behavior. Its APT axis selects reciprocal, raw negJ, sphere negJ, or trace-ratio variants and uses is_negj_family() to keep Phase-I behavior consistent. Config files define named runs such as sphere/reference-bank and sphere/online-bank variants.
Paths: src/variants.py, configs/base.yaml, configs/cifar100_variants_wave3.yaml.
Data and Representation Pipeline
Image datasets—including CIFAR-10/100 and SVHN for OOD—are loaded through the dataset layer; class-balanced PK sampling supports scatter/Fisher estimates. Batches flow into a ResNet50-based encoder that emits embedding z; this raw embedding remains the model and inference representation.
Paths: src/datasets/image.py, src/datasets/samplers.py, src/models/encoders.py.
NMFC Model and Memory Banks
VariantNMFCHead composes the selected geometry/logit/bank behaviors over encoder embeddings. Reference and online class banks supply class prototypes or dynamic representation state. This boundary separates learned visual representation from NMFC class-geometry computation.
Paths: src/models/heads_v3.py, src/models/banks.py, src/models/heads.py.
Two-Phase Training Control
src/train.py owns the stateful training loop. Phase I applies discriminative warmup; for negJ-family variants it routes batch embeddings to Fisher monitoring/loss and, for trace-ratio mode, establishes κ from the median observed Phase-I J values. ACSController detects Fisher-progress stagnation and latches a one-way transition to Phase II. Training logs metrics, history, and embedding-norm diagnostics under experiment output directories.
Paths: src/train.py, src/nmfc/acs.py, 산출물/c100v_shnb/history.json.
Phase-I Fisher Objective: v4 Core Change
fisher_j computes within/between-class scatter and the Fisher trace criterion. The sphere variant normalizes only inside this calculation (z/||z||), making its J scale-invariant; it does not normalize stored embeddings, Phase-II inputs, or inference inputs. neg_j_loss supports raw −J and bounded trace-ratio −J/(J+κ).
Paths: src/nmfc/acs.py, src/nmfc/losses.py, tests/test_acs.py.
Phase-II NMFC Objective and Evaluation
After ACS transition, the head’s affinity, softmin energy, geometric logits, and NMFC NLL drive optimization. Evaluation reports classification Top-1/Top-5, embedding silhouette, and CIFAR-vs-SVHN OOD AUC; results are persisted as JSON. The architecture is local Python/PyTorch execution with dataset downloads/storage and no indicated deployed service infrastructure.
Paths: src/nmfc/affinity.py, src/nmfc/softmin.py, src/nmfc/energy.py, src/evaluate.py, 산출물/ood10v_shnb/metrics.json.
Main entry points: train.py Training loop · heads_v3.py Variant NMFC head · cifar100_variants_wave3.yaml Experiment configs · energy.py NMFC NLL
Components 18
Experiment Assembly
- Experiment configs · Named CIFAR-100 and OOD variant runs.
configs/cifar100_variants_wave3.yaml - Base configuration
configs/base.yaml - Variant vocabulary · Combines energy, logit, APT, and bank axes.
src/variants.py
Data & Representation
- Image datasets · Loads CIFAR and SVHN image data.
src/datasets/image.py - PK sampler · Builds class-balanced batches for Fisher estimates.
src/datasets/samplers.py - ResNet50 encoder · Produces raw embedding z used by model and inference.
src/models/encoders.py
Training & Objectives
- Training loop · Primary python -m src.train execution and phase control.
src/train.py - ACS controller · Latches a one-way transition after Fisher-progress stagnation.
src/nmfc/acs.py - Fisher J · Computes within/between scatter; sphere mode normalizes only here.
src/nmfc/acs.py - neg-J loss · Supports raw −J and bounded trace-ratio loss.
src/nmfc/losses.py - Variant NMFC head · Applies selected geometry, logits, and bank behavior to z.
src/models/heads_v3.py - Class memory banks · Reference and online class representation state.
src/models/banks.py - Affinity
src/nmfc/affinity.py - Softmin energy
src/nmfc/softmin.py - NMFC NLL · Optimizes geometric logits and softmin energy.
src/nmfc/energy.py
Evaluation & Outputs
- Evaluation · Reports Top-1/5, silhouette, and CIFAR-vs-SVHN OOD AUC.
src/evaluate.py - Training history · Metrics and embedding-norm diagnostics.
산출물/c100v_shnb/history.json - OOD metrics · Persisted OOD evaluation results.
산출물/ood10v_shnb/metrics.json
Connections 20
- Base configuration → Experiment configs: defaults
- Experiment configs → Variant vocabulary: selects axes
- Experiment configs → Training loop: run config
- Variant vocabulary → Variant NMFC head: configures
- Image datasets → PK sampler: examples
- PK sampler → ResNet50 encoder: balanced batches
- ResNet50 encoder → Variant NMFC head: raw z
- Training loop → ACS controller: monitors Phase I
- Training loop → Fisher J: negJ-family z
- Fisher J → neg-J loss: J and κ
- neg-J loss → Training loop: Phase-I optimization
- ACS controller → NMFC NLL: enables Phase II
- Variant NMFC head → Class memory banks: reads and updates
- Variant NMFC head → Affinity: class geometry
- Affinity → Softmin energy: affinities
- Softmin energy → NMFC NLL: energy
- NMFC NLL → Training loop: Phase-II optimization
- Training loop → Evaluation: invokes
- Training loop → Training history: writes
- Evaluation → OOD metrics: writes JSON