# brianshih95/deep-learning-for-medical-imaging architecture

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

- Interactive diagram: https://gitdiagram.com/brianshih95/deep-learning-for-medical-imaging
- Repository: https://github.com/brianshih95/deep-learning-for-medical-imaging

## Overview

This repository contains two MRI brain-tumor segmentation implementations: a U-Net baseline and a Segment Anything Model (SAM) variant. Their principal workflow is to find image/mask pairs, split them by patient, prepare datasets, train and evaluate segmentation models, and save visualizations and checkpoints. The source excerpts support those flows but not the contents of the hw2 notebook, so it is shown without inferred connections.

Main entry points: [`hw1/src/unet.py`](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py) (U-Net training), [`hw1/src/sam.py`](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py) (SAM training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_unet_pairing["Pair images and masks<br/>[unet.py]"]
  node_unet_split["Patient-level split<br/>[unet.py]"]
  node_unet_dataset["U-Net dataset<br/>[unet.py]"]
  node_sam_pairing["Pair images and masks<br/>[sam.py]"]
  node_sam_split["Patient-level split<br/>[sam.py]"]
  node_sam_dataset["SAM dataset<br/>[sam.py]"]
end

subgraph group_models["Segmentation models"]
  node_unet_model["U-Net model<br/>[unet.py]"]
  node_sam_model["SAM model<br/>[sam.py]"]
end

subgraph group_evaluation["Training and evaluation"]
  node_unet_training["U-Net training<br/>[unet.py]"]
  node_sam_training["SAM training<br/>[sam.py]"]
  node_unet_metrics["Loss and metrics<br/>[unet.py]"]
  node_sam_metrics["Loss and metrics<br/>[sam.py]"]
  node_unet_outputs["Checkpoints and plots<br/>[unet.py]"]
  node_sam_outputs["Checkpoints and plots<br/>[sam.py]"]
end

subgraph group_notebook["Notebook work"]
  node_hw2_notebook["Notebook workflow<br/>[main.ipynb]"]
end

node_dataset_files[("MRI image-mask files")]

node_dataset_files -->|"scans files"| node_unet_pairing
node_unet_pairing -->|"passes pairs"| node_unet_split
node_unet_split -->|"creates splits"| node_unet_dataset
node_unet_dataset -->|"feeds batches"| node_unet_training
node_unet_training -->|"trains model"| node_unet_model
node_unet_training -->|"computes scores"| node_unet_metrics
node_unet_training -->|"saves results"| node_unet_outputs
node_dataset_files -->|"scans files"| node_sam_pairing
node_sam_pairing -->|"passes pairs"| node_sam_split
node_sam_split -->|"creates splits"| node_sam_dataset
node_sam_dataset -->|"feeds batches"| node_sam_training
node_sam_training -->|"trains model"| node_sam_model
node_sam_training -->|"computes scores"| node_sam_metrics
node_sam_training -->|"saves results"| node_sam_outputs

click node_unet_pairing "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py"
click node_unet_split "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py"
click node_unet_dataset "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py"
click node_sam_pairing "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py"
click node_sam_split "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py"
click node_sam_dataset "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py"
click node_unet_model "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py"
click node_sam_model "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py"
click node_unet_training "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py"
click node_sam_training "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py"
click node_unet_metrics "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py"
click node_sam_metrics "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py"
click node_unet_outputs "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py"
click node_sam_outputs "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py"
click node_hw2_notebook "https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw2/src/main.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_unet_pairing,node_unet_split,node_unet_dataset,node_sam_pairing,node_sam_split,node_sam_dataset toneBlue
class node_unet_model,node_sam_model,node_dataset_files toneAmber
class node_unet_training,node_sam_training,node_unet_metrics,node_sam_metrics,node_unet_outputs,node_sam_outputs toneMint
class node_hw2_notebook toneRose
```

## Components

### Data preparation

- [Pair images and masks](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py): `hw1/src/unet.py`
- [Patient-level split](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py): `hw1/src/unet.py`
- [U-Net dataset](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py): `hw1/src/unet.py`
- [Pair images and masks](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py): `hw1/src/sam.py`
- [Patient-level split](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py): `hw1/src/sam.py`
- [SAM dataset](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py): `hw1/src/sam.py`

### Segmentation models

- [U-Net model](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py): `hw1/src/unet.py`
- [SAM model](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py): `hw1/src/sam.py`

### Training and evaluation

- [U-Net training](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py): `hw1/src/unet.py`
- [SAM training](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py): `hw1/src/sam.py`
- [Loss and metrics](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py): `hw1/src/unet.py`
- [Loss and metrics](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py): `hw1/src/sam.py`
- [Checkpoints and plots](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/unet.py): `hw1/src/unet.py`
- [Checkpoints and plots](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw1/src/sam.py): `hw1/src/sam.py`

### Notebook work

- [Notebook workflow](https://github.com/brianshih95/deep-learning-for-medical-imaging/blob/main/hw2/src/main.ipynb): `hw2/src/main.ipynb`

### Other components

- **MRI image-mask files**

## Connections

- MRI image-mask files → Pair images and masks: scans files (evidence: `hw1/src/unet.py`)
- Pair images and masks → Patient-level split: passes pairs (evidence: `hw1/src/unet.py`)
- Patient-level split → U-Net dataset: creates splits (evidence: `hw1/src/unet.py`)
- U-Net dataset → U-Net training: feeds batches (evidence: `hw1/src/unet.py`)
- U-Net training → U-Net model: trains model (evidence: `hw1/src/unet.py`)
- U-Net training → Loss and metrics: computes scores (evidence: `hw1/src/unet.py`)
- U-Net training → Checkpoints and plots: saves results (evidence: `hw1/src/unet.py`)
- MRI image-mask files → Pair images and masks: scans files (evidence: `hw1/src/sam.py`)
- Pair images and masks → Patient-level split: passes pairs (evidence: `hw1/src/sam.py`)
- Patient-level split → SAM dataset: creates splits (evidence: `hw1/src/sam.py`)
- SAM dataset → SAM training: feeds batches (evidence: `hw1/src/sam.py`)
- SAM training → SAM model: trains model (evidence: `hw1/src/sam.py`)
- SAM training → Loss and metrics: computes scores (evidence: `hw1/src/sam.py`)
- SAM training → Checkpoints and plots: saves results (evidence: `hw1/src/sam.py`)
