# tsun/lada architecture

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

- Interactive diagram: https://gitdiagram.com/tsun/lada
- Repository: https://github.com/tsun/lada

## Overview

##### Project type and purpose
- This is a PyTorch‐based research codebase implementing “Local Context‐Aware Active Domain Adaptation (LADA).”
- It’s neither a web app nor a microservice mesh but a machine‐learning training pipeline that:
- Reads configurations and datasets
- Runs active‐learning samplers to select target samples
- Adapts a neural network via one of several domain‐adaptation solvers
- Logs metrics and checkpoints

- “main.py” (or `run.sh`) reads YAML → populates Config Manager →
- Config → instantiate Dataset class → DataLoader → feeds minibatches to Solver
- Solver calls Model → computes features → passes to loss & GRL layers → backprop
- After each iteration/epoch, Solver calls Active Sampler → queries new labels from target pool → updates labeled set
- Utilities (logger, lr_schedule) are invoked by Solver throughout
- Checkpoints & logs are written to disk (→ `log/…`)

##### Architectural patterns & principles
- Modular layering: clear separation between config, data, model, solver, sampler, utils
- Strategy pattern for both samplers and solvers: plug‐and‐play criteria and adaptation methods
- Single‐entry point: `main.py` orchestrates the pipeline based on configuration
- Reuse of PyTorch abstractions (Dataset, DataLoader, nn.Module, Optimizer, Scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Entry Point / Orchestrator"
        Main["main.py / run.sh"]:::orchestrator
    end

    subgraph "Configuration Management"
        Defaults["config/defaults.py"]:::config
        ConfigInit["config/__init__.py"]:::config
        YAML["configs/*.yaml"]:::config
    end

    subgraph "Data Layer"
        ImgList["data/image_list/..."]:::data
        Dataset["dataset/ASDADataset.py"]:::data
        ImgListPy["dataset/image_list.py"]:::data
        Transform["dataset/transform.py"]:::data
        RA["dataset/randaugment.py"]:::data
        RAMC["dataset/randaugmentMC.py"]:::data
    end

    subgraph "Active Sampler Layer"
        Sampler["active/sampler.py"]:::sampler
        LAS["active/LASsampler.py"]:::sampler
        MHP["active/MHPsampler.py"]:::sampler
        ABudget["active/budget.py"]:::sampler
        AUtils["active/utils.py"]:::sampler
        AInit["active/__init__.py"]:::sampler
    end

    subgraph "Model Definition"
        Network["model/network.py"]:::model
        Models["model/models.py"]:::model
        GRL["model/grl.py"]:::model
        Adaptor["model/adaptor.py"]:::model
        MInit["model/__init__.py"]:::model
    end

    subgraph "Solver / Trainer Layer"
        BaseSolver["solver/solver.py"]:::solver
        MME["solver/MMEsolver.py"]:::solver
        MCC["solver/MCCsolver.py"]:::solver
        CDAC["solver/CDACsolver.py"]:::solver
        PAA["solver/PAAsolver.py"]:::solver
        SUtils["solver/utils.py"]:::solver
        SInit["solver/__init__.py"]:::solver
    end

    subgraph "Utilities"
        Logger["utils/logger.py"]:::utils
        UtilsPy["utils/utils.py"]:::utils
        LRS["utils/lr_schedule.py"]:::utils
    end

    Outputs["Outputs (logs, checkpoints)"]:::outputs

    ExternalPyTorch("PyTorch"):::external
    ExternalCUDA("CUDA"):::external

    Defaults --> Main
    ConfigInit --> Main
    YAML --> Main

    ImgList --> Main
    Dataset --> Main
    ImgListPy --> Main
    Transform --> Main
    RA --> Main
    RAMC --> Main

    Main --> BaseSolver
    BaseSolver --> MME
    BaseSolver --> MCC
    BaseSolver --> CDAC
    BaseSolver --> PAA

    BaseSolver --> Network
    Network --> GRL
    Network --> Adaptor
    Network --- Models

    BaseSolver --> SUtils
    BaseSolver --> Logger
    BaseSolver --> UtilsPy
    BaseSolver --> LRS

    BaseSolver --> Sampler
    Sampler --> LAS
    Sampler --> MHP
    Sampler --> ABudget
    Sampler --> AUtils
    Sampler --> AInit
    Sampler --> BaseSolver

    BaseSolver --> Outputs

    BaseSolver --> ExternalPyTorch
    ExternalPyTorch --> BaseSolver
    BaseSolver --> ExternalCUDA

    click Defaults "https://github.com/tsun/lada/blob/master/config/defaults.py"
    click ConfigInit "https://github.com/tsun/lada/blob/master/config/__init__.py"
    click YAML "https://github.com/tsun/lada/blob/master/configs/office31.yaml"
    click ImgList "https://github.com/tsun/lada/tree/master/data/image_list/"
    click Dataset "https://github.com/tsun/lada/blob/master/dataset/ASDADataset.py"
    click ImgListPy "https://github.com/tsun/lada/blob/master/dataset/image_list.py"
    click Transform "https://github.com/tsun/lada/blob/master/dataset/transform.py"
    click RA "https://github.com/tsun/lada/blob/master/dataset/randaugment.py"
    click RAMC "https://github.com/tsun/lada/blob/master/dataset/randaugmentMC.py"
    click Sampler "https://github.com/tsun/lada/blob/master/active/sampler.py"
    click LAS "https://github.com/tsun/lada/blob/master/active/LASsampler.py"
    click MHP "https://github.com/tsun/lada/blob/master/active/MHPsampler.py"
    click ABudget "https://github.com/tsun/lada/blob/master/active/budget.py"
    click AUtils "https://github.com/tsun/lada/blob/master/active/utils.py"
    click AInit "https://github.com/tsun/lada/blob/master/active/__init__.py"
    click Network "https://github.com/tsun/lada/blob/master/model/network.py"
    click Models "https://github.com/tsun/lada/blob/master/model/models.py"
    click GRL "https://github.com/tsun/lada/blob/master/model/grl.py"
    click Adaptor "https://github.com/tsun/lada/blob/master/model/adaptor.py"
    click MInit "https://github.com/tsun/lada/blob/master/model/__init__.py"
    click BaseSolver "https://github.com/tsun/lada/blob/master/solver/solver.py"
    click MME "https://github.com/tsun/lada/blob/master/solver/MMEsolver.py"
    click MCC "https://github.com/tsun/lada/blob/master/solver/MCCsolver.py"
    click CDAC "https://github.com/tsun/lada/blob/master/solver/CDACsolver.py"
    click PAA "https://github.com/tsun/lada/blob/master/solver/PAAsolver.py"
    click SUtils "https://github.com/tsun/lada/blob/master/solver/utils.py"
    click SInit "https://github.com/tsun/lada/blob/master/solver/__init__.py"
    click Logger "https://github.com/tsun/lada/blob/master/utils/logger.py"
    click UtilsPy "https://github.com/tsun/lada/blob/master/utils/utils.py"
    click LRS "https://github.com/tsun/lada/blob/master/utils/lr_schedule.py"

    classDef config fill:#dddddd,stroke:#333,stroke-width:1px;
    classDef data fill:#aaddff,stroke:#333,stroke-width:1px;
    classDef sampler fill:#ccf2cc,stroke:#333,stroke-width:1px;
    classDef model fill:#ffd9b3,stroke:#333,stroke-width:1px;
    classDef solver fill:#e0ccff,stroke:#333,stroke-width:1px;
    classDef utils fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef orchestrator fill:#ffedcc,stroke:#333,stroke-width:1px;
    classDef outputs fill:#fff2cc,stroke:#333,stroke-width:1px;
    classDef external fill:#cccccc,stroke:#666,stroke-dasharray:5 5;
```
