# psgame/iim-smcm architecture

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

- Interactive diagram: https://gitdiagram.com/psgame/iim-smcm
- Repository: https://github.com/psgame/iim-smcm

## Overview

This repository implements few-shot out-of-distribution detection with IIM/SMCM-style local prompts, built around a local CLIP model and Dassl training infrastructure. The main workflow prepares ImageNet ID data, trains prompt parameters using global-guided negative augmentation and local regional regularization, then scores ID and OOD images during evaluation. The README describes these method capabilities; sampled source confirms the IIM trainer, CLIP components, dataset handling, and loader utilities, but does not show the complete training or evaluation call paths.

Main entry points: [`eval_ood_detection.py`](https://github.com/psgame/iim-smcm/blob/master/eval_ood_detection.py) (OOD evaluation), [`trainers/iim.py`](https://github.com/psgame/iim-smcm/blob/master/trainers/iim.py) (IIM trainer), [`utils/train_eval_util.py`](https://github.com/psgame/iim-smcm/blob/master/utils/train_eval_util.py) (Image loaders), [`train.py`](https://github.com/psgame/iim-smcm/blob/master/train.py) (Train entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Training and evaluation"]
  node_train["Train entry<br/>[train.py]"]
  node_evaluate["OOD evaluation"]
  node_zero_eval["Zero-shot evaluation"]
  node_scores["Detection scores<br/>[score_function.py]"]
  node_detection_util["Detection utilities<br/>[detection_util.py]"]
end

subgraph group_data["Image data"]
  node_id_data["ImageNet datasets<br/>[imagenet.py]"]
  node_loaders["Image loaders<br/>[train_eval_util.py]"]
  node_dassl_data["Data manager<br/>[data_manager.py]"]
  node_ood_sets["OOD collections<br/>[train_eval_util.py]"]
end

subgraph group_method["IIM method"]
  node_iim["IIM trainer<br/>[iim.py]"]
  node_prompts["Prompt learner<br/>[iim.py]"]
  node_local_loss["Regional objectives<br/>[iim.py]"]
end

subgraph group_runtime["Model runtime"]
  node_trainer_base["Trainer runtime<br/>[trainer.py]"]
  node_clip["Local CLIP<br/>[model.py]"]
  node_clip_loader["CLIP setup<br/>[train_eval_util.py]"]
end

node_user(("Research user"))

node_user -->|"starts training"| node_train
node_user -->|"runs evaluation"| node_evaluate
node_train -->|"requests batches"| node_dassl_data
node_dassl_data -->|"builds dataset"| node_id_data
node_dassl_data -->|"builds loaders"| node_loaders
node_train -->|"selects trainer"| node_iim
node_iim -->|"uses runtime"| node_trainer_base
node_iim -->|"optimizes prompts"| node_prompts
node_prompts -->|"encodes prompts"| node_clip
node_iim -->|"computes objectives"| node_local_loss
node_iim -->|"encodes images"| node_clip
node_evaluate -->|"loads ID images"| node_loaders
node_loaders -->|"reads ID samples"| node_id_data
node_evaluate -->|"loads OOD images"| node_ood_sets
node_evaluate -->|"initializes model"| node_clip_loader
node_clip_loader -->|"loads CLIP"| node_clip
node_evaluate -->|"computes scores"| node_scores
node_evaluate -->|"reports detection"| node_detection_util
node_user -.->|"runs baseline"| node_zero_eval
node_zero_eval -.->|"loads validation data"| node_loaders
node_zero_eval -.->|"initializes model"| node_clip_loader

click node_train "https://github.com/psgame/iim-smcm/blob/master/train.py"
click node_evaluate "https://github.com/psgame/iim-smcm/blob/master/eval_ood_detection.py"
click node_zero_eval "https://github.com/psgame/iim-smcm/blob/master/eval_ood_detection_zero_shot.py"
click node_id_data "https://github.com/psgame/iim-smcm/blob/master/datasets/imagenet.py"
click node_loaders "https://github.com/psgame/iim-smcm/blob/master/utils/train_eval_util.py"
click node_dassl_data "https://github.com/psgame/iim-smcm/blob/master/Dassl/dassl/data/data_manager.py"
click node_ood_sets "https://github.com/psgame/iim-smcm/blob/master/utils/train_eval_util.py"
click node_iim "https://github.com/psgame/iim-smcm/blob/master/trainers/iim.py"
click node_prompts "https://github.com/psgame/iim-smcm/blob/master/trainers/iim.py"
click node_local_loss "https://github.com/psgame/iim-smcm/blob/master/trainers/iim.py"
click node_trainer_base "https://github.com/psgame/iim-smcm/blob/master/Dassl/dassl/engine/trainer.py"
click node_clip "https://github.com/psgame/iim-smcm/blob/master/clip_w_local/model.py"
click node_clip_loader "https://github.com/psgame/iim-smcm/blob/master/utils/train_eval_util.py"
click node_scores "https://github.com/psgame/iim-smcm/blob/master/trainers/utils/score_function.py"
click node_detection_util "https://github.com/psgame/iim-smcm/blob/master/utils/detection_util.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_train,node_evaluate,node_zero_eval,node_scores,node_detection_util,node_user toneBlue
class node_id_data,node_loaders,node_dassl_data,node_ood_sets toneAmber
class node_iim,node_prompts,node_local_loss toneMint
class node_trainer_base,node_clip,node_clip_loader toneRose
```

## Components

### Training and evaluation

- [Train entry](https://github.com/psgame/iim-smcm/blob/master/train.py): `train.py`
- [OOD evaluation](https://github.com/psgame/iim-smcm/blob/master/eval_ood_detection.py): `eval_ood_detection.py`
- [Zero-shot evaluation](https://github.com/psgame/iim-smcm/blob/master/eval_ood_detection_zero_shot.py): `eval_ood_detection_zero_shot.py`
- [Detection scores](https://github.com/psgame/iim-smcm/blob/master/trainers/utils/score_function.py): `trainers/utils/score_function.py`
- [Detection utilities](https://github.com/psgame/iim-smcm/blob/master/utils/detection_util.py): `utils/detection_util.py`

### Image data

- [ImageNet datasets](https://github.com/psgame/iim-smcm/blob/master/datasets/imagenet.py): `datasets/imagenet.py`
- [Image loaders](https://github.com/psgame/iim-smcm/blob/master/utils/train_eval_util.py): `utils/train_eval_util.py`
- [Data manager](https://github.com/psgame/iim-smcm/blob/master/Dassl/dassl/data/data_manager.py): `Dassl/dassl/data/data_manager.py`
- [OOD collections](https://github.com/psgame/iim-smcm/blob/master/utils/train_eval_util.py): `utils/train_eval_util.py`

### IIM method

- [IIM trainer](https://github.com/psgame/iim-smcm/blob/master/trainers/iim.py): `trainers/iim.py`
- [Prompt learner](https://github.com/psgame/iim-smcm/blob/master/trainers/iim.py): `trainers/iim.py`
- [Regional objectives](https://github.com/psgame/iim-smcm/blob/master/trainers/iim.py): `trainers/iim.py`

### Model runtime

- [Trainer runtime](https://github.com/psgame/iim-smcm/blob/master/Dassl/dassl/engine/trainer.py): `Dassl/dassl/engine/trainer.py`
- [Local CLIP](https://github.com/psgame/iim-smcm/blob/master/clip_w_local/model.py): `clip_w_local/model.py`
- [CLIP setup](https://github.com/psgame/iim-smcm/blob/master/utils/train_eval_util.py): `utils/train_eval_util.py`

### Other components

- **Research user**

## Connections

- Research user → Train entry: starts training
- Research user → OOD evaluation: runs evaluation
- Train entry → Data manager: requests batches
- Data manager → ImageNet datasets: builds dataset
- Data manager → Image loaders: builds loaders
- Train entry → IIM trainer: selects trainer
- IIM trainer → Trainer runtime: uses runtime
- IIM trainer → Prompt learner: optimizes prompts
- Prompt learner → Local CLIP: encodes prompts
- IIM trainer → Regional objectives: computes objectives
- IIM trainer → Local CLIP: encodes images
- OOD evaluation → Image loaders: loads ID images
- Image loaders → ImageNet datasets: reads ID samples
- OOD evaluation → OOD collections: loads OOD images
- OOD evaluation → CLIP setup: initializes model
- CLIP setup → Local CLIP: loads CLIP
- OOD evaluation → Detection scores: computes scores
- OOD evaluation → Detection utilities: reports detection
- Research user → Zero-shot evaluation: runs baseline
- Zero-shot evaluation → Image loaders: loads validation data
- Zero-shot evaluation → CLIP setup: initializes model
