How junghwamin/nmfc-plan7-retrieval-cluster works
Purpose and execution model
This repository is plan7 of an NMFC research series: a no-retraining analysis that compares shrb/NMFC and softmax using cached test embeddings only. Its practical question is whether embedding-geometry gains translate into retrieval, clustering, verification, and few-shot recognition. Primary runnable entry points are scripts/eval_retrieval.py, scripts/eval_fewshot_verify.py, and scripts/build_report_figures.py.
Input boundary: cached experiment embeddings
Analysis consumes external, gitignored results/<experiment>/embeddings.npz files containing z_test (expected 10,000 × 128) and y_test. The repository does not include those inputs; 산출물/_읽는입력_embeddings_안내.txt documents this dependency. src/utils/experiments.py is the shared read-side boundary through load_embeddings and collect_results; analysis does not load checkpoints or invoke training.
Retrieval and clustering evaluation
scripts/eval_retrieval.py is the main geometry evaluator. It L2-normalizes embeddings, performs GPU-chunked cosine nearest-neighbor retrieval, excludes each query itself, and computes Recall@1, Recall@5, and mAP. It also clusters embeddings with KMeans for purity and NMI. Built-in assertions/self-tests protect AP, purity, class-count, and leave-one-out assumptions. Results are persisted in 산출물/retrieval_eval.json.
Verification and few-shot evaluation
scripts/eval_fewshot_verify.py measures pairwise same/different-class separability via balanced sampled cosine-score AUC, then evaluates prototype nearest-class-mean recognition. Few-shot performance is swept across K-shot settings and summarized with a class-incremental gallery curve. Its self-test validates separable synthetic cases. Results are written to 산출물/fewshot_verify_eval.json.
Reporting layer
scripts/build_report_figures.py reads both evaluation JSON outputs plus embeddings to create report-ready visualizations: t-SNE, retrieval comparison, few-shot curves, incremental curves, and reference-bank-related plots. It is a terminal consumer rather than part of metric computation, producing files under 산출물/figures.
Inherited embedding-production pipeline
The src/ tree is inherited and intentionally unmodified by plan7. In other plans, data flows from image datasets through an encoder and NMFC/softmax head to produce the cached embedding artifact:
• Data and sampling: src/datasets/image.py, src/datasets/samplers.py
• Encoder/head assembly: src/models/encoders.py, src/models/heads.py, src/models/heads_v3.py
• Reference-bank state: src/models/banks.py
• NMFC local-geometry computation: src/nmfc/affinity.py, src/nmfc/energy.py, src/nmfc/losses.py
• Training/evaluation orchestration: src/train.py, src/evaluate.py, src/variants.py
Runtime and external dependencies
The evaluation scripts require Python with NumPy/PyTorch for embedding and GPU-chunked similarity operations, scikit-learn for KMeans, NMI, ROC AUC, and likely t-SNE, plus matplotlib with a noninteractive Agg backend for reports. There is no service/API layer, configuration system, or training runtime required for plan7; the material infrastructure dependency is access to the external results/ embedding cache.
Main entry points: build_report_figures.py Report figure builder · experiments.py Experiment reader · eval_retrieval.py Retrieval evaluator · eval_fewshot_verify.py Few-shot verifier
Components 19
Plan7 analysis
No-retraining evaluation over cached test embeddings.
- Cached test embeddings · Gitignored NPZ files containing z_test and y_test.
- Embedding input guide · Documents the required external cache.
산출물/_읽는입력_embeddings_안내.txt - Experiment reader · Loads embeddings and collects experiment results.
src/utils/experiments.py - Retrieval evaluator · Main geometry evaluation entry point.
scripts/eval_retrieval.py - Retrieval metrics · Normalized chunked cosine search yields Recall@1/5 and mAP.
- Clustering metrics · KMeans produces purity and NMI.
- Retrieval results
산출물/retrieval_eval.json - Few-shot verifier · Evaluates pairwise verification and prototype recognition.
scripts/eval_fewshot_verify.py - Verification AUC · Balanced same/different cosine-score sampling.
- Few-shot prototypes · K-shot nearest-class-mean and incremental gallery curves.
- Few-shot results
산출물/fewshot_verify_eval.json - Report figure builder · Terminal consumer for metrics and embeddings.
scripts/build_report_figures.py - Report figures · t-SNE, retrieval, few-shot, incremental, and bank-related plots.
산출물/figures
Inherited embedding production
Unmodified pipeline that produces caches in other plans.
- Image data and sampling
src/datasets/image.py - Sampling
src/datasets/samplers.py - Encoder and heads
src/models/encoders.py - Reference-bank state
src/models/banks.py - NMFC geometry · Affinity, energy, and loss computation.
src/nmfc/affinity.py - Training and evaluation · Inherited runtime exports experiment embeddings.
src/train.py
Connections 23
- Embedding input guide → Cached test embeddings: documents
- Cached test embeddings → Experiment reader: loaded by
- Experiment reader → Retrieval evaluator: embeddings
- Retrieval evaluator → Retrieval metrics: cosine retrieval
- Retrieval evaluator → Clustering metrics: KMeans
- Retrieval metrics → Retrieval results: metrics
- Clustering metrics → Retrieval results: metrics
- Experiment reader → Few-shot verifier: embeddings
- Few-shot verifier → Verification AUC: cosine pairs
- Few-shot verifier → Few-shot prototypes: K-shot sweep
- Verification AUC → Few-shot results: AUC
- Few-shot prototypes → Few-shot results: recognition curves
- Cached test embeddings → Report figure builder: embeddings
- Retrieval results → Report figure builder: retrieval data
- Few-shot results → Report figure builder: few-shot data
- Report figure builder → Report figures: renders
- Image data and sampling → Sampling: images
- Sampling → Encoder and heads: batches
- Encoder and heads → NMFC geometry: embeddings
- Reference-bank state → NMFC geometry: references
- NMFC geometry → Training and evaluation: training loss
- Encoder and heads → Training and evaluation: softmax or NMFC model
- Training and evaluation → Cached test embeddings: exports in other plans