# sldgroup/mk-unet architecture

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

- Interactive diagram: https://gitdiagram.com/sldgroup/mk-unet
- Repository: https://github.com/sldgroup/mk-unet

## Overview

MK-UNet is a PyTorch polyp-image segmentation project. Its user workflow is to prepare ClinicDB or ColonDB images and masks, train a selected MK-UNet variant, save a best-validation checkpoint, and run testing to assess segmentation quality. The network implements multi-kernel encoder and attention-gated decoder stages; the dataset loader handles image/mask transforms and binary labels. Training and model internals are partially sampled; the testing entry point is documented in the README, but its source was not sampled, so detailed test wiring is omitted.

Main entry points: [`train_polyp.py`](https://github.com/sldgroup/mk-unet/blob/main/train_polyp.py) (Training loop), [`test_polyp.py`](https://github.com/sldgroup/mk-unet/blob/main/test_polyp.py) (Evaluation), [`mkunet_network.py`](https://github.com/sldgroup/mk-unet/blob/main/mkunet_network.py) (MK-UNet variants), [`utils/dataloader_polyp.py`](https://github.com/sldgroup/mk-unet/blob/main/utils/dataloader_polyp.py) (Dataset loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Segmentation workflow"]
  node_training["Training loop<br/>[train_polyp.py]"]
  node_evaluation["Evaluation<br/>[test_polyp.py]"]
  node_checkpoint[("Model checkpoint")]
  node_metrics["Segmentation metrics<br/>[train_polyp.py]"]
  node_helpers["Training helpers<br/>[utils.py]"]
  node_mask["Segmentation mask"]
end

subgraph group_model["MK-UNet model"]
  node_network["MK-UNet variants<br/>[mkunet_network.py]"]
  node_encoder["Multi-kernel encoder<br/>[mkunet_network.py]"]
  node_decoder["Attention decoder<br/>[mkunet_network.py]"]
end

subgraph group_data["Image data"]
  node_datasets[("Polyp datasets")]
  node_loader["Dataset loader"]
end

node_user(("Researcher"))

node_user -->|"prepares data"| node_datasets
node_datasets -->|"loads images"| node_loader
node_user -->|"starts training"| node_training
node_training -->|"requests batches"| node_loader
node_loader -->|"returns batches"| node_training
node_training -->|"runs inference"| node_network
node_network -->|"encodes features"| node_encoder
node_network -->|"decodes features"| node_decoder
node_training -->|"uses utilities"| node_helpers
node_training -->|"saves best weights"| node_checkpoint
node_user -->|"starts testing"| node_evaluation
node_evaluation -->|"loads weights"| node_checkpoint
node_evaluation -->|"computes scores"| node_metrics
node_evaluation -->|"produces segmentation"| node_mask

click node_loader "https://github.com/sldgroup/mk-unet/blob/main/utils/dataloader_polyp.py"
click node_training "https://github.com/sldgroup/mk-unet/blob/main/train_polyp.py"
click node_evaluation "https://github.com/sldgroup/mk-unet/blob/main/test_polyp.py"
click node_metrics "https://github.com/sldgroup/mk-unet/blob/main/train_polyp.py"
click node_helpers "https://github.com/sldgroup/mk-unet/blob/main/utils/utils.py"
click node_network "https://github.com/sldgroup/mk-unet/blob/main/mkunet_network.py"
click node_encoder "https://github.com/sldgroup/mk-unet/blob/main/mkunet_network.py"
click node_decoder "https://github.com/sldgroup/mk-unet/blob/main/mkunet_network.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_training,node_evaluation,node_checkpoint,node_metrics,node_helpers,node_mask toneBlue
class node_network,node_encoder,node_decoder toneAmber
class node_datasets,node_loader toneMint
class node_user toneIndigo
```

## Components

### Segmentation workflow

- [Training loop](https://github.com/sldgroup/mk-unet/blob/main/train_polyp.py): `train_polyp.py`
- [Evaluation](https://github.com/sldgroup/mk-unet/blob/main/test_polyp.py): `test_polyp.py`
- **Model checkpoint**
- [Segmentation metrics](https://github.com/sldgroup/mk-unet/blob/main/train_polyp.py): `train_polyp.py`
- [Training helpers](https://github.com/sldgroup/mk-unet/blob/main/utils/utils.py): `utils/utils.py`
- **Segmentation mask**

### MK-UNet model

- [MK-UNet variants](https://github.com/sldgroup/mk-unet/blob/main/mkunet_network.py): `mkunet_network.py`
- [Multi-kernel encoder](https://github.com/sldgroup/mk-unet/blob/main/mkunet_network.py): `mkunet_network.py`
- [Attention decoder](https://github.com/sldgroup/mk-unet/blob/main/mkunet_network.py): `mkunet_network.py`

### Image data

- **Polyp datasets**
- [Dataset loader](https://github.com/sldgroup/mk-unet/blob/main/utils/dataloader_polyp.py): `utils/dataloader_polyp.py`

### Other components

- **Researcher**

## Connections

- Researcher → Polyp datasets: prepares data
- Polyp datasets → Dataset loader: loads images
- Researcher → Training loop: starts training
- Training loop → Dataset loader: requests batches
- Dataset loader → Training loop: returns batches
- Training loop → MK-UNet variants: runs inference
- MK-UNet variants → Multi-kernel encoder: encodes features
- MK-UNet variants → Attention decoder: decodes features
- Training loop → Training helpers: uses utilities
- Training loop → Model checkpoint: saves best weights
- Researcher → Evaluation: starts testing
- Evaluation → Model checkpoint: loads weights
- Evaluation → Segmentation metrics: computes scores
- Evaluation → Segmentation mask: produces segmentation
