# damidirad/ai4mi_project architecture

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

- Interactive diagram: https://gitdiagram.com/damidirad/ai4mi_project
- Repository: https://github.com/damidirad/ai4mi_project

## Overview

This repository is a SegTHOR medical-image segmentation project. Its user workflow is to prepare 3D CT data as 2D slices or tiles, train a segmentation network, then inspect predictions and metrics; an optional tiled route evaluates reconstructed volumes in original geometry. The graph preserves both the documented baseline features and the tiled extensions visible in the tree. Some implementation links are dashed because the relevant call sites were not included in the excerpts.

Main entry points: [`main.py`](https://github.com/damidirad/ai4mi_project/blob/master/main.py) (Baseline training), [`slice_segthor.py`](https://github.com/damidirad/ai4mi_project/blob/master/slice_segthor.py) (Slice preprocessing), [`train_tiled.py`](https://github.com/damidirad/ai4mi_project/blob/master/train_tiled.py) (Tiled training), [`tiled_dataset.py`](https://github.com/damidirad/ai4mi_project/blob/master/tiled_dataset.py) (Tiled dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Data preparation"]
  node_slice["Slice preprocessing<br/>[slice_segthor.py]"]
  node_toy["Synthetic data<br/>[gen_two_circles.py]"]
  node_geometry["Voxel geometry<br/>[geometry.py]"]
  node_metadata["Preprocessing metadata"]
  node_tiling["Tile layout and writing<br/>[tiling.py]"]
  node_slice_data["Slice dataset<br/>[dataset.py]"]
  node_tile_data["Tiled dataset<br/>[tiled_dataset.py]"]
end

subgraph group_models["Segmentation models"]
  node_enet["ENet<br/>[ENet.py]"]
  node_enet25["2.5D ENet<br/>[ENet_2_5d.py]"]
  node_shallow["ShallowNet<br/>[ShallowNet.py]"]
end

subgraph group_training["Training and evaluation"]
  node_baseline["Baseline training<br/>[main.py]"]
  node_loss["Segmentation losses<br/>[losses.py]"]
  node_tile_train["Tiled training<br/>[train_tiled.py]"]
  node_tile_loss["Tiled losses<br/>[tiled_losses.py]"]
  node_tile_eval["Volume evaluation<br/>[evaluate_tiled.py]"]
end

subgraph group_analysis["Results and geometry"]
  node_reconstruct["Tile reconstruction"]
  node_stitch["Slice stitching<br/>[stitch.py]"]
  node_viewer["Segmentation viewer"]
  node_plots["Metric plotting<br/>[plot_metrics.py]"]
  node_utils["Metrics and utilities<br/>[utils.py]"]
end

node_user(("Researcher"))
node_source_data[("CT volumes")]

node_user -->|"prepares data"| node_slice
node_source_data -.->|"reads volumes"| node_slice
node_user -->|"generates toy data"| node_toy
node_slice -.->|"uses geometry"| node_geometry
node_slice -.->|"records geometry"| node_metadata
node_slice -.->|"writes tiles"| node_tiling
node_user -->|"trains model"| node_baseline
node_baseline -.->|"loads slices"| node_slice_data
node_baseline -.->|"selects network"| node_enet
node_baseline -.->|"selects network"| node_enet25
node_baseline -.->|"selects network"| node_shallow
node_baseline -.->|"uses loss"| node_loss
node_baseline -->|"dispatches tiled"| node_tile_train
node_tile_train -.->|"builds datasets"| node_tile_data
node_tile_train -.->|"builds losses"| node_tile_loss
node_tile_train -.->|"validates volumes"| node_tile_eval
node_tile_data -.->|"loads records"| node_metadata
node_tile_data -.->|"uses layout"| node_tiling
node_tile_eval -.->|"restores grid"| node_geometry
node_tile_eval -.->|"validates geometry"| node_metadata
node_user -.->|"reconstructs tiles"| node_reconstruct
node_user -->|"stitches slices"| node_stitch
node_user -->|"compares predictions"| node_viewer
node_user -->|"plots metrics"| node_plots
node_baseline -.->|"uses metrics"| node_utils

click node_slice "https://github.com/damidirad/ai4mi_project/blob/master/slice_segthor.py"
click node_toy "https://github.com/damidirad/ai4mi_project/blob/master/gen_two_circles.py"
click node_geometry "https://github.com/damidirad/ai4mi_project/blob/master/geometry.py"
click node_metadata "https://github.com/damidirad/ai4mi_project/blob/master/preprocessing_metadata.py"
click node_tiling "https://github.com/damidirad/ai4mi_project/blob/master/tiling.py"
click node_slice_data "https://github.com/damidirad/ai4mi_project/blob/master/dataset.py"
click node_tile_data "https://github.com/damidirad/ai4mi_project/blob/master/tiled_dataset.py"
click node_enet "https://github.com/damidirad/ai4mi_project/blob/master/ENet.py"
click node_enet25 "https://github.com/damidirad/ai4mi_project/blob/master/ENet_2_5d.py"
click node_shallow "https://github.com/damidirad/ai4mi_project/blob/master/ShallowNet.py"
click node_baseline "https://github.com/damidirad/ai4mi_project/blob/master/main.py"
click node_loss "https://github.com/damidirad/ai4mi_project/blob/master/losses.py"
click node_tile_train "https://github.com/damidirad/ai4mi_project/blob/master/train_tiled.py"
click node_tile_loss "https://github.com/damidirad/ai4mi_project/blob/master/tiled_losses.py"
click node_tile_eval "https://github.com/damidirad/ai4mi_project/blob/master/evaluate_tiled.py"
click node_reconstruct "https://github.com/damidirad/ai4mi_project/blob/master/reconstruct_tiled.py"
click node_stitch "https://github.com/damidirad/ai4mi_project/blob/master/stitch.py"
click node_plots "https://github.com/damidirad/ai4mi_project/blob/master/plot_metrics.py"
click node_utils "https://github.com/damidirad/ai4mi_project/blob/master/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_slice,node_toy,node_geometry,node_metadata,node_tiling,node_slice_data,node_tile_data toneBlue
class node_enet,node_enet25,node_shallow,node_source_data toneAmber
class node_baseline,node_loss,node_tile_train,node_tile_loss,node_tile_eval toneMint
class node_reconstruct,node_stitch,node_viewer,node_plots,node_utils toneRose
class node_user toneIndigo
```

## Components

### Data preparation

- [Slice preprocessing](https://github.com/damidirad/ai4mi_project/blob/master/slice_segthor.py): `slice_segthor.py`
- [Synthetic data](https://github.com/damidirad/ai4mi_project/blob/master/gen_two_circles.py): `gen_two_circles.py`
- [Voxel geometry](https://github.com/damidirad/ai4mi_project/blob/master/geometry.py): `geometry.py`
- [Preprocessing metadata](https://github.com/damidirad/ai4mi_project/blob/master/preprocessing_metadata.py): `preprocessing_metadata.py`
- [Tile layout and writing](https://github.com/damidirad/ai4mi_project/blob/master/tiling.py): `tiling.py`
- [Slice dataset](https://github.com/damidirad/ai4mi_project/blob/master/dataset.py): `dataset.py`
- [Tiled dataset](https://github.com/damidirad/ai4mi_project/blob/master/tiled_dataset.py): `tiled_dataset.py`

### Segmentation models

- [ENet](https://github.com/damidirad/ai4mi_project/blob/master/ENet.py): `ENet.py`
- [2.5D ENet](https://github.com/damidirad/ai4mi_project/blob/master/ENet_2_5d.py): `ENet_2_5d.py`
- [ShallowNet](https://github.com/damidirad/ai4mi_project/blob/master/ShallowNet.py): `ShallowNet.py`

### Training and evaluation

- [Baseline training](https://github.com/damidirad/ai4mi_project/blob/master/main.py): `main.py`
- [Segmentation losses](https://github.com/damidirad/ai4mi_project/blob/master/losses.py): `losses.py`
- [Tiled training](https://github.com/damidirad/ai4mi_project/blob/master/train_tiled.py): `train_tiled.py`
- [Tiled losses](https://github.com/damidirad/ai4mi_project/blob/master/tiled_losses.py): `tiled_losses.py`
- [Volume evaluation](https://github.com/damidirad/ai4mi_project/blob/master/evaluate_tiled.py): `evaluate_tiled.py`

### Results and geometry

- [Tile reconstruction](https://github.com/damidirad/ai4mi_project/blob/master/reconstruct_tiled.py): `reconstruct_tiled.py`
- [Slice stitching](https://github.com/damidirad/ai4mi_project/blob/master/stitch.py): `stitch.py`
- **Segmentation viewer**
- [Metric plotting](https://github.com/damidirad/ai4mi_project/blob/master/plot_metrics.py): `plot_metrics.py`
- [Metrics and utilities](https://github.com/damidirad/ai4mi_project/blob/master/utils.py): `utils.py`

### Other components

- **Researcher**
- **CT volumes**

## Connections

- Researcher → Slice preprocessing: prepares data (evidence: `readme.md`)
- CT volumes → Slice preprocessing: reads volumes
- Researcher → Synthetic data: generates toy data (evidence: `readme.md`)
- Slice preprocessing → Voxel geometry: uses geometry (evidence: `slice_segthor.py`)
- Slice preprocessing → Preprocessing metadata: records geometry (evidence: `slice_segthor.py`)
- Slice preprocessing → Tile layout and writing: writes tiles (evidence: `slice_segthor.py`)
- Researcher → Baseline training: trains model (evidence: `readme.md`)
- Baseline training → Slice dataset: loads slices (evidence: `main.py`)
- Baseline training → ENet: selects network (evidence: `main.py`)
- Baseline training → 2.5D ENet: selects network (evidence: `main.py`)
- Baseline training → ShallowNet: selects network (evidence: `main.py`)
- Baseline training → Segmentation losses: uses loss (evidence: `main.py`)
- Baseline training → Tiled training: dispatches tiled (evidence: `main.py`)
- Tiled training → Tiled dataset: builds datasets
- Tiled training → Tiled losses: builds losses (evidence: `train_tiled.py`)
- Tiled training → Volume evaluation: validates volumes (evidence: `train_tiled.py`)
- Tiled dataset → Preprocessing metadata: loads records (evidence: `tiled_dataset.py`)
- Tiled dataset → Tile layout and writing: uses layout (evidence: `tiled_dataset.py`)
- Volume evaluation → Voxel geometry: restores grid (evidence: `evaluate_tiled.py`)
- Volume evaluation → Preprocessing metadata: validates geometry (evidence: `evaluate_tiled.py`)
- Researcher → Tile reconstruction: reconstructs tiles
- Researcher → Slice stitching: stitches slices (evidence: `readme.md`)
- Researcher → Segmentation viewer: compares predictions (evidence: `readme.md`)
- Researcher → Metric plotting: plots metrics (evidence: `readme.md`)
- Baseline training → Metrics and utilities: uses metrics (evidence: `main.py`)
