# zhangruichi/cue architecture

> Architecture diagram of the GitHub repository zhangruichi/cue, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhangruichi/cue
- Repository: https://github.com/zhangruichi/cue

## Overview

CUE trains and evaluates long-tailed image classifiers: a user selects a dataset and model configuration, then training builds data loaders and a CLIP-based adaptable classifier, augments supervision with VLM instance cues and LLM class relations, and evaluates predictions. The repository also supports zero-shot and test-only runs. Groups distinguish data, model, CUE supervision, and orchestration/evaluation. Some subsystem links are documented in the README or source index rather than shown in full excerpts; those limits are reflected by omitting uncertain call paths.

Main entry points: [`trainer.py`](https://github.com/zhangruichi/cue/blob/main/trainer.py) (Trainer), [`datasets/__init__.py`](https://github.com/zhangruichi/cue/blob/main/datasets/__init__.py) (Dataset Registry), [`models/models.py`](https://github.com/zhangruichi/cue/blob/main/models/models.py) (Classifier Models), [`clip/clip.py`](https://github.com/zhangruichi/cue/blob/main/clip/clip.py) (CLIP Loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Datasets"]
  node_datasets["Dataset Registry<br/>[__init__.py]"]
  node_cifar["CIFAR Long-Tail<br/>[cifar100.py]"]
  node_ltdata["Image List Dataset<br/>[lt_data.py]"]
  node_inat["iNaturalist<br/>[inat2018.py]"]
  node_imagenet["ImageNet-LT<br/>[imagenet_lt.py]"]
  node_places["Places-LT<br/>[places_lt.py]"]
end

subgraph group_model["Modeling"]
  node_clip_api["CLIP Loading<br/>[clip.py]"]
  node_clip_model["CLIP Backbone<br/>[model.py]"]
  node_tokenizer["Text Tokenizer"]
  node_models["Classifier Models<br/>[models.py]"]
  node_peft_vit["ViT Adaptation<br/>[peft_vit.py]"]
  node_peft_rn["ResNet Adaptation<br/>[peft_rn.py]"]
  node_peft_parts["Tuning Modules<br/>[peft_modules.py]"]
  node_classifiers["Classifier Heads<br/>[classifiers.py]"]
  node_templates["Prompt Templates<br/>[templates.py]"]
end

subgraph group_cue["CUE Supervision"]
  node_cue_utils["Cue Generation<br/>[cue_utils.py]"]
  node_relations["LLM Relations"]
  node_losses["Training Losses<br/>[losses.py]"]
end

subgraph group_runtime["Training and Evaluation"]
  node_entry["CLI Entry<br/>[main.py]"]
  node_config["Run Configuration<br/>[config.py]"]
  node_trainer["Trainer<br/>[trainer.py]"]
  node_samplers["Class Samplers<br/>[samplers.py]"]
  node_evaluator["Metrics Evaluator<br/>[evaluator.py]"]
end

node_user(("Researcher"))

node_user -->|"configures run"| node_entry
node_entry -->|"loads settings"| node_config
node_entry -->|"starts run"| node_trainer
node_trainer -->|"builds loaders"| node_datasets
node_datasets -->|"selects dataset"| node_cifar
node_datasets -->|"selects dataset"| node_inat
node_datasets -->|"selects dataset"| node_imagenet
node_datasets -->|"selects dataset"| node_places
node_inat -->|"inherits data access"| node_ltdata
node_imagenet -->|"inherits data access"| node_ltdata
node_places -->|"inherits data access"| node_ltdata
node_trainer -->|"builds classifier"| node_models
node_trainer -->|"loads CLIP"| node_clip_api
node_clip_api -->|"builds backbone"| node_clip_model
node_clip_api -->|"tokenizes text"| node_tokenizer
node_models -->|"adapts ViT"| node_peft_vit
node_models -->|"adapts ResNet"| node_peft_rn
node_models -->|"creates head"| node_classifiers
node_peft_vit -->|"uses tuners"| node_peft_parts
node_peft_rn -->|"uses tuners"| node_peft_parts
node_trainer -->|"generates cues"| node_cue_utils
node_cue_utils -->|"reads relations"| node_relations
node_trainer -->|"computes objective"| node_losses
node_trainer -->|"samples batches"| node_samplers
node_trainer -->|"uses prompts"| node_templates
node_trainer -->|"evaluates predictions"| node_evaluator
node_templates -.->|"encodes class prompts"| node_clip_model

click node_entry "https://github.com/zhangruichi/cue/blob/main/main.py"
click node_config "https://github.com/zhangruichi/cue/blob/main/utils/config.py"
click node_trainer "https://github.com/zhangruichi/cue/blob/main/trainer.py"
click node_datasets "https://github.com/zhangruichi/cue/blob/main/datasets/__init__.py"
click node_cifar "https://github.com/zhangruichi/cue/blob/main/datasets/cifar100.py"
click node_ltdata "https://github.com/zhangruichi/cue/blob/main/datasets/lt_data.py"
click node_inat "https://github.com/zhangruichi/cue/blob/main/datasets/inat2018.py"
click node_imagenet "https://github.com/zhangruichi/cue/blob/main/datasets/imagenet_lt.py"
click node_places "https://github.com/zhangruichi/cue/blob/main/datasets/places_lt.py"
click node_clip_api "https://github.com/zhangruichi/cue/blob/main/clip/clip.py"
click node_clip_model "https://github.com/zhangruichi/cue/blob/main/clip/model.py"
click node_tokenizer "https://github.com/zhangruichi/cue/blob/main/clip/simple_tokenizer.py"
click node_models "https://github.com/zhangruichi/cue/blob/main/models/models.py"
click node_peft_vit "https://github.com/zhangruichi/cue/blob/main/models/peft_vit.py"
click node_peft_rn "https://github.com/zhangruichi/cue/blob/main/models/peft_rn.py"
click node_peft_parts "https://github.com/zhangruichi/cue/blob/main/models/peft_modules.py"
click node_classifiers "https://github.com/zhangruichi/cue/blob/main/models/classifiers.py"
click node_cue_utils "https://github.com/zhangruichi/cue/blob/main/utils/cue_utils.py"
click node_relations "https://github.com/zhangruichi/cue/tree/main/llm_json"
click node_losses "https://github.com/zhangruichi/cue/blob/main/utils/losses.py"
click node_samplers "https://github.com/zhangruichi/cue/blob/main/utils/samplers.py"
click node_templates "https://github.com/zhangruichi/cue/blob/main/utils/templates.py"
click node_evaluator "https://github.com/zhangruichi/cue/blob/main/utils/evaluator.py"

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_datasets,node_cifar,node_ltdata,node_inat,node_imagenet,node_places toneBlue
class node_clip_api,node_clip_model,node_tokenizer,node_models,node_peft_vit,node_peft_rn,node_peft_parts,node_classifiers,node_templates toneAmber
class node_cue_utils,node_relations,node_losses toneMint
class node_entry,node_config,node_trainer,node_samplers,node_evaluator toneRose
class node_user toneIndigo
```

## Components

### Datasets

- [Dataset Registry](https://github.com/zhangruichi/cue/blob/main/datasets/__init__.py): `datasets/__init__.py`
- [CIFAR Long-Tail](https://github.com/zhangruichi/cue/blob/main/datasets/cifar100.py): `datasets/cifar100.py`
- [Image List Dataset](https://github.com/zhangruichi/cue/blob/main/datasets/lt_data.py): `datasets/lt_data.py`
- [iNaturalist](https://github.com/zhangruichi/cue/blob/main/datasets/inat2018.py): `datasets/inat2018.py`
- [ImageNet-LT](https://github.com/zhangruichi/cue/blob/main/datasets/imagenet_lt.py): `datasets/imagenet_lt.py`
- [Places-LT](https://github.com/zhangruichi/cue/blob/main/datasets/places_lt.py): `datasets/places_lt.py`

### Modeling

- [CLIP Loading](https://github.com/zhangruichi/cue/blob/main/clip/clip.py): `clip/clip.py`
- [CLIP Backbone](https://github.com/zhangruichi/cue/blob/main/clip/model.py): `clip/model.py`
- [Text Tokenizer](https://github.com/zhangruichi/cue/blob/main/clip/simple_tokenizer.py): `clip/simple_tokenizer.py`
- [Classifier Models](https://github.com/zhangruichi/cue/blob/main/models/models.py): `models/models.py`
- [ViT Adaptation](https://github.com/zhangruichi/cue/blob/main/models/peft_vit.py): `models/peft_vit.py`
- [ResNet Adaptation](https://github.com/zhangruichi/cue/blob/main/models/peft_rn.py): `models/peft_rn.py`
- [Tuning Modules](https://github.com/zhangruichi/cue/blob/main/models/peft_modules.py): `models/peft_modules.py`
- [Classifier Heads](https://github.com/zhangruichi/cue/blob/main/models/classifiers.py): `models/classifiers.py`
- [Prompt Templates](https://github.com/zhangruichi/cue/blob/main/utils/templates.py): `utils/templates.py`

### CUE Supervision

- [Cue Generation](https://github.com/zhangruichi/cue/blob/main/utils/cue_utils.py): `utils/cue_utils.py`
- [LLM Relations](https://github.com/zhangruichi/cue/tree/main/llm_json): `llm_json`
- [Training Losses](https://github.com/zhangruichi/cue/blob/main/utils/losses.py): `utils/losses.py`

### Training and Evaluation

- [CLI Entry](https://github.com/zhangruichi/cue/blob/main/main.py): `main.py`
- [Run Configuration](https://github.com/zhangruichi/cue/blob/main/utils/config.py): `utils/config.py`
- [Trainer](https://github.com/zhangruichi/cue/blob/main/trainer.py): `trainer.py`
- [Class Samplers](https://github.com/zhangruichi/cue/blob/main/utils/samplers.py): `utils/samplers.py`
- [Metrics Evaluator](https://github.com/zhangruichi/cue/blob/main/utils/evaluator.py): `utils/evaluator.py`

### Other components

- **Researcher**

## Connections

- Researcher → CLI Entry: configures run (evidence: `README.md`)
- CLI Entry → Run Configuration: loads settings (evidence: `main.py`)
- CLI Entry → Trainer: starts run (evidence: `main.py`)
- Trainer → Dataset Registry: builds loaders (evidence: `trainer.py`)
- Dataset Registry → CIFAR Long-Tail: selects dataset (evidence: `datasets/__init__.py`)
- Dataset Registry → iNaturalist: selects dataset (evidence: `datasets/__init__.py`)
- Dataset Registry → ImageNet-LT: selects dataset (evidence: `datasets/__init__.py`)
- Dataset Registry → Places-LT: selects dataset (evidence: `datasets/__init__.py`)
- iNaturalist → Image List Dataset: inherits data access (evidence: `datasets/inat2018.py`)
- ImageNet-LT → Image List Dataset: inherits data access (evidence: `datasets/imagenet_lt.py`)
- Places-LT → Image List Dataset: inherits data access (evidence: `datasets/places_lt.py`)
- Trainer → Classifier Models: builds classifier (evidence: `trainer.py`)
- Trainer → CLIP Loading: loads CLIP (evidence: `trainer.py`)
- CLIP Loading → CLIP Backbone: builds backbone (evidence: `clip/clip.py`)
- CLIP Loading → Text Tokenizer: tokenizes text (evidence: `clip/clip.py`)
- Classifier Models → ViT Adaptation: adapts ViT (evidence: `models/models.py`)
- Classifier Models → ResNet Adaptation: adapts ResNet (evidence: `models/models.py`)
- Classifier Models → Classifier Heads: creates head (evidence: `models/models.py`)
- ViT Adaptation → Tuning Modules: uses tuners (evidence: `models/peft_vit.py`)
- ResNet Adaptation → Tuning Modules: uses tuners (evidence: `models/peft_rn.py`)
- Trainer → Cue Generation: generates cues (evidence: `trainer.py`)
- Cue Generation → LLM Relations: reads relations (evidence: `README.md`)
- Trainer → Training Losses: computes objective (evidence: `trainer.py`)
- Trainer → Class Samplers: samples batches (evidence: `trainer.py`)
- Trainer → Prompt Templates: uses prompts (evidence: `trainer.py`)
- Trainer → Metrics Evaluator: evaluates predictions (evidence: `trainer.py`)
- Prompt Templates → CLIP Backbone: encodes class prompts
