# levalby/miswsssm architecture

> Architecture diagram of the GitHub repository levalby/miswsssm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/levalby/miswsssm
- Repository: https://github.com/levalby/miswsssm

## Overview

##### Project type and purpose
- This is a research-oriented machine-learning codebase for 3D medical image segmentation.
- It provides two neural architectures (U-Mamba and Swin-UMamba) built on the nnU-Net pattern, plus dataset-adaptation scripts.
- It is designed to run on an HPC cluster (SLURM, NVIDIA A40 GPUs).

##### Sketch the high-level components
A. Data-management layer
– Datasets/HarDNet-MSEG
– Datasets/Kvasir-SEG
– Preprocessing scripts (download, convert, adapt)
B. Model implementation layer
– U-Mamba (nnU-Net structure + state-space modules)
– Swin-U-Mamba (Vision Transformer backbone + state-space modules)
C. Training orchestration layer
– SLURM batch scripts
– CUDA drivers, conda/mamba environments
– HPC job scheduler interface (bladecluster)
D. Outputs & evaluation
– Trained model checkpoints
– Validation & test metrics
– Visualization / segmentation masks

##### Relationships and data flow
- Dataset → Preprocessing scripts → Standardized nnU-Net folder structure
→ “run_training.py” in each model directory.
- run_training.py → Submits SLURM job → Allocates GPU via CUDA driver
- GPU nodes → Execute training loops using PyTorch/TensorFlow under nnU-Net APIs
- Models write checkpoints to shared HPC storage → Post-processing/evaluation
- Logs and results → README-referenced output folders

##### Architectural patterns & principles
- Modular design: Separate folders for each model variant (U-Mamba vs. Swin-U-Mamba)
- HPC-first deployment: Use of SLURM scripts and environment modules reflects batch-processing pattern.
- nnU-Net’s automated pipeline rules: folder conventions drive data split and augmentation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Management Layer
    subgraph "Data Management"
        direction TB
        Datasets["Datasets\n(HarDNet-MSEG, Kvasir-SEG)"]:::data
        Preprocessor["Preprocessing Scripts\n(download, convert, adapt)"]:::data
    end

    %% Model Implementation Layer
    subgraph "Model Implementation"
        direction TB
        UMamba["U-Mamba\n(nnU-Net + state-space modules)"]:::compute
        SwinUMamba["Swin-U-Mamba\n(Vision Transformer + state-space)"]:::compute
    end

    %% Training Orchestration Layer
    subgraph "Training Orchestration"
        direction TB
        SLURM["SLURM Batch Scripts\n(submit_job.sh)"]:::scheduler
        CondaEnv["Conda/Mamba env\nCUDA ≥12, nnU-Net vX.Y, PyTorch vZ"]:::scheduler
        BladeCluster["Bladecluster Head Node"]:::scheduler
    end

    %% Compute Layer
    subgraph "Compute Resources"
        direction TB
        GPU["A40 GPU Pool"]:::compute
    end

    %% Outputs & Evaluation
    subgraph "Outputs & Evaluation"
        direction TB
        Checkpoints["Trained Checkpoints\n(checkpoint.tar)"]:::storage
        Metrics["Validation & Test Metrics"]:::storage
        Masks["Segmentation Masks\n(.nii)"]:::storage
        Logs["Logs & Results"]:::storage
    end

    %% Data Flow Connections
    Datasets -->|".nii → NIfTI converted"| Preprocessor
    Preprocessor -->|"standardized nnU-Net folder"| UMamba
    Preprocessor -->|"standardized nnU-Net folder"| SwinUMamba

    %% Orchestration Flow
    UMamba -->|"run_training.py"| SLURM
    SwinUMamba -->|"run_training.py"| SLURM
    SLURM -->|"submit_job.sh"| BladeCluster
    BladeCluster -->|"allocates GPU via CUDA"| GPU

    %% Compute to Output Flow
    GPU -->|"checkpoint.tar"| Checkpoints
    GPU -->|"metrics.csv"| Metrics
    GPU -->|"masks (.nii)"| Masks
    GPU -->|"log files"| Logs

    %% Class Definitions
    classDef data fill:#D6EAF8,stroke:#3498DB,color:#154360;
    classDef compute fill:#D5F5E3,stroke:#27AE60,color:#1D8348;
    classDef scheduler fill:#FCF3CF,stroke:#F1C40F,color:#7D6608;
    classDef storage fill:#EBEDEF,stroke:#95A5A6,color:#566573;
```
