# suhas-srinath/genselfdiff-his architecture

> Architecture diagram of the GitHub repository suhas-srinath/genselfdiff-his, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/suhas-srinath/genselfdiff-his
- Repository: https://github.com/suhas-srinath/genselfdiff-his

## Overview

##### Project’s Main Components
- Data Pre-processing:
- This module handles data ingestion and preparation from various sources (e.g., GlaS, HN, MoNuSeg).
- In the file tree, the “pre_process” directory (with subfolders for each dataset) houses Python scripts converting images (bmp_to_jpg.py, xml_to_segmask.py, image_labels.py) and patch generation (train, test, unlabel tasks).

- Pre-training (Generative Self-supervision using Diffusion):
- Located in “GenSelfDiff/pretrain”, this contains scripts like SS_diff.py, model.py, and utils.py where the diffusion-based generative model is implemented.
- This is the stage where unlabeled data is used to train the diffusion model as a pretext task.

- Downstream Training for Segmentation:
- Found in “GenSelfDiff/downstream_train”, where the segmentation-specific training happens using a diffusion pre-trained model.
- Key files include Diff_Seg.py, losses.py, and model.py, which likely incorporate multi-loss optimization to fine-tune the segmentation task.

- Evaluation and Testing:
- Residing in “GenSelfDiff/test”, components like test_script.py and metrics.py allow evaluation on segmentation performance.

- Additional/Utility Modules:
- Standalone scripts like image_generation.py, HE_diff_general.py, and sample_images*.py suggest auxiliary functionalities or experiments.
- The “utils_general.py” file provides helper routines that might be used across different stages.

##### Relationships and Data Flow
- Data flows into the Data Pre-processing component where images are transformed, normalized, or split into patches.
- The pre-processed data then feeds into the Pre-training module, where the generative diffusion model learns self-supervised representations.
- The scored pre-trained model is used for the Downstream Training phase to fine-tune the segmentation performance with supervised signals.
- Finally, the Evaluation module uses the produced segmentation outputs to compute metrics and assess system performance.

##### Architectural Patterns and Technologies
- The project uses a staged learning approach: a self-supervised (pre-training) stage followed by a downstream supervised segmentation training stage.
- Diffusion models form the core of the generative self-supervision, which is a key novel idea.
- There is an emphasis on modular design: pre-processing, training, and evaluation are clearly separated, suggesting a pipeline or orchestrated workflow.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Raw Data Sources
    subgraph "Raw Data Sources"
        A("Histopathological Images (GlaS, HN, MoNuSeg)"):::source
    end

    %% Data Pre-processing Module
    subgraph "Data Pre-processing Module"
        B1("GlaS"):::preprocessing
        B2("HN"):::preprocessing
        B3("MoNuSeg"):::preprocessing
    end

    %% Pre-training Module (Diffusion-based Self-supervision)
    subgraph "Pre-training Module (Diffusion-based Self-supervision)"
        C1("SS_diff.py"):::training
        C2("Model.py"):::training
        C3("Utils.py"):::training
    end

    %% Downstream Segmentation Training Module
    subgraph "Downstream Segmentation Training Module"
        D1("Diff_Seg.py"):::training
        D2("Losses.py"):::training
        D3("Model.py"):::training
    end

    %% Evaluation & Testing Module
    subgraph "Evaluation & Testing Module"
        E1("Test_script.py"):::evaluation
        E2("Metrics.py"):::evaluation
    end

    %% Supporting Utilities
    subgraph "Supporting Utilities"
        F1("image_generation.py"):::utility
        F2("image_generation_general.py"):::utility
        F3("sample_images.py"):::utility
        F4("sample_images_general.py"):::utility
        F5("utils_general.py"):::utility
        F6("HE_diff_general.py"):::utility
    end

    %% Data Flow
    A -->|"input"| B1
    A -->|"input"| B2
    A -->|"input"| B3

    B1 -->|"processed"| C1
    B2 -->|"processed"| C1
    B3 -->|"processed"| C1

    C1 -->|"pre-trained"| D1

    D1 -->|"segmentation"| E1
    D1 -->|"segmentation"| E2

    %% Styles
    classDef source fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef preprocessing fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef training fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef evaluation fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef utility fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events for Data Pre-processing
    click B1 "https://github.com/suhas-srinath/genselfdiff-his/tree/main/pre_process/GlaS"
    click B2 "https://github.com/suhas-srinath/genselfdiff-his/tree/main/pre_process/HN"
    click B3 "https://github.com/suhas-srinath/genselfdiff-his/tree/main/pre_process/MoNuSeg"

    %% Click Events for Pre-training
    click C1 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/GenSelfDiff/pretrain/SS_diff.py"
    click C2 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/GenSelfDiff/pretrain/model.py"
    click C3 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/GenSelfDiff/pretrain/utils.py"

    %% Click Events for Downstream Training
    click D1 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/GenSelfDiff/downstream_train/Diff_Seg.py"
    click D2 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/GenSelfDiff/downstream_train/losses.py"
    click D3 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/GenSelfDiff/downstream_train/model.py"

    %% Click Events for Evaluation and Testing
    click E1 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/GenSelfDiff/test/test_script.py"
    click E2 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/GenSelfDiff/test/metrics.py"

    %% Click Events for Supporting Utilities
    click F1 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/image_generation.py"
    click F2 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/image_generation_general.py"
    click F3 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/sample_images.py"
    click F4 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/sample_images_general.py"
    click F5 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/utils_general.py"
    click F6 "https://github.com/suhas-srinath/genselfdiff-his/blob/main/HE_diff_general.py"
```
