# mohamedalihabib/brain-tumor-detection architecture

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

- Interactive diagram: https://gitdiagram.com/mohamedalihabib/brain-tumor-detection
- Repository: https://github.com/mohamedalihabib/brain-tumor-detection

## Overview

##### Project type and purpose
- This is a machine-learning image-classification pipeline (brain tumor vs. non-tumor) implemented in Jupyter notebooks using TensorFlow/Keras.
- It ingests raw MRI images, augments and preprocesses them, trains a custom CNN, logs metrics, and saves model weights.

##### File structure
- Notebooks:
- Data Augmentation.ipynb – contains data-augmentation logic.
- Brain Tumor Detection.ipynb – contains data preprocessing, model definition, training, evaluation.
- Data directories:
- “yes” and “no” – original raw images (tumor vs. non-tumor).
- “augmented data” – output of augmentation step (combined original + synthetic).
- “logs” – TensorBoard event logs for each training run.
- “models” – serialized Keras .model files for each epoch/checkpoint; best model highlighted.
- Config artifacts: LICENSE, README.md.

##### Key insights from the README
- Data augmentation expanded 253 images → 2,065 examples.
- Preprocessing steps: cropping, resizing to (240×240×3), normalization.
- Data split: 70% train / 15% val / 15% test.
- CNN architecture: zero-padding → Conv7×7 → batch-norm → ReLU → two max-pool layers → flatten → dense(sigmoid).
- Training epochs logged; best model at epoch 23 (91% val accuracy).

1. External Data Source (Kaggle repository link)
2. Raw Data Store
3. Data Augmentation Module
4. Preprocessing Module
5. Data Splitter (Train / Validation / Test)
6. Model Training Engine (CNN)
7. Logging Service (TensorBoard logs)
8. Model Storage (serialized .model files)
9. Evaluation & Metrics Report
10. Model Loader / Deployment Interface
- External Data → Raw Data Store
- Raw Data Store → Data Augmentation → Augmented Data Store
- Augmented Data Store → Preprocessing → Preprocessed Dataset
- Preprocessed Dataset → Data Splitter → {Train, Val, Test}
- Train + Val → Model Training → Model Storage + Logging Service
- Test + Stored Model → Evaluation → Metrics Report
- Model Storage → Model Loader / Deployment
c. Architectural patterns & principles:
- Pipeline pattern – sequential stages of data transformation.
- Modularity – separate notebooks/modules for augmentation vs. training.
- Reproducibility – logs tied to each training run; versioned model artifacts.
- Scalability consideration – augmentation to expand small dataset.
d. Key technologies & frameworks:
- Jupyter Notebooks (or Python scripts)
- TensorFlow 2.x & Keras API
- Python imaging libraries (e.g., OpenCV or PIL) for crop/resize
- TensorBoard for logging
- HDF5 or SavedModel format for weights

## Diagram (Mermaid)

```mermaid
flowchart TD
    External["External Data Source\n(Kaggle)"]:::external
    Raw["Raw Data Store\n(/yes, /no)"]:::dataStore
    AugMod["Data Augmentation Module"]:::processing
    Augmented["Augmented Data Store\n(/augmented data)"]:::dataStore
    PreMod["Preprocessing Module"]:::processing
    Preprocessed["Preprocessed Dataset"]:::dataStore
    Split["Data Splitter\n(Train/Val/Test)"]:::processing
    Train["Model Training Engine\n(CNN)"]:::processing
    Logs["Logging Service\n(TensorBoard logs)"]:::storage
    Models["Model Storage\n(.model files)"]:::storage
    Eval["Evaluation & Metrics Report"]:::evaluation
    Deploy["Model Loader / Deployment"]:::evaluation

    External --> Raw
    Raw --> AugMod
    AugMod --> Augmented
    Augmented --> PreMod
    PreMod --> Preprocessed
    Preprocessed --> Split
    Split --> Train
    Train --> Logs
    Train --> Models
    Split -->|Test Data| Eval
    Models -->|Load Model| Eval
    Models --> Deploy

    click Raw "https://github.com/mohamedalihabib/brain-tumor-detection/tree/master//yes and /no"
    click AugMod "https://github.com/mohamedalihabib/brain-tumor-detection/blob/master/Data Augmentation.ipynb"
    click Augmented "https://github.com/mohamedalihabib/brain-tumor-detection/tree/master//augmented data"
    click PreMod "https://github.com/mohamedalihabib/brain-tumor-detection/blob/master/Brain Tumor Detection.ipynb"
    click Split "https://github.com/mohamedalihabib/brain-tumor-detection/blob/master/Brain Tumor Detection.ipynb"
    click Train "https://github.com/mohamedalihabib/brain-tumor-detection/blob/master/Brain Tumor Detection.ipynb"
    click Logs "https://github.com/mohamedalihabib/brain-tumor-detection/tree/master//logs"
    click Models "https://github.com/mohamedalihabib/brain-tumor-detection/tree/master//models"
    click Eval "https://github.com/mohamedalihabib/brain-tumor-detection/blob/master/Brain Tumor Detection.ipynb"

    classDef dataStore fill:#AED6F1,stroke:#154360,color:#154360
    classDef processing fill:#ABEBC6,stroke:#1D8348,color:#1D8348
    classDef storage fill:#F5B041,stroke:#B9770E,color:#873600
    classDef evaluation fill:#D2B4DE,stroke:#7D3C98,color:#512E5F
    classDef external fill:#E5E7E9,stroke:#566573,color:#1C2833
```
