# shiqiyu/opengait architecture

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

- Interactive diagram: https://gitdiagram.com/shiqiyu/opengait
- Repository: https://github.com/shiqiyu/opengait

## Overview

##### Project Type & Purpose
- This is a full-stack machine-learning research codebase (“OpenGait”) for gait recognition.
- It orchestrates data preparation (many datasets + pretreatment scripts), model configuration (YAML files under configs/), training & evaluation pipelines (opengait/), and logging/checkpointing (output/, train.sh, test.sh).

##### File-Structure Analysis
- Top-level directories:
– configs/: YAML configurations for dozens of gait-recognition models and benchmarks.
– datasets/: Raw dataset definitions (JSON) + preprocessing scripts.
– opengait/: Core Python package – data loaders, transforms, models, losses, evaluators, main entrypoint.
– docs/: User tutorials & model-zoo results.
– misc/: Utility shell/Python scripts for cleaning and downloading.
– assets/: Images and logos referenced in README.
– output/: Checkpoint & tensorboard log stubs.
- Scripts: train.sh/test.sh launch opengait/main.py with selected config.
- CI: .github/workflows for stale-issue management.

##### Key Architectural Patterns
- Modular layering – clear separation of Data Layer, Model Layer, Training/Evaluation Orchestrator, Configuration Layer.
- Factory/Registry Pattern – model classes and datasets are registered and instantiated via config.
- PyTorch DDP & AMP support integrated into training pipeline.

##### Main Components & Interactions
[CONFIG MANAGER]
- Loads YAML (configs/) → instantiates Dataset, DataLoader, Model, Loss, Optimizer, DDP/AMP flags.
[DATA INGESTION]
- Raw datasets (datasets/) + pretreatment scripts → unified Dataset classes (opengait/data/dataset.py)
- Transform & sampler modules (opengait/data/transform.py, sampler.py, collate_fn.py)
- DataLoader (PyTorch) → batch tensors
[MODEL & LOSSES]
- Backbones (GCN, ResNet, ViT modules in opengait/modeling/backbones/)
- Head & full models (BigGait, DeepGaitV2, GaitBase, etc. in opengait/modeling/models/)
- Loss functions (ce, triplet, supcon in opengait/modeling/losses/)
- LossAggregator combines multi-losses
[TRAINING & EVALUATION]
- main.py orchestrates train/eval loops, handles DDP setup, checkpointing, AMP
- Evaluator & metrics (opengait/evaluation/) → compute accuracy, re-ranking, save results
[OUTPUT & LOGGING]
- Checkpoints & logs written to output/
- TensorBoard logging via opengait/utils/msg_manager.py

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Layer
    subgraph "Configuration Layer"
        ConfigFiles["configs/"]:::orchestration
        ConfigMgr["Config Manager\n(YAML loader)"]:::orchestration
    end

    %% Data Layer
    subgraph "Data Layer"
        RawData["Raw Data"]:::storage
        Pretreat["Pretreatment Scripts"]:::data
        DatasetClasses["Dataset Classes"]:::data
        Transforms["Transforms"]:::data
        Sampler["Sampler"]:::data
        CollateFn["CollateFn"]:::data
        DataLoader["DataLoader\n(PyTorch)"]:::data
    end

    %% Model & Loss Layer
    subgraph "Model & Loss Layer"
        Backbones["Model Backbones"]:::compute
        ModelZoo["Model Zoo"]:::compute
        LossFunctions["Loss Functions"]:::compute
        LossAggregator["Loss Aggregator"]:::compute
    end

    %% Orchestration Layer
    subgraph "Training & Evaluation"
        TrainingLoop["Training Loop\n(DDP & AMP)"]:::orchestration
        MsgManager["MsgManager\n(TensorBoard)"]:::orchestration
        Evaluation["Evaluation Module"]:::compute
    end

    %% Storage Layer
    subgraph "Output & CI"
        Output["Checkpoints & Logs"]:::storage
        CIWorkflow["CI Workflow"]:::external
    end

    %% Data Flow & Dependencies
    ConfigFiles --> ConfigMgr
    ConfigMgr --> DatasetClasses
    ConfigMgr --> Backbones
    ConfigMgr --> ModelZoo
    ConfigMgr --> LossFunctions
    ConfigMgr --> TrainingLoop

    RawData --> Pretreat
    Pretreat --> DatasetClasses
    DatasetClasses --> DataLoader
    Transforms --> DataLoader
    Sampler --> DataLoader
    CollateFn --> DataLoader

    DataLoader --> ModelZoo
    ModelZoo --> LossAggregator
    LossFunctions --> LossAggregator
    LossAggregator --> TrainingLoop

    TrainingLoop -->|trains| ModelZoo
    TrainingLoop --> MsgManager
    TrainingLoop --> Evaluation
    TrainingLoop --> Output
    Evaluation --> Output

    CIWorkflow -.-> ConfigFiles

    %% Click Events
    click ConfigFiles "https://github.com/shiqiyu/opengait/tree/master/configs/"
    click ConfigMgr "https://github.com/shiqiyu/opengait/blob/master/opengait/main.py"
    click RawData "https://github.com/shiqiyu/opengait/tree/master/datasets/"
    click Pretreat "https://github.com/shiqiyu/opengait/tree/master/datasets/"
    click DatasetClasses "https://github.com/shiqiyu/opengait/blob/master/opengait/data/dataset.py"
    click Transforms "https://github.com/shiqiyu/opengait/blob/master/opengait/data/transform.py"
    click Sampler "https://github.com/shiqiyu/opengait/blob/master/opengait/data/sampler.py"
    click CollateFn "https://github.com/shiqiyu/opengait/blob/master/opengait/data/collate_fn.py"
    click Backbones "https://github.com/shiqiyu/opengait/tree/master/opengait/modeling/backbones/"
    click ModelZoo "https://github.com/shiqiyu/opengait/tree/master/opengait/modeling/models/"
    click LossFunctions "https://github.com/shiqiyu/opengait/tree/master/opengait/modeling/losses/"
    click LossAggregator "https://github.com/shiqiyu/opengait/blob/master/opengait/modeling/loss_aggregator.py"
    click TrainingLoop "https://github.com/shiqiyu/opengait/blob/master/opengait/main.py"
    click MsgManager "https://github.com/shiqiyu/opengait/blob/master/opengait/utils/msg_manager.py"
    click Evaluation "https://github.com/shiqiyu/opengait/blob/master/opengait/evaluation/evaluator.py"
    click Output "https://github.com/shiqiyu/opengait/tree/master/output/"
    click CIWorkflow "https://github.com/shiqiyu/opengait/blob/master/.github/workflows/stale.yml"

    %% Styles
    classDef orchestration fill:#f9f871,stroke:#333,stroke-width:1px
    classDef data fill:#a4f9a4,stroke:#333,stroke-width:1px
    classDef compute fill:#a4d2f9,stroke:#333,stroke-width:1px
    classDef storage fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef external fill:#e0ccff,stroke:#333,stroke-width:1px
```
