# liheyoung/unimatch architecture

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

- Interactive diagram: https://gitdiagram.com/liheyoung/unimatch
- Repository: https://github.com/liheyoung/unimatch

## Overview

##### Main Components
- Data Management:
– Dataset loading and preprocessing: Include “dataset”, “splits”, and data transformation routines (e.g., dataset/transform.py and similar files under more-scenarios).
– Configuration files for different datasets (e.g., configs/cityscapes.yaml, configs/coco.yaml, configs/pascal.yaml).
- Model Architecture:
– Backbone Networks: Represent “model/backbone” with nodes for ResNet and Xception.
– Segmentation Heads: Represent “model/semseg” (e.g., deeplabv3plus) for natural images, and also scenario-specific models like “medical/model/unet.py” and remote-sensing segmentation models (including PSPNet, as seen in the remote-sensing subfolder).
- Training Pipelines & Methods:
– Training Scripts: Clearly note the entry scripts (“fixmatch.py”, “unimatch.py”, “supervised.py”) and the shell scripts in “scripts” plus scenario-specific scripts.
– Semi-Supervised Mechanism: Emphasize the weak-to-strong consistency framework (the core idea behind UniMatch) which likely connects the outputs of two network predictions.
- Utilities & Helpers:
– Utility libraries found in “util” and “more-scenarios/…/util” for distributed training and loss functions (e.g., dist_helper.py, ohem.py, utils.py).

##### Relationships and Interactions
- How raw images (from various datasets) are ingested via the dataset directories and processed using transformation modules.
- Scenario branching: have a “core” pipeline for natural images while separately indicating how “more-scenarios” (under medical and remote sensing) re-use similar modules but with specialized configurations, models, and dataset management.

##### Architectural Patterns and Design Principles
- Modularity: Emphasize the separation of concerns (datasets, models, training loops, utilities).
- Reusability: Common utilities and modules are reused among different scenarios (natural, remote sensing, medical). An abstraction layer can be noted that helps swap out segmentation heads or backbones.
- Configuration-driven: The heavy use of YAML configuration files to define experimental parameters demonstrates a design that favors parameterization.

##### Relevant Technologies & Frameworks
- PyTorch for deep learning implementation (as seen in the installation steps and usage commands).
- Distributed/Semi-Supervised Training: Include elements for distributed training (e.g., use of torch.distributed.launch) with the provided training shell scripts.
- Integration with external datasets and pretrained backbone models, as indicated by the pretrained files and external dataset links.

##### Essential Elements
- Notations for external dependencies (e.g., pretrained weights, external dataset links) that come into play.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        A["Raw Data"]:::datalayer
        B["Dataset Loader (Natural Images)"]:::datalayer
        C["Dataset Loader (Medical)"]:::datalayer
        D["Dataset Loader (Remote Sensing)"]:::datalayer
        E["Dataset Splits"]:::datalayer
        F["Config (Natural: cityscapes, coco, pascal)"]:::config
        G["Config (Medical: acdc.yaml)"]:::config
        H["Config (Remote: levir.yaml, whu.yaml)"]:::config
    end

    %% Model Layer
    subgraph "Model Layer"
        I["Backbone (Natural: ResNet/Xception)"]:::model
        J["Segmentation (Natural: DeepLabv3+)"]:::model
        K["Backbone (Remote: ResNet)"]:::model
        L["Segmentation (Remote: DeepLabv3+ & PSPNet)"]:::model
        M["Segmentation (Medical: Unet)"]:::model
    end

    %% Training Layer
    subgraph "Training Layer"
        N["Training Scripts (Natural: fixmatch.py, unimatch.py, supervised.py)"]:::training
        O["Training Scripts (Medical: unimatch.py, supervised.py)"]:::training
        P["Training Scripts (Remote: unimatch.py, supervised.py)"]:::training
        Q["Semi-Supervised Consistency"]:::training
        R["Logging & Evaluation"]:::training
    end

    %% Utilities & Helpers
    subgraph "Utilities & Helpers"
        S["Common Utilities"]:::util
        T["Medical Utilities"]:::util
        U["Remote Utilities"]:::util
    end

    %% Data Layer Connections
    A --> B
    A --> C
    A --> D
    B --> E
    D --> E
    C --> M

    %% Configuration to Training Layer
    F --> N
    G --> O
    H --> P

    %% Model Layer Connections
    E --> I
    I --> J
    E --> K
    K --> L

    %% Training Flow Connections
    J --> Q
    M --> Q
    L --> Q
    N --> Q
    O --> Q
    P --> Q
    Q --> R

    %% Utilities Connections
    S --> N
    S --> I
    S --> J
    T --> O
    T --> M
    U --> P
    U --> K
    U --> L

    %% Click Events
    click B "https://github.com/liheyoung/unimatch/blob/main/dataset/transform.py"
    click C "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/medical/dataset/acdc.py"
    click D "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/remote-sensing/dataset/semicd.py"
    click E "https://github.com/liheyoung/unimatch/tree/main/splits/"
    click F "https://github.com/liheyoung/unimatch/blob/main/configs/cityscapes.yaml"
    click G "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/medical/configs/acdc.yaml"
    click H "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/remote-sensing/configs/levir.yaml"
    click I "https://github.com/liheyoung/unimatch/blob/main/model/backbone/resnet.py"
    click K "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/remote-sensing/model/backbone/resnet.py"
    click J "https://github.com/liheyoung/unimatch/blob/main/model/semseg/deeplabv3plus.py"
    click L "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/remote-sensing/model/semseg/pspnet.py"
    click M "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/medical/model/unet.py"
    click N "https://github.com/liheyoung/unimatch/blob/main/fixmatch.py"
    click O "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/medical/unimatch.py"
    click P "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/remote-sensing/unimatch.py"
    click S "https://github.com/liheyoung/unimatch/blob/main/util/utils.py"
    click T "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/medical/util/utils.py"
    click U "https://github.com/liheyoung/unimatch/blob/main/more-scenarios/remote-sensing/util/utils.py"

    %% Style Definitions
    classDef datalayer fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef model fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef training fill:#FFD700,stroke:#FF8C00,stroke-width:2px;
    classDef util fill:#DDA0DD,stroke:#800080,stroke-width:2px;
    classDef config fill:#F4A460,stroke:#D2691E,stroke-width:2px;
```
