# aravind-aripaka/fed-tumour-segmentation architecture

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

- Interactive diagram: https://gitdiagram.com/aravind-aripaka/fed-tumour-segmentation
- Repository: https://github.com/aravind-aripaka/fed-tumour-segmentation

## Overview

##### Project type and purpose
- This is an open-source, federated learning research tool focused on medical image segmentation.
- It simulates multiple “virtual hospitals” that collaboratively train a U-Net-16 model on MRI brain scans (e.g., BraTS) without sharing raw data.
- The goal is to build a privacy-preserving pipeline for clinical decision support in oncology.

##### File structure
- Top-level scripts:
- preprocess.py – contains image normalization, cropping, augmentation logic.
- dataset.py – handles data loading and partitioning into simulated hospital shards.
- model.py – defines the U-Net-16 architecture (likely using PyTorch or TensorFlow).
- train_baseline.py – single-site training loop for benchmarking.
- checker.py – evaluation/validation metrics and sanity checks on predictions.
- requirements*.txt – Python dependencies (e.g., torch, nibabel, numpy).
- BraTS20 Training Metadata.csv – raw metadata for partitioning.
- No explicit “server/” or “client/” directories – federated logic is embedded in these scripts.

##### README for additional insights
- “[F]ederated … multiple virtual hospitals collaboratively train … without compromising patient confidentiality.”
- Mentions public MRI datasets partitioned to simulate institutions.
- Emphasizes privacy-preserving AI, clinical decision support, and strict data regulations.

a. Main components
1. Data Storage: raw MRI scans + metadata CSV
2. Preprocessing Module (preprocess.py)
3. Data Partitioning / Client Simulator (dataset.py)
4. Local Training Clients (“Hospitals”)
– Each runs train_baseline.py (or its federated equivalent)
– Loads a data shard, applies preprocess, feeds model
5. Model Definition (model.py) – U-Net-16 module shared by clients and server
6. Federated Aggregator (Parameter Server)
7. Evaluation/Checker (checker.py)
8. Dependency Layer – Python runtime, PyTorch/TensorFlow, nibabel, numpy
b. Relationships & data-flow
- Partition shards flow to multiple Client nodes
- Clients load Model Definition and run local training
- Clients send model weight deltas/gradients to Aggregator
- Aggregator performs FedAvg (or similar) and returns updated global weights
- Clients receive updated weights for next round
- After convergence, outputs flow to Checker/Evaluation module
c. Architectural patterns
- Federated Learning (Parameter-Server model)
- Modular ML Pipeline (ETL → Data Loader → Model → Training → Evaluation)
- Separation of concerns: preprocessing, data handling, model spec, training loops
d. Key technologies & libraries
- Python 3.x ● PyTorch or TensorFlow ● nibabel (for NIfTI)
- numpy, pandas (metadata CSV)
- Possible FL frameworks (e.g., Flower or PySyft) for future extension

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Data Layer"
        DataStorage["Raw MRI Scans\n& BraTS20 Training Metadata.csv"]:::data
    end

    subgraph "Preprocessing Layer"
        Preprocess["preprocess.py"]:::compute
        Partition["dataset.py"]:::compute
    end

    DataStorage --> Preprocess --> Partition

    subgraph "Federated Learning"
        subgraph "Local Training Clients"
            direction TB
            C1["Hospital 1"]:::compute
            C2["Hospital 2"]:::compute
            C3["Hospital N"]:::compute
        end
        Model["model.py\n(U-Net-16)"]:::compute
        Aggregator["Parameter Server\n(FedAvg)"]:::service
    end

    Partition --> C1
    Partition --> C2
    Partition --> C3

    C1 -->|"loads model"| Model
    C2 -->|"loads model"| Model
    C3 -->|"loads model"| Model

    C1 -->|"local training\n(train_baseline.py)"| Aggregator
    C2 -->|"local training\n(train_baseline.py)"| Aggregator
    C3 -->|"local training\n(train_baseline.py)"| Aggregator

    Aggregator -->|"global weights"| C1
    Aggregator -->|"global weights"| C2
    Aggregator -->|"global weights"| C3

    subgraph "Evaluation"
        Checker["checker.py"]:::compute
    end

    Aggregator --> Checker

    subgraph "Dependencies"
        Req1["requirements.txt"]:::deps
        Req2["requirements_frozen.txt"]:::deps
    end

    %% Click Events
    click DataStorage "https://github.com/aravind-aripaka/fed-tumour-segmentation/blob/main/BraTS20 Training Metadata.csv"
    click Preprocess "https://github.com/aravind-aripaka/fed-tumour-segmentation/blob/main/preprocess.py"
    click Partition "https://github.com/aravind-aripaka/fed-tumour-segmentation/blob/main/dataset.py"
    click Model "https://github.com/aravind-aripaka/fed-tumour-segmentation/blob/main/model.py"
    click Checker "https://github.com/aravind-aripaka/fed-tumour-segmentation/blob/main/checker.py"
    click Req1 "https://github.com/aravind-aripaka/fed-tumour-segmentation/blob/main/requirements.txt"
    click Req2 "https://github.com/aravind-aripaka/fed-tumour-segmentation/blob/main/requirements_frozen.txt"

    %% Styles
    classDef data fill:#DCEEFB,stroke:#084298,color:#084298;
    classDef compute fill:#D1E7DD,stroke:#0F5132,color:#0F5132;
    classDef service fill:#FFF3CD,stroke:#664D03,color:#664D03;
    classDef deps fill:#E2E3E5,stroke:#41464B,color:#41464B;
```
