# mr-eggplant/sar architecture

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

- Interactive diagram: https://gitdiagram.com/mr-eggplant/sar
- Repository: https://github.com/mr-eggplant/sar

## Overview

This repository evaluates test-time adaptation methods on ImageNet-C streams. The principal workflow is: configure an experiment, prepare corruption data (and optionally impose label-shift ordering), run inference with no adaptation or an adaptation wrapper, then report accuracy. SAR is the central method; Tent and EATA are documented alternatives. The graph retains the model, data-preparation, and metric layers. Main-to-method dispatch is partly unsampled; those links rely on main.py’s indexed references rather than inspected branch code.

Main entry points: [`main.py`](https://github.com/mr-eggplant/sar/blob/main/main.py) (Experiment runner), [`dataset/generate_shifted_sample_indices.py`](https://github.com/mr-eggplant/sar/blob/main/dataset/generate_shifted_sample_indices.py) (Shifted ordering), [`sar.py`](https://github.com/mr-eggplant/sar/blob/main/sar.py) (SAR), [`dataset/selectedRotateImageFolder.py`](https://github.com/mr-eggplant/sar/blob/main/dataset/selectedRotateImageFolder.py) (Corruption loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experiment["Experiment runner"]
  node_runner["Experiment runner<br/>[main.py]"]
end

subgraph group_data["Test data"]
  node_testdata["Corruption loader"]
  node_shiftindices["Shifted ordering"]
  node_shiftfiles["Order arrays"]
end

subgraph group_adapt["Adaptation methods"]
  node_baseline["No adaptation<br/>[main.py]"]
  node_tent["Tent<br/>[tent.py]"]
  node_eata["EATA<br/>[eata.py]"]
  node_sar["SAR<br/>[sar.py]"]
  node_sam["SAM optimizer<br/>[sam.py]"]
end

subgraph group_runtime["Models and metrics"]
  node_resnet["ResNet model<br/>[Res.py]"]
  node_metrics["Accuracy metrics<br/>[cli_utils.py]"]
  node_helpers["Experiment utilities<br/>[utils.py]"]
end

node_engineer(("Experiment user"))

node_engineer -->|"runs experiment"| node_runner
node_runner -->|"prepares data"| node_testdata
node_runner -.->|"generates ordering"| node_shiftindices
node_shiftindices -->|"saves indices"| node_shiftfiles
node_runner -->|"evaluates directly"| node_baseline
node_runner -->|"configures and evaluates"| node_tent
node_runner -.->|"dispatches method"| node_eata
node_runner -.->|"dispatches method"| node_sar
node_runner -.->|"selects model"| node_resnet
node_runner -.->|"validates accuracy"| node_metrics
node_runner -->|"gets logger"| node_helpers
node_sar -->|"uses optimizer"| node_sam

click node_runner "https://github.com/mr-eggplant/sar/blob/main/main.py"
click node_testdata "https://github.com/mr-eggplant/sar/blob/main/dataset/selectedRotateImageFolder.py"
click node_shiftindices "https://github.com/mr-eggplant/sar/blob/main/dataset/generate_shifted_sample_indices.py"
click node_shiftfiles "https://github.com/mr-eggplant/sar/tree/main/dataset"
click node_baseline "https://github.com/mr-eggplant/sar/blob/main/main.py"
click node_tent "https://github.com/mr-eggplant/sar/blob/main/tent.py"
click node_eata "https://github.com/mr-eggplant/sar/blob/main/eata.py"
click node_sar "https://github.com/mr-eggplant/sar/blob/main/sar.py"
click node_sam "https://github.com/mr-eggplant/sar/blob/main/sam.py"
click node_resnet "https://github.com/mr-eggplant/sar/blob/main/models/Res.py"
click node_metrics "https://github.com/mr-eggplant/sar/blob/main/utils/cli_utils.py"
click node_helpers "https://github.com/mr-eggplant/sar/blob/main/utils/utils.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_runner,node_engineer toneBlue
class node_testdata,node_shiftindices,node_shiftfiles toneAmber
class node_baseline,node_tent,node_eata,node_sar,node_sam toneMint
class node_resnet,node_metrics,node_helpers toneRose
```

## Components

### Experiment runner

- [Experiment runner](https://github.com/mr-eggplant/sar/blob/main/main.py): `main.py`

### Test data

- [Corruption loader](https://github.com/mr-eggplant/sar/blob/main/dataset/selectedRotateImageFolder.py): `dataset/selectedRotateImageFolder.py`
- [Shifted ordering](https://github.com/mr-eggplant/sar/blob/main/dataset/generate_shifted_sample_indices.py): `dataset/generate_shifted_sample_indices.py`
- [Order arrays](https://github.com/mr-eggplant/sar/tree/main/dataset): `dataset`

### Adaptation methods

- [No adaptation](https://github.com/mr-eggplant/sar/blob/main/main.py): `main.py`
- [Tent](https://github.com/mr-eggplant/sar/blob/main/tent.py): `tent.py`
- [EATA](https://github.com/mr-eggplant/sar/blob/main/eata.py): `eata.py`
- [SAR](https://github.com/mr-eggplant/sar/blob/main/sar.py): `sar.py`
- [SAM optimizer](https://github.com/mr-eggplant/sar/blob/main/sam.py): `sam.py`

### Models and metrics

- [ResNet model](https://github.com/mr-eggplant/sar/blob/main/models/Res.py): `models/Res.py`
- [Accuracy metrics](https://github.com/mr-eggplant/sar/blob/main/utils/cli_utils.py): `utils/cli_utils.py`
- [Experiment utilities](https://github.com/mr-eggplant/sar/blob/main/utils/utils.py): `utils/utils.py`

### Other components

- **Experiment user**

## Connections

- Experiment user → Experiment runner: runs experiment (evidence: `README.md`)
- Experiment runner → Corruption loader: prepares data (evidence: `main.py`)
- Experiment runner → Shifted ordering: generates ordering
- Shifted ordering → Order arrays: saves indices (evidence: `dataset/generate_shifted_sample_indices.py`)
- Experiment runner → No adaptation: evaluates directly (evidence: `main.py`)
- Experiment runner → Tent: configures and evaluates (evidence: `main.py`)
- Experiment runner → EATA: dispatches method (evidence: `main.py`)
- Experiment runner → SAR: dispatches method (evidence: `main.py`)
- Experiment runner → ResNet model: selects model (evidence: `main.py`)
- Experiment runner → Accuracy metrics: validates accuracy (evidence: `main.py`)
- Experiment runner → Experiment utilities: gets logger (evidence: `main.py`)
- SAR → SAM optimizer: uses optimizer (evidence: `README.md`)
