# caominhh/swin-deeplabv3 architecture

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

- Interactive diagram: https://gitdiagram.com/caominhh/swin-deeplabv3
- Repository: https://github.com/caominhh/swin-deeplabv3

## Overview

Swin-DeepLabV3 is a TensorFlow/Keras breast-ultrasound lesion segmentation project. Its main workflow loads prepared image/mask arrays, trains the hybrid Swin–DeepLabV3 model, evaluates predictions, and uses saved checkpoints for image or array inference. The model combines hierarchical shifted-window features, ASPP context, and a skip-connected decoder; training adds configurable losses and streaming Dice/IoU metrics. Dataset preprocessing is documented, but its scripts are absent from the supplied tree, so that subsystem is not mapped. Unsampled config and package wiring are represented only where documented.

Main entry points: [`training.py`](https://github.com/caominhh/swin-deeplabv3/blob/main/training.py) (Training runner), [`evaluation.py`](https://github.com/caominhh/swin-deeplabv3/blob/main/evaluation.py) (Evaluation runner), [`inference.py`](https://github.com/caominhh/swin-deeplabv3/blob/main/inference.py) (Inference runner), [`swin_dl/model.py`](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/model.py) (SwinDeepLabV3)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Segmentation model"]
  node_model["SwinDeepLabV3<br/>[model.py]"]
  node_encoder["Swin encoder<br/>[model.py]"]
  node_attention["Window attention<br/>[attention.py]"]
  node_merging["Patch merging<br/>[merging.py]"]
  node_aspp["ASPP context<br/>[aspp.py]"]
  node_decoder["Skip decoder<br/>[model.py]"]
end

subgraph group_train["Training"]
  node_trainer["Training runner<br/>[training.py]"]
  node_train_utils["Data and callbacks<br/>[training_utils.py]"]
end

subgraph group_assess["Evaluation and inference"]
  node_evaluator["Evaluation runner<br/>[evaluation.py]"]
  node_infer["Inference runner<br/>[inference.py]"]
  node_utils["Evaluation utilities<br/>[training_utils.py]"]
end

subgraph group_support["Model objectives"]
  node_losses["Loss functions<br/>[losses.py]"]
  node_metrics["Dice and IoU<br/>[metrics.py]"]
  node_package["Model registration<br/>[__init__.py]"]
end

node_user(("Engineer"))
node_arrays[("Prepared arrays")]
node_checkpoint["Saved checkpoint"]
node_image["Image inputs"]
node_predictions["Masks or arrays"]

node_user -->|"starts training"| node_trainer
node_arrays -->|"provides splits"| node_train_utils
node_trainer -->|"loads and batches"| node_train_utils
node_trainer -->|"builds and fits"| node_model
node_trainer -->|"selects objective"| node_losses
node_trainer -->|"compiles metrics"| node_metrics
node_trainer -->|"saves best model"| node_checkpoint
node_model -->|"extracts features"| node_encoder
node_encoder -->|"applies blocks"| node_attention
node_encoder -->|"downsamples stages"| node_merging
node_model -->|"aggregates context"| node_aspp
node_model -->|"fuses skip features"| node_decoder
node_user -->|"starts evaluation"| node_evaluator
node_evaluator -->|"loads split"| node_utils
node_arrays -->|"provides splits"| node_utils
node_evaluator -->|"loads model"| node_checkpoint
node_evaluator -->|"predicts with"| node_model
node_evaluator -->|"computes scores"| node_metrics
node_evaluator -->|"saves predictions"| node_predictions
node_user -->|"starts inference"| node_infer
node_image -->|"supplies images"| node_infer
node_infer -->|"loads model"| node_checkpoint
node_infer -->|"registers custom objects"| node_package
node_infer -->|"predicts with"| node_model
node_infer -->|"writes masks"| node_predictions

click node_trainer "https://github.com/caominhh/swin-deeplabv3/blob/main/training.py"
click node_train_utils "https://github.com/caominhh/swin-deeplabv3/blob/main/training_utils.py"
click node_model "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/model.py"
click node_encoder "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/model.py"
click node_attention "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/layers/attention.py"
click node_merging "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/layers/merging.py"
click node_aspp "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/layers/aspp.py"
click node_decoder "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/model.py"
click node_losses "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/losses.py"
click node_metrics "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/metrics.py"
click node_evaluator "https://github.com/caominhh/swin-deeplabv3/blob/main/evaluation.py"
click node_infer "https://github.com/caominhh/swin-deeplabv3/blob/main/inference.py"
click node_utils "https://github.com/caominhh/swin-deeplabv3/blob/main/training_utils.py"
click node_package "https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/__init__.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_model,node_encoder,node_attention,node_merging,node_aspp,node_decoder toneBlue
class node_trainer,node_train_utils,node_arrays toneAmber
class node_evaluator,node_infer,node_utils toneMint
class node_losses,node_metrics,node_package toneRose
class node_user,node_checkpoint,node_image,node_predictions toneIndigo
```

## Components

### Segmentation model

- [SwinDeepLabV3](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/model.py): `swin_dl/model.py`
- [Swin encoder](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/model.py): `swin_dl/model.py`
- [Window attention](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/layers/attention.py): `swin_dl/layers/attention.py`
- [Patch merging](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/layers/merging.py): `swin_dl/layers/merging.py`
- [ASPP context](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/layers/aspp.py): `swin_dl/layers/aspp.py`
- [Skip decoder](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/model.py): `swin_dl/model.py`

### Training

- [Training runner](https://github.com/caominhh/swin-deeplabv3/blob/main/training.py): `training.py`
- [Data and callbacks](https://github.com/caominhh/swin-deeplabv3/blob/main/training_utils.py): `training_utils.py`

### Evaluation and inference

- [Evaluation runner](https://github.com/caominhh/swin-deeplabv3/blob/main/evaluation.py): `evaluation.py`
- [Inference runner](https://github.com/caominhh/swin-deeplabv3/blob/main/inference.py): `inference.py`
- [Evaluation utilities](https://github.com/caominhh/swin-deeplabv3/blob/main/training_utils.py): `training_utils.py`

### Model objectives

- [Loss functions](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/losses.py): `swin_dl/losses.py`
- [Dice and IoU](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/metrics.py): `swin_dl/metrics.py`
- [Model registration](https://github.com/caominhh/swin-deeplabv3/blob/main/swin_dl/__init__.py): `swin_dl/__init__.py`

### Other components

- **Engineer**
- **Prepared arrays**
- **Saved checkpoint**
- **Image inputs**
- **Masks or arrays**

## Connections

- Engineer → Training runner: starts training
- Prepared arrays → Data and callbacks: provides splits
- Training runner → Data and callbacks: loads and batches
- Training runner → SwinDeepLabV3: builds and fits
- Training runner → Loss functions: selects objective
- Training runner → Dice and IoU: compiles metrics
- Training runner → Saved checkpoint: saves best model
- SwinDeepLabV3 → Swin encoder: extracts features
- Swin encoder → Window attention: applies blocks
- Swin encoder → Patch merging: downsamples stages
- SwinDeepLabV3 → ASPP context: aggregates context
- SwinDeepLabV3 → Skip decoder: fuses skip features
- Engineer → Evaluation runner: starts evaluation
- Evaluation runner → Evaluation utilities: loads split
- Prepared arrays → Evaluation utilities: provides splits
- Evaluation runner → Saved checkpoint: loads model
- Evaluation runner → SwinDeepLabV3: predicts with
- Evaluation runner → Dice and IoU: computes scores
- Evaluation runner → Masks or arrays: saves predictions
- Engineer → Inference runner: starts inference
- Image inputs → Inference runner: supplies images
- Inference runner → Saved checkpoint: loads model
- Inference runner → Model registration: registers custom objects
- Inference runner → SwinDeepLabV3: predicts with
- Inference runner → Masks or arrays: writes masks
