# has1elb/brain-tumor-classification2 architecture

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

- Interactive diagram: https://gitdiagram.com/has1elb/brain-tumor-classification2
- Repository: https://github.com/has1elb/brain-tumor-classification2

## Overview

##### Main Components Identification
- Data Management:
- Raw Data Repository: The “data/raw” directory holds the original MRI images organized by tumor type (glioma, meningioma, notumor, pituitary) for both training and testing.
- Processed Data: Although not explicitly seen in the file tree, the README mentions “data/processed”, which will contain the preprocessed data after scaling, normalization, and label encoding.
- Preprocessing Module:
- Scripts/notebooks (preprocess_data.py / preprocess_data.ipynb) are responsible for image resizing, normalization, and label encoding.
- Model Training Module:
- Separate training scripts for different models (e.g., train_model.py for a custom CNN, train_ResNet.py, train_vgg16.py, train_vgg19.py) indicate modular training processes for each architecture.
- Notebooks for training and experimentation also exist for interactive exploration.
- Model Evaluation and Comparison:
- Scripts (evaluate_model.py, compare_models.py) and notebooks (evaluation_model.ipynb, compare_models.ipynb) support evaluating model performance and comparing different architectures’ accuracy.
- Application Interface:
- app.py forms the core of the Streamlit application where users can upload MRI images and get predictions.
- Prediction script and notebook (predict_image.py / predict_image.ipynb) supplement the prediction capability.
- Containerization & Deployment:
- A Dockerfile, .dockerignore, and a devcontainer folder indicate that containerization is used for deployment and development consistency.
- Logging and Model Storage:
- Logs (evaluation_report.txt in logs/) capture evaluation results.
- (Although not explicitly seen in the file tree, the README mentions a “models” directory for saving trained models.)

##### Relationships and Data Flow
- The Data Management component supplies raw images to the Preprocessing Module. Preprocessed data then feeds the Model Training Modules.
- Model Training results (saved models) are used in the Model Evaluation and Prediction Modules.
- The Application Interface (Streamlit app in app.py) accesses these trained models to serve prediction requests.
- Docker encapsulates the overall setup, ensuring all components run in a standardized environment.
- Notebooks act as exploratory interfaces demonstrating each of these steps.

##### Architectural Patterns and Design Principles
- Modular Design: Different scripts and notebooks encapsulate specific stages (preprocessing, training per model architecture, evaluation, prediction).
- Separation of Concerns: Distinguishing between data handling, model training, and application interface components.
- Containerization: Use of Docker (and a devcontainer) emphasizes reproducible environments and deployment robustness.
- Experimentation & Extensibility: The inclusion of multiple notebooks encourages iterative experimentation and model comparison.

##### Relevant Technologies and Frameworks
- TensorFlow/Keras or PyTorch (implied by deep learning and CNN processing)
- Streamlit for creating the interactive web application
- OpenCV for image processing (as mentioned in installation instructions)
- Docker for containerized deployment
- Python libraries such as scikit-learn for preprocessing and evaluation metrics

##### Essential Elements
- Each major component (data, preprocessing, training modules, evaluation, prediction, and UI) as clearly labeled nodes.
- Data storage components (raw and processed data)
- Processing modules (scripts in preprocessing and training)
- User interface components (Streamlit application)
- Deployment tools (Docker, devcontainer)

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Data Ingestion"
        RawData["Raw Data"]:::data
        ProcessedData["Processed Data"]:::data
    end

    subgraph "Preprocessing Module"
        PreprocessScript["preprocess_data.py"]:::script
        PreprocessNotebook["preprocess_data.ipynb"]:::notebook
    end

    subgraph "Model Training Module"
        CustomCNN["train_model.py (Custom CNN)"]:::script
        ResNet["train_ResNet.py (ResNet50)"]:::script
        VGG16["train_vgg16.py (VGG16)"]:::script
        VGG19["train_vgg19.py (VGG19)"]:::script
        TrainingNotebook["train_model.ipynb"]:::notebook
    end

    subgraph "Model Evaluation Module"
        EvalScript["evaluate_model.py"]:::script
        CompareScript["compare_models.py"]:::script
        EvalNotebook["evaluation_model.ipynb"]:::notebook
        CompareNotebook["compare_models.ipynb"]:::notebook
        EvalReport["Evaluation Report"]:::log
    end

    subgraph "Prediction & Application"
        PredictionScript["predict_image.py"]:::script
        PredictionNotebook["predict_image.ipynb"]:::notebook
        StreamlitApp["app.py (Streamlit App)"]:::app
    end

    subgraph "Containerization & Deployment"
        Containerization["Containerization (Docker, .dockerignore, devcontainer)"]:::deployment
    end

    ExternalDeps["External Dependencies"]:::external

    %% Data flow connections
    RawData -->|"raw_images"| PreprocessScript
    RawData -->|"raw_images"| PreprocessNotebook
    PreprocessScript -->|"processed"| ProcessedData
    PreprocessNotebook -->|"processed"| ProcessedData
    ProcessedData -->|"training_data"| CustomCNN
    ProcessedData -->|"training_data"| ResNet
    ProcessedData -->|"training_data"| VGG16
    ProcessedData -->|"training_data"| VGG19
    ProcessedData -->|"training_data"| TrainingNotebook
    CustomCNN -->|"trained"| EvalScript
    ResNet -->|"trained"| EvalScript
    VGG16 -->|"trained"| EvalScript
    VGG19 -->|"trained"| EvalScript
    TrainingNotebook -->|"trained"| EvalNotebook
    EvalScript -->|"evaluation"| EvalReport
    EvalScript -->|"compares"| CompareScript
    EvalNotebook -->|"compares"| CompareNotebook
    EvalNotebook -->|"evaluation"| PredictionScript
    PredictionScript -->|"predicts"| StreamlitApp
    PredictionNotebook -->|"predicts"| StreamlitApp

    %% External dependencies
    ExternalDeps --- PreprocessScript
    ExternalDeps --- CustomCNN
    ExternalDeps --- EvalScript
    ExternalDeps --- PredictionScript

    %% Containerization influences key components
    Containerization --- RawData
    Containerization --- ProcessedData
    Containerization --- CustomCNN
    Containerization --- EvalScript
    Containerization --- StreamlitApp

    %% Click Events
    click RawData "https://github.com/has1elb/brain-tumor-classification2/tree/main/data/raw"
    click PreprocessScript "https://github.com/has1elb/brain-tumor-classification2/blob/main/scripts/preprocess_data.py"
    click PreprocessNotebook "https://github.com/has1elb/brain-tumor-classification2/blob/main/notebooks/preprocess_data.ipynb"
    click CustomCNN "https://github.com/has1elb/brain-tumor-classification2/blob/main/scripts/train_model.py"
    click ResNet "https://github.com/has1elb/brain-tumor-classification2/blob/main/scripts/train_ResNet.py"
    click VGG16 "https://github.com/has1elb/brain-tumor-classification2/blob/main/scripts/train_vgg16.py"
    click VGG19 "https://github.com/has1elb/brain-tumor-classification2/blob/main/scripts/train_vgg19.py"
    click TrainingNotebook "https://github.com/has1elb/brain-tumor-classification2/blob/main/notebooks/train_model.ipynb"
    click EvalScript "https://github.com/has1elb/brain-tumor-classification2/blob/main/scripts/evaluate_model.py"
    click CompareScript "https://github.com/has1elb/brain-tumor-classification2/blob/main/scripts/compare_models.py"
    click EvalNotebook "https://github.com/has1elb/brain-tumor-classification2/blob/main/notebooks/evaluation_model.ipynb"
    click CompareNotebook "https://github.com/has1elb/brain-tumor-classification2/blob/main/notebooks/compare_models.ipynb"
    click PredictionScript "https://github.com/has1elb/brain-tumor-classification2/blob/main/scripts/predict_image.py"
    click PredictionNotebook "https://github.com/has1elb/brain-tumor-classification2/blob/main/notebooks/predict_image.ipynb"
    click StreamlitApp "https://github.com/has1elb/brain-tumor-classification2/blob/main/app.py"
    click Containerization "https://github.com/has1elb/brain-tumor-classification2/tree/main/Dockerfile"
    click EvalReport "https://github.com/has1elb/brain-tumor-classification2/blob/main/logs/evaluation_report.txt"

    %% Styles
    classDef data fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef script fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef notebook fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef app fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef deployment fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef log fill:#FADBD8,stroke:#943126,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
