# junghwamin/nmfc-plan4-openset-80-100 architecture

> Architecture diagram of the GitHub repository junghwamin/nmfc-plan4-openset-80-100, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/junghwamin/nmfc-plan4-openset-80-100
- Repository: https://github.com/junghwamin/nmfc-plan4-openset-80-100

## Overview

#### Purpose and entry point
This is a PyTorch research experiment for CIFAR-100 open-set 80/100 transfer. Models train only on 80 deterministic “seen” classes, then evaluate both 100-way reference-bank classification and seen-vs-novel near-OOD detection. Main entry point: `python -m src.train --config ...`; open-set configs are `configs/cifar100_openset.yaml` and `configs/cifar100_openset_smoke.yaml`.

#### Configuration and experiment orchestration
`src/train.py` dispatches configured runners, including `runner: openset`, executes training/evaluation, and caches completed runs using output metrics. `src/utils/experiments.py` supports experiment lifecycle/output handling. Configs define the two central comparisons: NMFC `shrb` and a 100-logit softmax baseline.
- `src/train.py`
- `configs/base.yaml`
- `configs/cifar100_openset.yaml`

#### Open-set data boundary
The image dataset layer selects a deterministic subset of seen class IDs without relabeling them. Training data contains only those examples; test data remains all 100 CIFAR-100 classes, and model class count remains 100. This preserves sparse original labels and creates the principal train/evaluation boundary.
- `src/datasets/image.py`
- `src/datasets/samplers.py`

#### Encoder and model assembly
An ImageNet-pretrained ResNet50-style encoder produces embeddings. `src/variants.py` interprets the four-axis variant configuration and assembles the NMFC head; the target `shrb` variant uses softmin energy, hinge-temperature logits, reciprocal APT, and a minibatch bank. Softmax instead uses the conventional linear classifier path.
- `src/models/encoders.py`
- `src/variants.py`
- `src/models/heads_v3.py`

#### NMFC learning stages
NMFC has a two-phase training control flow: an initial linear-MFA warmup, followed by NMFC loss optimization once the APT controller transitions phases. Core distance/affinity, local energy, softmin neighbor processing, and losses are isolated in `src/nmfc`, while the head exposes batch training behavior.
- `src/nmfc/apt.py`
- `src/nmfc/losses.py`
- `src/nmfc/softmin.py`

#### Reference-bank inference
`VariantNMFCHead` has no class-specific learned classifier weights beyond temperature-related state. After embedding data, it fits class-labeled coreset prototype banks and maps predictions through stored `bank_classes`. This is the architectural distinction from softmax: replacing an 80-class bank with a 100-class bank enables novel-class predictions without retraining the head.
- `src/models/heads_v3.py`
- `src/models/banks.py`
- `src/nmfc/affinity.py`

#### Dual evaluation and outputs
`run_openset` performs two post-training evaluations: (A) rebuild a bank from all 100 plain training classes and report all/seen/novel top-1; (B) retain a seen-only bank and use minimum positive energy for OOD AUC between seen and novel test samples. Softmax uses its 100 logits for top-1 and MSP-derived OOD scoring. Shared metrics live in `src/evaluate.py`; persisted results are under `산출물/*/metrics.json` and `산출물/*/history.json`.
- `src/train.py`
- `src/evaluate.py`
- `산출물/c100v_shrb_open/metrics.json`

Main entry points: [`src/train.py`](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/train.py) (Training entry point), [`src/models/heads_v3.py`](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/models/heads_v3.py) (Variant NMFC head), [`src/models/encoders.py`](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/models/encoders.py) (ResNet50 encoder), [`src/variants.py`](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/variants.py) (Variant assembly)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Experiment Orchestration"]
  node_config["Open-set config<br/>YAML config"]
  node_train["Training entry point<br/>runner dispatcher<br/>[train.py]"]
  node_experiments["Experiment lifecycle<br/>run cache<br/>[experiments.py]"]
end

subgraph group_data["Open-Set Data"]
  node_dataset[("CIFAR-100 image dataset<br/>dataset boundary<br/>[image.py]")]
  node_seen_sampler["Deterministic seen split<br/>class sampler<br/>[samplers.py]"]
end

subgraph group_models["Model and NMFC"]
  node_encoder["ResNet50 encoder<br/>embedding model<br/>[encoders.py]"]
  node_variant_assembly["Variant assembly<br/>model factory<br/>[variants.py]"]
  node_nmfc_head["Variant NMFC head<br/>training and inference head<br/>[heads_v3.py]"]
  node_apt["APT phase controller<br/>training controller<br/>[apt.py]"]
  node_nmfc_losses["NMFC losses<br/>loss module<br/>[losses.py]"]
  node_softmin["Softmin energy<br/>neighbor energy<br/>[softmin.py]"]
end

subgraph group_evaluation["Inference and Evaluation"]
  node_reference_bank[("Class-labeled reference bank<br/>coreset prototype bank<br/>[banks.py]")]
  node_affinity["Bank affinity scoring<br/>inference scoring<br/>[affinity.py]"]
  node_dual_evaluation["Dual open-set evaluation<br/>evaluation workflow<br/>[train.py]"]
  node_metrics["Shared metrics<br/>metric computation<br/>[evaluate.py]"]
  node_results["Persisted run results<br/>experiment outputs<br/>[metrics.json]"]
end

node_config -->|"configures"| node_train
node_train -->|"manages runs"| node_experiments
node_train -->|"loads data"| node_dataset
node_seen_sampler -->|"restricts training to 80 classes"| node_dataset
node_train -->|"builds configured model"| node_variant_assembly
node_variant_assembly -->|"uses embeddings"| node_encoder
node_variant_assembly -->|"selects shrb head"| node_nmfc_head
node_encoder -->|"embedding batches"| node_nmfc_head
node_apt -->|"controls training phase"| node_nmfc_head
node_nmfc_losses -->|"optimizes head"| node_nmfc_head
node_softmin -->|"local energy"| node_nmfc_losses
node_nmfc_head -->|"fits labeled coresets"| node_reference_bank
node_reference_bank -->|"prototypes and classes"| node_affinity
node_encoder -->|"test embeddings"| node_affinity
node_train -->|"after training"| node_dual_evaluation
node_dual_evaluation -->|"rebuilds 100-class bank"| node_reference_bank
node_affinity -->|"bank predictions and energy"| node_dual_evaluation
node_dual_evaluation -->|"classification and OOD scores"| node_metrics
node_metrics -->|"writes metrics"| node_results
node_experiments -->|"persists history"| node_results

click node_config "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/configs/cifar100_openset.yaml"
click node_train "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/train.py"
click node_experiments "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/utils/experiments.py"
click node_dataset "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/datasets/image.py"
click node_seen_sampler "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/datasets/samplers.py"
click node_encoder "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/models/encoders.py"
click node_variant_assembly "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/variants.py"
click node_nmfc_head "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/models/heads_v3.py"
click node_apt "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/nmfc/apt.py"
click node_nmfc_losses "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/nmfc/losses.py"
click node_softmin "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/nmfc/softmin.py"
click node_reference_bank "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/models/banks.py"
click node_affinity "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/nmfc/affinity.py"
click node_dual_evaluation "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/train.py"
click node_metrics "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/evaluate.py"
click node_results "https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/%EC%82%B0%EC%B6%9C%EB%AC%BC/c100v_shrb_open/metrics.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_train,node_experiments toneBlue
class node_dataset,node_seen_sampler toneAmber
class node_encoder,node_variant_assembly,node_nmfc_head,node_apt,node_nmfc_losses,node_softmin toneMint
class node_reference_bank,node_affinity,node_dual_evaluation,node_metrics,node_results toneRose
```

## Components

### Experiment Orchestration

- [Open-set config](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/configs/cifar100_openset.yaml): YAML config · Defines the shrb NMFC and 100-logit softmax comparisons. · `configs/cifar100_openset.yaml`
- [Training entry point](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/train.py): runner dispatcher · Dispatches configured training and open-set evaluation runs. · `src/train.py`
- [Experiment lifecycle](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/utils/experiments.py): run cache · Manages run outputs and completion caching. · `src/utils/experiments.py`

### Open-Set Data

- [CIFAR-100 image dataset](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/datasets/image.py): dataset boundary · Keeps original 100-class labels while training data is restricted to seen examples. · `src/datasets/image.py`
- [Deterministic seen split](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/datasets/samplers.py): class sampler · Selects the fixed 80 seen class IDs without relabeling. · `src/datasets/samplers.py`

### Model and NMFC

- [ResNet50 encoder](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/models/encoders.py): embedding model · ImageNet-pretrained encoder producing embeddings. · `src/models/encoders.py`
- [Variant assembly](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/variants.py): model factory · Interprets four-axis variants and selects NMFC or softmax heads. · `src/variants.py`
- [Variant NMFC head](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/models/heads_v3.py): training and inference head · Exposes minibatch-bank NMFC training and bank-based prediction. · `src/models/heads_v3.py`
- [APT phase controller](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/nmfc/apt.py): training controller · Transitions from linear-MFA warmup to NMFC optimization. · `src/nmfc/apt.py`
- [NMFC losses](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/nmfc/losses.py): loss module · Optimizes distance, affinity, and local-energy objectives. · `src/nmfc/losses.py`
- [Softmin energy](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/nmfc/softmin.py): neighbor energy · Processes neighbors for the shrb energy formulation. · `src/nmfc/softmin.py`

### Inference and Evaluation

- [Class-labeled reference bank](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/models/banks.py): coreset prototype bank · Stores prototypes and bank_classes for 80- or 100-class prediction. · `src/models/banks.py`
- [Bank affinity scoring](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/nmfc/affinity.py): inference scoring · Scores embeddings against the reference bank. · `src/nmfc/affinity.py`
- [Dual open-set evaluation](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/train.py): evaluation workflow · Runs 100-bank classification and seen-bank OOD detection. · `src/train.py`
- [Shared metrics](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/src/evaluate.py): metric computation · Computes top-1, OOD AUC, and softmax MSP scoring. · `src/evaluate.py`
- [Persisted run results](https://github.com/junghwamin/nmfc-plan4-openset-80-100/blob/main/%EC%82%B0%EC%B6%9C%EB%AC%BC/c100v_shrb_open/metrics.json): experiment outputs · Stores metrics and training history for completed runs. · `산출물/c100v_shrb_open/metrics.json`

## Connections

- Open-set config → Training entry point: configures
- Training entry point → Experiment lifecycle: manages runs
- Training entry point → CIFAR-100 image dataset: loads data
- Deterministic seen split → CIFAR-100 image dataset: restricts training to 80 classes
- Training entry point → Variant assembly: builds configured model
- Variant assembly → ResNet50 encoder: uses embeddings
- Variant assembly → Variant NMFC head: selects shrb head
- ResNet50 encoder → Variant NMFC head: embedding batches
- APT phase controller → Variant NMFC head: controls training phase
- NMFC losses → Variant NMFC head: optimizes head
- Softmin energy → NMFC losses: local energy
- Variant NMFC head → Class-labeled reference bank: fits labeled coresets
- Class-labeled reference bank → Bank affinity scoring: prototypes and classes
- ResNet50 encoder → Bank affinity scoring: test embeddings
- Training entry point → Dual open-set evaluation: after training
- Dual open-set evaluation → Class-labeled reference bank: rebuilds 100-class bank
- Bank affinity scoring → Dual open-set evaluation: bank predictions and energy
- Dual open-set evaluation → Shared metrics: classification and OOD scores
- Shared metrics → Persisted run results: writes metrics
- Experiment lifecycle → Persisted run results: persists history
