# atharv-arya/3d-brain-tumor-segmentation architecture

> Architecture diagram of the GitHub repository atharv-arya/3d-brain-tumor-segmentation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atharv-arya/3d-brain-tumor-segmentation
- Repository: https://github.com/atharv-arya/3d-brain-tumor-segmentation

## Overview

##### Project type and purpose
- This is a machine-learning research/codebase for 3D brain tumor segmentation.
- It consists of two Jupyter notebooks: one for exploratory data analysis (EDA.ipynb) and one for building/training a 3D ResNet segmentation model (3D_Resnet.ipynb).
- The README simply points to an external dataset (brain MRI scans in 3D).

##### File structure
- Top level:
- 3D_Resnet.ipynb – the modeling/training notebook.
- EDA.ipynb – data loading, visualization, preprocessing exploration.
- README.md – dataset download instructions.
- No dedicated src/, scripts/, or config/ folders—everything is in notebooks.
- No deployment or CI/CD artifacts.

##### Key insights from the README
- The entire pipeline depends on one core dataset downloaded externally.
- No mention of data storage solution beyond local filesystem.
- No explicit description of computing environment, but typical dependencies are PyTorch (for 3D ResNet), nibabel or SimpleITK (for reading medical images), NumPy, matplotlib, etc.

##### Main components
a. Data Source
- External storage (Google Drive link) → Local raw data files (e.g., NIfTI volumes).
b. Data Ingestion & Preprocessing
- Notebook/Script that loads raw 3D volumes, applies normalization, resizing/cropping, augmentations.
c. Exploratory Data Analysis (EDA)
- Notebook cell modules for visualizing slices, histograms, 3D renderings.
d. Model Definition
- 3D ResNet architecture: input layer → residual blocks → bottleneck → upsampling if segmentation head is included.
e. Training Engine
- Training loop: batch loader → forward pass → loss computation (e.g., Dice loss) → optimizer step → checkpointing.
f. Evaluation & Inference
- Metrics calculation, visualizing segmentation overlays on MRI slices, saving output masks.
g. Environment & Dependencies
- GPU compute cluster or local GPU, Python environment (conda/venv), PyTorch, medical-imaging libraries.

##### Relationships & interactions
- Data flows from external source into preprocessing.
- Preprocessed data feeds both EDA and the training engine.
- Model definition is invoked by the training engine.
- Checkpoints and final model artifacts are stored to disk.
- Inference modules take a trained model + new images and produce segmentation masks.

##### Architectural patterns & design principles
- Modular pipeline: separate data ingestion, EDA, model definition, training, and inference stages.
- Notebook-driven prototyping, but can be refactored into a script-based pipeline (use Python modules for each component).
- Use of GPU acceleration for compute-intensive 3D convolutions.
- Data-centric approach: validate correctness at EDA stage before training.

- Notes on external dependencies (e.g., GPU, Python libs)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        DS["External Dataset\n(Google Drive link)"]:::data
    end

    %% Preprocessing & EDA
    subgraph "Preprocessing & EDA"
        PP["Preprocessing\nNumPy, nibabel, SimpleITK"]:::pre
        EDA["EDA\nVisualization\n(matplotlib, Plotly)"]:::pre
    end

    %% Model & Training
    subgraph "Model & Training"
        MD["3D ResNet Model\n(PyTorch)"]:::model
        TE["Training Loop\n(Dice Loss, Optimizer,\nCheckpointing)"]:::model
        MC["Model Checkpoints\n(.pt files)"]:::model
    end

    %% Inference & Output
    subgraph "Inference & Output"
        EI["Inference & Evaluation\n(Metrics, Masks)"]:::output
        SM["Segmentation Masks\n(NIfTI files)"]:::output
    end

    %% Environment
    subgraph "Environment & Dependencies"
        ENV["Conda/Venv, GPU Compute\nPython libs: PyTorch,\nnibabel, SimpleITK"]:::env
    end

    %% Data Flow
    DS -->|"raw data"| PP
    PP -->|"preprocessed data"| EDA
    PP -->|"training data"| TE
    MD -->|"model definition"| TE
    TE -->|"save checkpoints"| MC
    MC -->|"trained model"| EI
    DS -->|"new data"| EI
    EI -->|"output masks"| SM

    %% Click Events
    click DS "https://github.com/atharv-arya/3d-brain-tumor-segmentation/blob/main/README.md"
    click PP "https://github.com/atharv-arya/3d-brain-tumor-segmentation/blob/main/EDA.ipynb"
    click EDA "https://github.com/atharv-arya/3d-brain-tumor-segmentation/blob/main/EDA.ipynb"
    click MD "https://github.com/atharv-arya/3d-brain-tumor-segmentation/blob/main/3D_Resnet.ipynb"
    click TE "https://github.com/atharv-arya/3d-brain-tumor-segmentation/blob/main/3D_Resnet.ipynb"
    click EI "https://github.com/atharv-arya/3d-brain-tumor-segmentation/blob/main/3D_Resnet.ipynb"
    click ENV "https://github.com/atharv-arya/3d-brain-tumor-segmentation/blob/main/README.md"

    %% Styles
    classDef data fill:#cce5ff,stroke:#0066cc,color:#003366;
    classDef pre fill:#d4edda,stroke:#28a745,color:#155724;
    classDef model fill:#ffe5b4,stroke:#ff8c00,color:#8b4500;
    classDef output fill:#e2d6f3,stroke:#6f42c1,color:#38106b;
    classDef env fill:#f0f0f0,stroke:#999999,color:#333333;
```
