# junghwamin/nmfc-plan6-novel-transfer architecture

> Architecture diagram of the GitHub repository junghwamin/nmfc-plan6-novel-transfer, 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-plan6-novel-transfer
- Repository: https://github.com/junghwamin/nmfc-plan6-novel-transfer

## Overview

#### Purpose and entry points
This is a PyTorch research pipeline for reassessing NMFC’s `shrb` open-set classifier on CIFAR-100. It tests whether poor novel-class transfer comes from fine-tuning specialization and whether reference-bank performance belongs to NMFC training or bank-based inference.

Primary entry points:
- Training/open-set experiments: `src/train.py`
- Bank-only reevaluation of cached encoders: `scripts/eval_softmax_bank.py`
- Experiment specifications: `configs/cifar100_openset_nseen.yaml`, `configs/cifar100_openset_freeze.yaml`, `configs/cifar100_openset_freeze_smoke.yaml`

#### Data and open-set partitioning
CIFAR-100 is loaded and partitioned into seen versus novel classes while preserving the full test-label space. `n_seen` controls the amount of supervised training data/classes and is swept at 50/80/90.
- `src/datasets/image.py`
- `src/datasets/samplers.py`
- `configs/cifar100_openset_nseen.yaml`

#### Training orchestration and experiment boundary
`run_openset` and its image-training core coordinate encoder construction, variant resolution, optimization, phase scheduling, bank fitting, cache/run management, and final metrics. The `freeze_backbone` gate makes the pretrained ResNet body non-trainable while retaining its projection layer and head parameters for linear-probe-like training.
- `src/train.py`
- `src/utils/experiments.py`
- `configs/cifar100_openset_freeze.yaml`

#### Encoder and representation boundary
`ResNet50Encoder` starts from ImageNet-pretrained ResNet-50 and replaces its classifier with a 128-dimensional projection. It emits raw, non-L2-normalized embeddings, preserving Euclidean distance behavior used by NMFC energy and bank computations.
- `src/models/encoders.py`
- `src/models/baselines.py`

#### Variant assembly and NMFC head
Variant resolution converts four configured axes—energy, logit, APT schedule, and bank mode—into the selected head. The main `shrb` path uses `VariantNMFCHead`, with soft-min energies, hinge-temperature logits, reciprocal APT, and minibatch behavior. The head owns coreset-bank fitting, bank energy calculation, prediction, and OOD scoring.
- `src/variants.py`
- `src/models/heads_v3.py`
- `src/models/banks.py`

#### NMFC mathematical/training stages
The reusable NMFC layer implements local soft-min/kNN energy, affinity computation, energy formulations, loss construction, and a two-phase reciprocal APT controller. Training applies NMFC loss to encoder/head outputs; after training, a classwise coreset reference bank is fit for open-set and expanded-class evaluation.
- `src/nmfc/softmin.py`
- `src/nmfc/affinity.py`
- `src/nmfc/losses.py`
- `src/nmfc/apt.py`

#### Evaluation and bank-only control experiment
Standard evaluation reports open top-1 for all/seen/novel classes, OOD AUC, and embedding silhouette. The independent bank script bypasses training: it loads a cached softmax or shrb encoder, embeds all 100 classes, fits the same NMFC coreset bank, then predicts by minimum positive bank energy. This isolates bank inference from encoder-training methodology.
- `src/evaluate.py`
- `scripts/eval_softmax_bank.py`
- `src/models/heads_v3.py`

#### Runtime, artifacts, and external dependencies
The system is Python/PyTorch-based and depends on CIFAR-100 plus torchvision/ImageNet pretrained ResNet-50 weights. Training/checkpoints and excluded embedding caches are external runtime artifacts; committed result summaries live under `산출물/`, including `metrics.json` and training `history.json`. No dedicated test suite exists.
- `산출물/c100v_shrb_open_frz/metrics.json`
- `산출물/c100v_softmax_open_bank/metrics.json`
- `산출물/_checkpoints_원본경로.txt`

Main entry points: [`src/train.py`](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/train.py) (Open-set training entry), [`src/models/encoders.py`](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/models/encoders.py) (ResNet50 encoder), [`src/models/heads_v3.py`](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/models/heads_v3.py) (Variant NMFC head (shrb)), [`configs/cifar100_openset_nseen.yaml`](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/configs/cifar100_openset_nseen.yaml) (Open-set experiment specs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data &amp; splits"]
  node_cifar[("CIFAR-100 + pretrained weights<br/>external data")]
  node_dataset["Image dataset partition<br/>dataset loader<br/>[image.py]"]
  node_samplers["Seen-class samplers<br/>[samplers.py]"]
end

subgraph group_training["Training"]
  node_configs["Open-set experiment specs<br/>YAML configs"]
  node_train["Open-set training entry<br/>training orchestrator<br/>[train.py]"]
  node_experiments["Run management<br/>experiment utilities<br/>[experiments.py]"]
  node_encoder["ResNet50 encoder<br/>PyTorch encoder<br/>[encoders.py]"]
  node_freeze["Frozen-backbone mode<br/>training mode"]
end

subgraph group_nmfc["NMFC variant &amp; bank"]
  node_variants["Variant resolver<br/>variant assembly<br/>[variants.py]"]
  node_shrb_head["Variant NMFC head &#40;shrb&#41;<br/>open-set head<br/>[heads_v3.py]"]
  node_nmfc_energy["Soft-min &amp; affinity energy<br/>NMFC representation layer<br/>[softmin.py]"]
  node_nmfc_loss["NMFC loss<br/>loss construction<br/>[losses.py]"]
  node_apt["Reciprocal APT controller<br/>phase scheduler<br/>[apt.py]"]
  node_coreset_bank[("Classwise coreset bank<br/>reference bank<br/>[banks.py]")]
end

subgraph group_evaluation["Evaluation"]
  node_evaluate["Standard evaluation<br/>metrics evaluator<br/>[evaluate.py]"]
  node_bank_eval["Bank-only reevaluation<br/>control experiment"]
  node_artifacts["Committed result summaries<br/>result artifacts<br/>[metrics.json]"]
end

node_cifar -->|"loaded by"| node_dataset
node_configs -->|"sets n_seen"| node_dataset
node_dataset -->|"partitioned data"| node_samplers
node_configs -->|"configures"| node_train
node_samplers -->|"training batches"| node_train
node_experiments -->|"run/cache support"| node_train
node_freeze -->|"freeze_backbone gate"| node_train
node_cifar -->|"ImageNet initialization"| node_encoder
node_train -->|"optimizes"| node_encoder
node_configs -->|"variant axes"| node_variants
node_variants -->|"selects shrb head"| node_shrb_head
node_encoder -->|"raw 128-D embeddings"| node_shrb_head
node_nmfc_energy -->|"energy terms"| node_nmfc_loss
node_apt -->|"phase schedule"| node_nmfc_loss
node_nmfc_loss -->|"training objective"| node_train
node_train -->|"fits after training"| node_coreset_bank
node_coreset_bank -->|"reference energies"| node_shrb_head
node_shrb_head -->|"predictions and OOD scores"| node_evaluate
node_evaluate -->|"writes metrics"| node_artifacts
node_encoder -.->|"cached encoder embeddings"| node_bank_eval
node_bank_eval -->|"refits same bank"| node_coreset_bank
node_bank_eval -->|"control metrics"| node_artifacts

click node_configs "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/configs/cifar100_openset_nseen.yaml"
click node_dataset "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/datasets/image.py"
click node_samplers "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/datasets/samplers.py"
click node_train "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/train.py"
click node_experiments "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/utils/experiments.py"
click node_encoder "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/models/encoders.py"
click node_freeze "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/configs/cifar100_openset_freeze.yaml"
click node_variants "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/variants.py"
click node_shrb_head "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/models/heads_v3.py"
click node_nmfc_energy "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/nmfc/softmin.py"
click node_nmfc_loss "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/nmfc/losses.py"
click node_apt "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/nmfc/apt.py"
click node_coreset_bank "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/models/banks.py"
click node_evaluate "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/evaluate.py"
click node_bank_eval "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/scripts/eval_softmax_bank.py"
click node_artifacts "https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/%EC%82%B0%EC%B6%9C%EB%AC%BC/c100v_shrb_open_frz/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_cifar,node_dataset,node_samplers toneBlue
class node_configs,node_train,node_experiments,node_encoder,node_freeze toneAmber
class node_variants,node_shrb_head,node_nmfc_energy,node_nmfc_loss,node_apt,node_coreset_bank toneMint
class node_evaluate,node_bank_eval,node_artifacts toneRose
```

## Components

### Data & splits

- **CIFAR-100 + pretrained weights**: external data · CIFAR-100 retains its full 100-class test label space; ResNet-50 begins from ImageNet weights.
- [Image dataset partition](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/datasets/image.py): dataset loader · Partitions labels into seen and novel classes. · `src/datasets/image.py`
- [Seen-class samplers](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/datasets/samplers.py): samplers · Controls supervised data exposure for n_seen. · `src/datasets/samplers.py`

### Training

- [Open-set experiment specs](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/configs/cifar100_openset_nseen.yaml): YAML configs · Defines n_seen sweeps, variants, and frozen-backbone runs. · `configs/cifar100_openset_nseen.yaml`
- [Open-set training entry](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/train.py): training orchestrator · Runs encoder/head construction, optimization, phases, bank fitting, caching, and final metrics. · `src/train.py`
- [Run management](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/utils/experiments.py): experiment utilities · Manages experiment runs and caches. · `src/utils/experiments.py`
- [ResNet50 encoder](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/models/encoders.py): PyTorch encoder · Pretrained ResNet-50 with a 128-D raw embedding projection. · `src/models/encoders.py`
- [Frozen-backbone mode](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/configs/cifar100_openset_freeze.yaml): training mode · Freezes the ResNet body while training projection and head parameters. · `configs/cifar100_openset_freeze.yaml`

### NMFC variant & bank

- [Variant resolver](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/variants.py): variant assembly · Selects the head from energy, logit, APT, and bank-mode axes. · `src/variants.py`
- [Variant NMFC head (shrb)](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/models/heads_v3.py): open-set head · Owns bank fitting, bank energy, prediction, and OOD scoring. · `src/models/heads_v3.py`
- [Soft-min & affinity energy](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/nmfc/softmin.py): NMFC representation layer · Computes local soft-min/kNN energy and affinities. · `src/nmfc/softmin.py`
- [NMFC loss](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/nmfc/losses.py): loss construction · Builds the training objective from NMFC energies. · `src/nmfc/losses.py`
- [Reciprocal APT controller](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/nmfc/apt.py): phase scheduler · Applies the two-phase reciprocal APT schedule. · `src/nmfc/apt.py`
- [Classwise coreset bank](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/models/banks.py): reference bank · Fits per-class references for open-set and expanded-class inference. · `src/models/banks.py`

### Evaluation

- [Standard evaluation](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/src/evaluate.py): metrics evaluator · Reports all/seen/novel top-1, OOD AUC, and embedding silhouette. · `src/evaluate.py`
- [Bank-only reevaluation](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/scripts/eval_softmax_bank.py): control experiment · Loads cached encoders, refits the bank over all classes, and predicts by minimum positive bank energy. · `scripts/eval_softmax_bank.py`
- [Committed result summaries](https://github.com/junghwamin/nmfc-plan6-novel-transfer/blob/main/%EC%82%B0%EC%B6%9C%EB%AC%BC/c100v_shrb_open_frz/metrics.json): result artifacts · Stores metrics and training histories; checkpoints and embedding caches are runtime artifacts. · `산출물/c100v_shrb_open_frz/metrics.json`

## Connections

- CIFAR-100 + pretrained weights → Image dataset partition: loaded by
- Open-set experiment specs → Image dataset partition: sets n_seen
- Image dataset partition → Seen-class samplers: partitioned data
- Open-set experiment specs → Open-set training entry: configures
- Seen-class samplers → Open-set training entry: training batches
- Run management → Open-set training entry: run/cache support
- Frozen-backbone mode → Open-set training entry: freeze_backbone gate
- CIFAR-100 + pretrained weights → ResNet50 encoder: ImageNet initialization
- Open-set training entry → ResNet50 encoder: optimizes
- Open-set experiment specs → Variant resolver: variant axes
- Variant resolver → Variant NMFC head (shrb): selects shrb head
- ResNet50 encoder → Variant NMFC head (shrb): raw 128-D embeddings
- Soft-min & affinity energy → NMFC loss: energy terms
- Reciprocal APT controller → NMFC loss: phase schedule
- NMFC loss → Open-set training entry: training objective
- Open-set training entry → Classwise coreset bank: fits after training
- Classwise coreset bank → Variant NMFC head (shrb): reference energies
- Variant NMFC head (shrb) → Standard evaluation: predictions and OOD scores
- Standard evaluation → Committed result summaries: writes metrics
- ResNet50 encoder → Bank-only reevaluation: cached encoder embeddings
- Bank-only reevaluation → Classwise coreset bank: refits same bank
- Bank-only reevaluation → Committed result summaries: control metrics
