# ola-vish/lung-tumor-segmentation architecture

> Architecture diagram of the GitHub repository ola-vish/lung-tumor-segmentation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ola-vish/lung-tumor-segmentation
- Repository: https://github.com/ola-vish/lung-tumor-segmentation

## Overview

##### Project type and purpose
- This is a Python-based machine-learning pipeline for lung tumor segmentation.
- It ingests raw CT scans (NIfTI files), preprocesses them, trains segmentation models (SegNet, U-Net via PyTorch/PyTorch Lightning), and runs inference to produce tumor masks.
- It uses Weights & Biases for logging and tracks experiments via checkpoints.

##### File structure
Top-level files:
- setup.py, requirements.txt, LICENSE, README.md – packaging and docs
- images/ – example outputs
- .gitignore
project/ (main package)
- datasets/
– lung_tumor_dataset.py: DataLoader wrapper & augmentation
- loggers/
– image_logger.py: wandb image logging
- models/
– segnet.py, unet.py: raw model definitions
– lit_segmentation_model.py: PyTorch Lightning Module wrapping training/validation/etc.
- preprocessing.py – CLI entry for data normalization, cropping, saving preprocessed NIfTI.
- train.py – CLI entry to kick off training via the Lightning module, checkpointing, wandb init.
- inference.py – CLI entry to load a trained checkpoint, run the model on new CT scans, and save predicted masks.

##### README for additional insights
- Requires Python 3.7, wandb login.
- Workflow: preprocessing → train → inference.
- Input/Output: raw scans/labels folder → preprocessed data folder → model checkpoints → prediction folder.
- External dependencies: Medical Decathlon dataset, wandb service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Ingestion & Preprocessing"
        direction TB
        EXT_DATA(("Medical Decathlon\nDataset")):::external
        PREPROCESS["preprocessing.py"]:::data
        PREPROCESSED[(Preprocessed Data\nStore)]:::storage
    end

    subgraph "Model Training"
        direction TB
        LOADER["lung_tumor_dataset.py"]:::data
        subgraph "Model Library"
            direction TB
            SEGNET["segnet.py"]:::compute
            UNET["unet.py"]:::compute
        end
        subgraph "Training Engine"
            direction TB
            LIT["lit_segmentation_model.py"]:::compute
            TRAIN_CLI["train.py"]:::compute
        end
        LOGGER(("Weights & Biases\nImage Logger")):::external
        MODEL_STORE[(Model Artifact\nStore)]:::storage
    end

    subgraph "Inference & Output"
        direction TB
        INFER["inference.py"]:::compute
        OUTPUT[(Output Result\nStore)]:::storage
    end

    EXT_DATA -->|"downloads NIfTI"| PREPROCESS
    PREPROCESS -->|"saves NIfTI"| PREPROCESSED
    PREPROCESSED -->|"reads NIfTI"| LOADER
    LOADER -->|"provides batches"| LIT
    SEGNET -->|"used by"| LIT
    UNET -->|"used by"| LIT
    LIT -->|"orchestrates training"| TRAIN_CLI
    TRAIN_CLI -->|"saves .ckpt"| MODEL_STORE
    LIT -->|"wandb.log() API call"| LOGGER
    MODEL_STORE -->|"loads checkpoint"| INFER
    EXT_DATA -->|"new CT scans"| INFER
    INFER -->|"outputs masks"| OUTPUT

    click PREPROCESS "https://github.com/ola-vish/lung-tumor-segmentation/blob/main/project/preprocessing.py"
    click LOADER "https://github.com/ola-vish/lung-tumor-segmentation/blob/main/project/datasets/lung_tumor_dataset.py"
    click SEGNET "https://github.com/ola-vish/lung-tumor-segmentation/blob/main/project/models/segnet.py"
    click UNET "https://github.com/ola-vish/lung-tumor-segmentation/blob/main/project/models/unet.py"
    click LIT "https://github.com/ola-vish/lung-tumor-segmentation/blob/main/project/models/lit_segmentation_model.py"
    click TRAIN_CLI "https://github.com/ola-vish/lung-tumor-segmentation/blob/main/project/train.py"
    click LOGGER "https://github.com/ola-vish/lung-tumor-segmentation/blob/main/project/loggers/image_logger.py"
    click INFER "https://github.com/ola-vish/lung-tumor-segmentation/blob/main/project/inference.py"

    classDef data fill:#A0C4FF,stroke:#333,stroke-width:1px
    classDef compute fill:#B7E4C7,stroke:#333,stroke-width:1px
    classDef storage fill:#FFD6A5,stroke:#333,stroke-width:1px
    classDef external fill:#D0ACFF,stroke:#333,stroke-width:1px
```
