# m3mentomor1/breast-cancer-image-classification-with-densenet121 architecture

> Architecture diagram of the GitHub repository m3mentomor1/breast-cancer-image-classification-with-densenet121, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/m3mentomor1/breast-cancer-image-classification-with-densenet121
- Repository: https://github.com/m3mentomor1/breast-cancer-image-classification-with-densenet121

## Overview

##### Project type and purpose
- This is a full-stack machine-learning application for breast ultrasound image classification.
- Purpose: load a pre-trained DenseNet121-based CNN, run inference on uploaded ultrasound images via a Streamlit web UI, and display multiclass predictions (benign, malignant, normal).

##### File structure
- Top‐level artifacts:
- LICENSE, README.md, requirements.txt – project metadata & deps
- model_training.ipynb, model_evaluation.ipynb – offline training & evaluation pipelines
- splitted_model/ (model.h5 in 32 parts) – stored model artifacts
- streamlit_app.py – the entry point for the deployed web UI
- test_images/ – sample inputs for evaluation
- No separate “frontend” vs. “backend” directories: Streamlit combines UI & inference logic in one script.
- Dependencies declared in requirements.txt; deployment handled by Streamlit Cloud.

##### README for additional insights
- Describes transfer-learning pipeline: DenseNet121 base (frozen) + custom Dense + Dropout layers.
- Mentions Streamlit deployment for user interaction.
- References external dataset source and model weight download URL.

a. Main components
1. Client (Web Browser)
2. Streamlit App (streamlit_app.py)
3. Model Loader/Inference Engine (TensorFlow/Keras + DenseNet121 + custom layers)
4. Model Artifact Storage (splitted_model/model.h5 parts combined at startup)
5. Offline Training & Evaluation Modules (Jupyter notebooks + dataset)
6. External Services (Kaggle dataset source, Google Drive / Streamlit Cloud)
b. Relationships & interactions
- User uploads or selects an image in the browser → HTTP request to Streamlit server
- Streamlit server reconstructs model.h5 from parts (or downloads weights) → loads into TensorFlow
- Inference Engine processes image → returns predicted class
- Streamlit UI displays results (class label + probability + optional confusion matrix visuals)
- Offline notebooks consume raw dataset → train/fine-tune model → export model.h5 → split into parts
c. Architectural patterns / design principles
- MVC-like separation: Streamlit’s UI widgets (View) + Python callbacks (Controller) + model artifacts (Model)
- Transfer-learning pipeline: frozen base + trainable head
- Modularity: notebooks isolated from deployment code, model parts separated from code
d. Key technologies/frameworks
- Python, Streamlit (UI + web server)
- TensorFlow/Keras (model loading & inference)
- Jupyter (training & evaluation)
- h5py (model file handling)
- External hosting: Streamlit Cloud, Google Drive

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Live Inference Path
    subgraph "Live Inference Path"
        direction TB
        Browser["Web Browser"]:::ui
        StreamlitApp["Streamlit Web App"]:::ui
        Requirements["requirements.txt"]:::dev
        ModelLoader["Model Loader & Reconstruction"]:::ml
        Inference["Inference Engine<br/>(TensorFlow/Keras)"]:::ml
        ModelStorage["Model Artifact Storage"]:::ml
    end

    Browser -->|"upload image"| StreamlitApp
    StreamlitApp -->|"requires deps"| Requirements
    StreamlitApp -->|"reconstruct model"| ModelLoader
    ModelLoader -->|"reads splits"| ModelStorage
    ModelLoader -->|"loads model"| Inference
    Inference -->|"predict class"| StreamlitApp
    StreamlitApp -->|"display results"| Browser
    StreamlitApp --> StreamlitCloud

    %% Offline Development Pipeline
    subgraph "Offline Development Pipeline"
        direction TB
        Dataset["Raw Dataset (Kaggle)"]:::ext
        NotebookTrain["Training Notebook<br/>(model_training.ipynb)"]:::dev
        NotebookEval["Evaluation Notebook<br/>(model_evaluation.ipynb)"]:::dev
        TestImages["Sample Test Images"]:::dev
    end

    Dataset --> NotebookTrain
    NotebookTrain -->|"export model.h5"| ModelStorage
    NotebookTrain --> NotebookEval
    NotebookEval -->|"uses splits"| ModelStorage
    NotebookEval -->|"uses samples"| TestImages

    %% External Services
    subgraph "External Services"
        direction TB
        GDrive["Weights Download<br/>(Google Drive)"]:::ext
        StreamlitCloud["Deployment Hosting<br/>(Streamlit Cloud)"]:::ext
    end

    GDrive --> StreamlitApp

    %% Click Events
    click StreamlitApp "https://github.com/m3mentomor1/breast-cancer-image-classification-with-densenet121/blob/main/streamlit_app.py"
    click ModelStorage "https://github.com/m3mentomor1/breast-cancer-image-classification-with-densenet121/tree/main/splitted_model/"
    click NotebookTrain "https://github.com/m3mentomor1/breast-cancer-image-classification-with-densenet121/blob/main/model_training.ipynb"
    click NotebookEval "https://github.com/m3mentomor1/breast-cancer-image-classification-with-densenet121/blob/main/model_evaluation.ipynb"
    click Requirements "https://github.com/m3mentomor1/breast-cancer-image-classification-with-densenet121/blob/main/requirements.txt"
    click TestImages "https://github.com/m3mentomor1/breast-cancer-image-classification-with-densenet121/tree/main/test_images/"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef ml fill:#D6F5D6,stroke:#28A745,color:#28A745;
    classDef dev fill:#E2E3E5,stroke:#6A737D,color:#6A737D;
    classDef ext fill:#FFE5B4,stroke:#FF8C00,color:#FF8C00;
```
