# aipi540spring2025avengers/retinal-fundus-disorder-detection architecture

> Architecture diagram of the GitHub repository aipi540spring2025avengers/retinal-fundus-disorder-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aipi540spring2025avengers/retinal-fundus-disorder-detection
- Repository: https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection

## Overview

##### Main Components
- User Interface: Represented by main.py, which launches the Streamlit web app. This component accepts user image uploads and displays prediction results from all approaches.
- Data Management: Include the data directory and its subdirectories for raw, processed, and output data. This is the central repository for the retinal images and results used for both training and inference.
- Machine Learning Pipelines:
- Naïve Approach: Illustrated by scripts/naive containing the rule-based classifier logic. It uses image properties such as edge density and brightness.
- Deep Learning: Under scripts/deep, the deep learning model training is handled (using an EfficientNet-B4 based CNN). Pre-trained deep models (as seen with mobilenetv3.pth in the models directory) should be clearly indicated.
- Notebooks: The notebooks directory (with EDA.ipynb and naive_eva.ipynb) shows exploratory analysis and validation, useful for illustrating where experimentation and diagnostics occur.

##### Relationships and Interactions
- Model Artifacts: Connect the training scripts (in the scripts folders) with the models directory to show how models get saved and later loaded by the inference routines.
- Integration: Tie the outputs from the pipelines back to the Streamlit UI (main.py), which collates the predictions and displays them to the user.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Different pipelines are separated into discrete directories (naive, traditional, deep), clearly indicating modular design.
- Reusable Components: The central data folder, configuration files (requirements.txt, packages.txt), and setup scripts (setup.sh) show that the project is designed to be reproducible and maintainable.

##### Relevant Technologies and Frameworks
- Python scripts for algorithmic implementations.
- Streamlit for the user interface.
- Various ML libraries (likely scikit-learn for SVM and PCA, Torch for deep learning models, and OpenCV/numpy for image pre-processing in the naive approach).
- EfficientNet-B4 architecture for deep learning.

##### Implementation Strategy
- For each processing pipeline, break it down further to showcase sub-stages: pre-processing, model inference, and output.
- Incorporate notes (possibly annotations) that mention critical dependencies like the setup.sh environment initialization, the importance of GPU/TPU for deep learning model training, and the use of pre-trained models.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface
    UI["User Interface (Streamlit App)"]:::ui

    %% Data Management Subgraph
    subgraph "Data Management"
        RAW["Raw Data"]:::data
        PROCESSED["Processed Data"]:::data
        OUTPUT["Output Data"]:::data
        RAW -->|"processes_to"| PROCESSED
        PROCESSED -->|"stores"| OUTPUT
    end

    %% Pipelines Subgraph
    subgraph "Processing Pipelines"
        %% Naïve Pipeline Subgraph
        subgraph "Naïve Pipeline"
            NAIVE["Rule-Based Classifier"]:::pipeline
            NAIVE_LOGIC["Classifier Logic (model.py & main_test.py)"]:::pipeline
            NAIVE -->|"predicts"| NAIVE_LOGIC
        end

        %% Traditional ML Pipeline Subgraph
        subgraph "Traditional ML Pipeline"
            TRAD_PRE["Preprocessing (preprocessingML.py)"]:::pipeline
            TRAD_MODEL["SVM Model (modelML.py)"]:::pipeline
            TRAD_ARTIFACT["Model Artifacts (TRADML_encoder.pkl, TRADML_model.pkl)"]:::artifact
            TRAD_PRE -->|"features"| TRAD_MODEL
            TRAD_MODEL -->|"saves/loads"| TRAD_ARTIFACT
        end

        %% Deep Learning Pipeline Subgraph
        subgraph "Deep Learning Pipeline"
            DEEP_MODEL["Deep Model (model.py)"]:::pipeline
            DEEP_ARTIFACT["Model Artifact (mobilenetv3.pth)"]:::artifact
            DEEP_MODEL -->|"utilizes"| DEEP_ARTIFACT
        end
    end

    %% Experimentation & Diagnostics
    NOTEBOOKS["Experimentation & Diagnostics (Notebooks)"]:::notebook

    %% Data Flow Connections
    UI -->|"uploads image"| RAW
    RAW ---|"data served"| NAIVE
    RAW ---|"data served"| TRAD_PRE
    RAW ---|"data served"| DEEP_MODEL
    NAIVE_LOGIC -->|"results to"| OUTPUT
    TRAD_MODEL -->|"results to"| OUTPUT
    DEEP_MODEL -->|"results to"| OUTPUT
    OUTPUT -->|"display results"| UI

    %% Notebooks analyze processed output
    OUTPUT ---|"analysis"| NOTEBOOKS

    %% Click Events
    click UI "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/main.py"
    click RAW "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/tree/main/data/raw"
    click PROCESSED "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/tree/main/data/processed"
    click OUTPUT "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/tree/main/data/outputs"
    click NAIVE "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/tree/main/scripts/naive/"
    click NAIVE_LOGIC "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/scripts/naive/main_test.py"
    click NAIVE_LOGIC "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/scripts/naive/model.py"
    click TRAD_PRE "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/tree/main/scripts/traditional/"
    click TRAD_MODEL "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/scripts/traditional/modelML.py"
    click TRAD_PRE "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/scripts/traditional/preprocessingML.py"
    click TRAD_ARTIFACT "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/models/TRADML_encoder.pkl"
    click TRAD_ARTIFACT "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/models/TRADML_model.pkl"
    click DEEP_MODEL "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/scripts/deep/model.py"
    click DEEP_ARTIFACT "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/models/mobilenetv3.pth"
    click NOTEBOOKS "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/tree/main/notebooks/"
    click NOTEBOOKS "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/notebooks/EDA.ipynb"
    click NOTEBOOKS "https://github.com/aipi540spring2025avengers/retinal-fundus-disorder-detection/blob/main/notebooks/naive_eva.ipynb"

    %% Styling
    classDef ui fill:#ffeb3b,stroke:#333,stroke-width:2px;
    classDef data fill:#b3e5fc,stroke:#0277bd,stroke-width:2px;
    classDef pipeline fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef artifact fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef notebook fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
```
