# souhib-khalbous/breast-cancer_-computer-vision architecture

> Architecture diagram of the GitHub repository souhib-khalbous/breast-cancer_-computer-vision, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/souhib-khalbous/breast-cancer_-computer-vision
- Repository: https://github.com/souhib-khalbous/breast-cancer_-computer-vision

## Overview

- A BI-RADS classification pipeline to classify breast images based on the BI-RADS type.
- An object detection and segmentation pipeline aimed at identifying key features such as calcifications and masses, likely using U-Net–based models.

##### Main Components
a. BI-RADS Classification Pipeline:
- Training Module ("BI-RADS Type Classification Task/Train-classification"): Contains multiple Jupyter notebooks that describe different models (e.g., variants of Combined-Model with ConvNext and Swin) used for training.
- Inference Module ("BI-RADS Type Classification Task/Inference"): Includes notebooks for different inference tasks, such as preprocessing (PreprocessInference.ipynb), image conversion (pngConverter.ipynb), and the main inference procedure (Inference.ipynb). Also, there are JSON configuration or pixel mapping files.
b. Object Detection Pipeline:
- Preprocessing Stage ("Object Detection/Stage.1_First"): Preprocessing notebooks that likely prepare the data.
- Middle Stage (“Object Detection/Stage.2_Middle”): Loads models and performs key segmentation steps using U-Net models for both calcification and mass detection.
- Final Stage (“Object Detection/Stage.3_Final”): Updates JSON outputs or integrates the results (Json_Updator_code.ipynb).
- U-Net Model Components (“Object Detection/U-Net Models files”): Notebooks that explain the U-Net architecture for both calcification and mass.
- Model Weights (h5 Files): Stores the trained model parameters in organized folders to separate “Best h5” from custom training results.
c. Shared or Supporting Elements:
- Common configuration and readme files that help outline project metadata.
- Potential utility scripts (e.g., Pixelers.json file and additional outputs.json) which might serve as connectors or configuration mechanisms between different steps.

##### Relationships and Data Flow
a. For the Classification Pipeline:
- An entry point for input images that flow into a preprocessing step.
- Branch the process into two paths: one for training and one for inference.
- For inference, illustrate how input images (or batches) are preprocessed and then run through the trained models to output BI-RADS classification results.
b. For the Object Detection Pipeline:
- Out the three clear processing stages (Stage 1: Preprocessing, Stage 2: Model Loading/Processing, Stage 3: Output Integration).
- Within Stage 2, explicitly differentiate between the calcification and mass detection submodules – each loading their respective U-Net models.
- Detections to a final module that updates or consolidates findings (using JSON updation).

##### Architectural Patterns and Design Principles
a. Separation of concerns: The project separates training from inference. Similarly, the object detection pipeline is divided into distinct stages (preprocessing, processing, and post-processing).
b. Modular design: Components like U-Net model definitions and the multiple notebooks for training different models indicate a design that supports experimentation and extensibility.
c. Pipeline architecture: Each task (classification and detection) follows a pipeline or staged approach that allows one stage’s output to be the next stage’s input.

##### Technologies, Frameworks, and File Artifacts
a. Clearly mention that the system relies on Jupyter notebooks for high-level orchestration of tasks.
b. That the deep learning models use modern architectures such as ConvNext, Swin Transformer, and U-Net.
c. That model weights are stored in .h5 files, indicating the use of frameworks like Keras or TensorFlow.

##### Elements
– Data input → Preprocessing → Model Training/Inference → Output generation.
d. Annotations or comments to each component as needed to denote:
– The file type (Jupyter notebooks, h5 files, JSON configuration),
– The role of the component in the overall workflow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global Input
    imgInput("Image Input"):::input

    %% BI-RADS Classification Pipeline
    subgraph "BI-RADS Classification Pipeline"
        direction TB
        classPre("Preprocessing for Classification"):::process
        %% Branch: Training
        subgraph "Training Branch"
            training("Training Module"):::train
        end
        %% Branch: Inference
        subgraph "Inference Branch"
            inference("Inference Module"):::infer
            preprocess("PreprocessInference.ipynb"):::notebook
            converter("pngConverter.ipynb"):::notebook
            inferenceNote("Inference.ipynb"):::notebook
            jsonPixel("539822_Pixelers.json"):::json
            jsonOutput("outputs.json"):::json
        end
    end

    %% Object Detection Pipeline
    subgraph "Object Detection Pipeline"
        direction TB
        odPre("Preprocessing Stage"):::process
        subgraph "Middle Stage"
            direction TB
            calcLoad("Calcification Model Loading"):::unet
            calcUNet("Calcification U-Net Model"):::unet
            massLoad("Mass Model Loading"):::unet
            massUNet("Mass U-Net Model"):::unet
            weights("Model Weights Storage (h5 Files)"):::store
        end
        odFinal("Output Integration (JSON Updator)"):::output
    end

    %% Connections for BI-RADS Classification Pipeline
    imgInput -->|"flows to"| classPre
    classPre -->|"triggers"| training
    classPre -->|"triggers"| inference
    inference -->|"runs"| preprocess
    preprocess -->|"converts"| converter
    converter -->|"executes"| inferenceNote
    inferenceNote -->|"generates"| jsonPixel
    inferenceNote -->|"generates"| jsonOutput

    %% Connections for Object Detection Pipeline
    imgInput -->|"feeds"| odPre
    odPre -->|"prepares data"| calcLoad
    odPre -->|"prepares data"| massLoad
    calcLoad -->|"processes"| calcUNet
    massLoad -->|"processes"| massUNet
    calcLoad -->|"uses weights"| weights
    massLoad -->|"uses weights"| weights
    calcUNet -->|"outputs"| odFinal
    massUNet -->|"outputs"| odFinal

    %% Click Events for BI-RADS Classification Pipeline
    click training "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/tree/master/BI-RADS Type Classification Task/Train-classification"
    click inference "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/tree/master/BI-RADS Type Classification Task/Inference"
    click preprocess "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/BI-RADS Type Classification Task/Inference/PreprocessInference.ipynb"
    click converter "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/BI-RADS Type Classification Task/Inference/pngConverter.ipynb"
    click inferenceNote "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/BI-RADS Type Classification Task/Inference/Inference.ipynb"
    click jsonPixel "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/BI-RADS Type Classification Task/Inference/539822_Pixelers.json"
    click jsonOutput "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/BI-RADS Type Classification Task/Inference/outputs.json"

    %% Click Events for Object Detection Pipeline
    click odPre "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/Object Detection/Stage.1_First/Preprocessing.ipynb"
    click calcLoad "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/Object Detection/Stage.2_Middle/Calcification_Loading_Model_Unet.ipynb"
    click calcUNet "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/Object Detection/U-Net Models files/Calcification_UNet.ipynb"
    click massLoad "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/Object Detection/Stage.2_Middle/Mass_Loading_Model_Unet.ipynb"
    click massUNet "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/Object Detection/U-Net Models files/Mass_UNet.ipynb"
    click odFinal "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/blob/master/Object Detection/Stage.3_Final/Json_Updator_code.ipynb"
    click weights "https://github.com/souhib-khalbous/breast-cancer_-computer-vision/tree/master/Object Detection/h5 Files"

    %% Styles
    classDef input fill:#bbf,stroke:#333,stroke-width:2px;
    classDef process fill:#cff,stroke:#333,stroke-width:2px;
    classDef train fill:#cfc,stroke:#333,stroke-width:2px;
    classDef infer fill:#fcf,stroke:#333,stroke-width:2px;
    classDef notebook fill:#ff9,stroke:#333,stroke-width:2px;
    classDef json fill:#fee,stroke:#333,stroke-width:2px;
    classDef unet fill:#ffd,stroke:#333,stroke-width:2px;
    classDef store fill:#dfd,stroke:#333,stroke-width:2px;
    classDef output fill:#fdd,stroke:#333,stroke-width:2px;
```
