# leizan/cbramod_homework architecture

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

- Interactive diagram: https://gitdiagram.com/leizan/cbramod_homework
- Repository: https://github.com/leizan/cbramod_homework

## Overview

This repository supports SHU-MI EEG experiments comparing a pretrained CBraMod model with an EEGSimpleConv baseline. The documented workflow preprocesses MAT trials into LMDB, loads train/validation/test splits, fine-tunes a selected model, and evaluates results; the notebook also documents comparisons, data-efficiency experiments, and inference-time measurements. Source excerpts show the training and model call structure. Notebook and configuration links rely on README statements; the dataset preprocessing and persisted-result details are documented rather than fully sampled.

Main entry points: [`finetune_main.py`](https://github.com/leizan/cbramod_homework/blob/main/finetune_main.py) (Experiment runner), [`models/CBraMod/model_for_shu.py`](https://github.com/leizan/cbramod_homework/blob/main/models/CBraMod/model_for_shu.py) (CBraMod SHU adapter), [`preprocessing/preprocessing_shu.py`](https://github.com/leizan/cbramod_homework/blob/main/preprocessing/preprocessing_shu.py) (Trial preprocessing), [`preprocessing/shu_dataset.py`](https://github.com/leizan/cbramod_homework/blob/main/preprocessing/shu_dataset.py) (Split data loaders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["EEG Data"]
  node_shu_mat["SHU-MI MAT"]
  node_preprocess["Trial preprocessing"]
  node_lmdb[("Processed LMDB")]
  node_dataset["Split data loaders<br/>[shu_dataset.py]"]
  node_tensor_utils["Tensor conversion<br/>[util.py]"]
end

subgraph group_models["Model Architectures"]
  node_cbra_adapter["CBraMod SHU adapter<br/>[model_for_shu.py]"]
  node_cbra["CBraMod backbone<br/>[cbramod.py]"]
  node_transformer["Criss-cross transformer"]
  node_simple_adapter["EEGSimpleConv SHU adapter"]
  node_simpleconv["EEGSimpleConv network<br/>[EEGSimpleConv.py]"]
  node_resample["Same-rate resampling"]
  node_checkpoint["Pretrained checkpoint"]
end

subgraph group_training["Fine-tuning"]
  node_main["Experiment runner<br/>[finetune_main.py]"]
  node_trainer["Training and selection"]
  node_evaluator["Metric evaluation"]
end

subgraph group_experiments["Experiments"]
  node_configs["Model configurations"]
  node_notebook["Experiment notebook<br/>[CBraMod.ipynb]"]
end

node_researcher(("Researcher"))

node_researcher -->|"runs experiments"| node_notebook
node_researcher -->|"prepares data"| node_preprocess
node_shu_mat -->|"provides trials"| node_preprocess
node_preprocess -->|"writes processed trials"| node_lmdb
node_lmdb -->|"supplies splits"| node_dataset
node_dataset -->|"converts batches"| node_tensor_utils
node_main -->|"loads splits"| node_dataset
node_main -->|"starts training"| node_trainer
node_main -->|"selects CBraMod"| node_cbra_adapter
node_main -->|"selects baseline"| node_simple_adapter
node_trainer -->|"evaluates models"| node_evaluator
node_cbra_adapter -->|"runs backbone"| node_cbra
node_cbra -->|"uses encoder"| node_transformer
node_cbra_adapter -->|"loads weights"| node_checkpoint
node_simple_adapter -->|"adapts inputs"| node_simpleconv
node_simpleconv -->|"resamples input"| node_resample
node_configs -->|"configures runs"| node_notebook
node_notebook -.->|"documents training"| node_main

click node_preprocess "https://github.com/leizan/cbramod_homework/blob/main/preprocessing/preprocessing_shu.py"
click node_dataset "https://github.com/leizan/cbramod_homework/blob/main/preprocessing/shu_dataset.py"
click node_tensor_utils "https://github.com/leizan/cbramod_homework/blob/main/utils/util.py"
click node_main "https://github.com/leizan/cbramod_homework/blob/main/finetune_main.py"
click node_trainer "https://github.com/leizan/cbramod_homework/blob/main/finetune_trainer.py"
click node_evaluator "https://github.com/leizan/cbramod_homework/blob/main/finetune_evaluator.py"
click node_cbra_adapter "https://github.com/leizan/cbramod_homework/blob/main/models/CBraMod/model_for_shu.py"
click node_cbra "https://github.com/leizan/cbramod_homework/blob/main/models/CBraMod/cbramod.py"
click node_transformer "https://github.com/leizan/cbramod_homework/blob/main/models/CBraMod/criss_cross_transformer.py"
click node_simple_adapter "https://github.com/leizan/cbramod_homework/blob/main/models/EEGSimpleConv/model_for_shu_simpleconv.py"
click node_simpleconv "https://github.com/leizan/cbramod_homework/blob/main/models/EEGSimpleConv/EEGSimpleConv.py"
click node_resample "https://github.com/leizan/cbramod_homework/blob/main/models/EEGSimpleConv/simpleconv_resample.py"
click node_checkpoint "https://github.com/leizan/cbramod_homework/blob/main/models/model_weights/CBraMod/pretrained_weights.pth"
click node_configs "https://github.com/leizan/cbramod_homework/tree/main/configs"
click node_notebook "https://github.com/leizan/cbramod_homework/blob/main/CBraMod.ipynb"

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_shu_mat,node_preprocess,node_lmdb,node_dataset,node_tensor_utils toneBlue
class node_cbra_adapter,node_cbra,node_transformer,node_simple_adapter,node_simpleconv,node_resample,node_checkpoint toneAmber
class node_main,node_trainer,node_evaluator toneMint
class node_configs,node_notebook toneRose
class node_researcher toneIndigo
```

## Components

### EEG Data

- **SHU-MI MAT**
- [Trial preprocessing](https://github.com/leizan/cbramod_homework/blob/main/preprocessing/preprocessing_shu.py): `preprocessing/preprocessing_shu.py`
- **Processed LMDB**
- [Split data loaders](https://github.com/leizan/cbramod_homework/blob/main/preprocessing/shu_dataset.py): `preprocessing/shu_dataset.py`
- [Tensor conversion](https://github.com/leizan/cbramod_homework/blob/main/utils/util.py): `utils/util.py`

### Model Architectures

- [CBraMod SHU adapter](https://github.com/leizan/cbramod_homework/blob/main/models/CBraMod/model_for_shu.py): `models/CBraMod/model_for_shu.py`
- [CBraMod backbone](https://github.com/leizan/cbramod_homework/blob/main/models/CBraMod/cbramod.py): `models/CBraMod/cbramod.py`
- [Criss-cross transformer](https://github.com/leizan/cbramod_homework/blob/main/models/CBraMod/criss_cross_transformer.py): `models/CBraMod/criss_cross_transformer.py`
- [EEGSimpleConv SHU adapter](https://github.com/leizan/cbramod_homework/blob/main/models/EEGSimpleConv/model_for_shu_simpleconv.py): `models/EEGSimpleConv/model_for_shu_simpleconv.py`
- [EEGSimpleConv network](https://github.com/leizan/cbramod_homework/blob/main/models/EEGSimpleConv/EEGSimpleConv.py): `models/EEGSimpleConv/EEGSimpleConv.py`
- [Same-rate resampling](https://github.com/leizan/cbramod_homework/blob/main/models/EEGSimpleConv/simpleconv_resample.py): `models/EEGSimpleConv/simpleconv_resample.py`
- [Pretrained checkpoint](https://github.com/leizan/cbramod_homework/blob/main/models/model_weights/CBraMod/pretrained_weights.pth): `models/model_weights/CBraMod/pretrained_weights.pth`

### Fine-tuning

- [Experiment runner](https://github.com/leizan/cbramod_homework/blob/main/finetune_main.py): `finetune_main.py`
- [Training and selection](https://github.com/leizan/cbramod_homework/blob/main/finetune_trainer.py): `finetune_trainer.py`
- [Metric evaluation](https://github.com/leizan/cbramod_homework/blob/main/finetune_evaluator.py): `finetune_evaluator.py`

### Experiments

- [Model configurations](https://github.com/leizan/cbramod_homework/tree/main/configs): `configs`
- [Experiment notebook](https://github.com/leizan/cbramod_homework/blob/main/CBraMod.ipynb): `CBraMod.ipynb`

### Other components

- **Researcher**

## Connections

- Researcher → Experiment notebook: runs experiments (evidence: `README.md`)
- Researcher → Trial preprocessing: prepares data (evidence: `README.md`)
- SHU-MI MAT → Trial preprocessing: provides trials (evidence: `README.md`)
- Trial preprocessing → Processed LMDB: writes processed trials (evidence: `README.md`)
- Processed LMDB → Split data loaders: supplies splits (evidence: `preprocessing/shu_dataset.py`)
- Split data loaders → Tensor conversion: converts batches (evidence: `preprocessing/shu_dataset.py`)
- Experiment runner → Split data loaders: loads splits (evidence: `finetune_main.py`)
- Experiment runner → Training and selection: starts training (evidence: `finetune_main.py`)
- Experiment runner → CBraMod SHU adapter: selects CBraMod (evidence: `finetune_main.py`)
- Experiment runner → EEGSimpleConv SHU adapter: selects baseline (evidence: `finetune_main.py`)
- Training and selection → Metric evaluation: evaluates models (evidence: `finetune_trainer.py`)
- CBraMod SHU adapter → CBraMod backbone: runs backbone (evidence: `models/CBraMod/model_for_shu.py`)
- CBraMod backbone → Criss-cross transformer: uses encoder (evidence: `models/CBraMod/cbramod.py`)
- CBraMod SHU adapter → Pretrained checkpoint: loads weights (evidence: `models/CBraMod/model_for_shu.py`)
- EEGSimpleConv SHU adapter → EEGSimpleConv network: adapts inputs (evidence: `models/EEGSimpleConv/model_for_shu_simpleconv.py`)
- EEGSimpleConv network → Same-rate resampling: resamples input (evidence: `models/EEGSimpleConv/EEGSimpleConv.py`)
- Model configurations → Experiment notebook: configures runs (evidence: `README.md`)
- Experiment notebook → Experiment runner: documents training (evidence: `README.md`)
