# mahmoodlab/clam architecture

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

- Interactive diagram: https://gitdiagram.com/mahmoodlab/clam
- Repository: https://github.com/mahmoodlab/clam

## Overview

##### Main Components Identification

The system can be broken down into these major components:
- Data Processing Pipeline
- Feature Extraction Module
- CLAM Model Architecture
- Visualization System

##### Additional Elements

- Configuration files (yaml)
- Dataset management
- Model checkpoints storage
- Results output

##### Technical Details

Annotations for:
- Input image dimensions
- Feature dimensions (512/1024)
- Batch sizes
- GPU requirements
- Storage formats (.h5, .pt)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        WSI[Whole Slide Images]
    end

    subgraph "Data Processing"
        SEG["WSI Segmentation"]:::processing
        PATCH["Patch Extraction"]:::processing
        COORD["Patch Coordinates (.h5)"]:::storage
    end

    subgraph "Feature Extraction"
        FE["Feature Extractor"]:::feature
        BB{"Backbone Models"}:::feature
        FS["Feature Storage (.pt)"]:::storage
    end

    subgraph "CLAM Architecture"
        CLAM["CLAM Model"]:::model
        ATT["Attention Mechanism"]:::model
        INST["Instance-Level Clustering"]:::model
        MIL["Multiple Instance Learning"]:::model
        SB["CLAM-SB"]:::model
        MB["CLAM-MB"]:::model
    end

    subgraph "Training & Inference"
        TRAIN["Training Pipeline"]:::pipeline
        INFER["Inference Pipeline"]:::pipeline
        SPLIT["Cross-validation Splits"]:::pipeline
        EVAL["Evaluation Metrics"]:::pipeline
    end

    subgraph "Output"
        CLASS["Classification Results"]:::output
        VIS["Heatmap Visualization"]:::output
    end

    %% Connections
    WSI --> SEG
    SEG --> PATCH
    PATCH --> COORD
    COORD --> FE
    FE --> BB
    BB --> FS
    FS --> CLAM
    CLAM --> ATT & INST & MIL
    ATT & INST & MIL --> SB & MB
    SB & MB --> TRAIN & INFER
    TRAIN & INFER --> SPLIT
    SPLIT --> EVAL
    EVAL --> CLASS & VIS

    %% Styling
    classDef processing fill:#a8d1f0
    classDef feature fill:#90EE90
    classDef model fill:#FFB347
    classDef pipeline fill:#DDA0DD
    classDef output fill:#FF6961
    classDef storage fill:#F0E68C

    %% Click Events
    click SEG "https://github.com/mahmoodlab/CLAM/blob/master/wsi_core/WholeSlideImage.py"
    click PATCH "https://github.com/mahmoodlab/CLAM/blob/master/create_patches_fp.py"
    click FE "https://github.com/mahmoodlab/CLAM/blob/master/extract_features_fp.py"
    click CLAM "https://github.com/mahmoodlab/CLAM/blob/master/models/model_clam.py"
    click MIL "https://github.com/mahmoodlab/CLAM/blob/master/models/model_mil.py"
    click VIS "https://github.com/mahmoodlab/CLAM/blob/master/vis_utils/heatmap_utils.py"
    click TRAIN "https://github.com/mahmoodlab/CLAM/blob/master/main.py"
    click INFER "https://github.com/mahmoodlab/CLAM/blob/master/eval.py"
    click CLASS "https://github.com/mahmoodlab/CLAM/blob/master/create_heatmaps.py"
    click SPLIT "https://github.com/mahmoodlab/CLAM/blob/master/create_splits_seq.py"

    %% Legend
    subgraph Legend
        L1["Processing"]:::processing
        L2["Feature Extraction"]:::feature
        L3["Model Components"]:::model
        L4["Pipeline Steps"]:::pipeline
        L5["Output"]:::output
        L6["Storage"]:::storage
    end
```
