# guijiejie/dual-conditioned-motion-diffusion architecture

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

- Interactive diagram: https://gitdiagram.com/guijiejie/dual-conditioned-motion-diffusion
- Repository: https://github.com/guijiejie/dual-conditioned-motion-diffusion

## Overview

##### Project Type & Purpose
- This project implements a research framework for video anomaly detection using pose-based data. It leverages a diffusion model that is “dual conditioned” – from both motion features and latent embeddings – to integrate reconstruction and prediction methods.
- The README details the dual conditioning, a motion transformer for reverse diffusion, and a novel United Association Discrepancy regularization. The project is primarily research-focused but also includes production-ready training and evaluation pipelines.

##### Analyzing the File Structure
- Top-Level Directories:
– config: Contains YAML files for different datasets (Avenue, STC, UBnormal) that outline training and testing configurations. This indicates environment-specific settings for anomaly detection experiments.
– models: Houses different modeling components:
▪ models/dcmd.py: Contains the core diffusion model implementation.
▪ models/gcae: Appears to include a graph-based convolutional network component (stsgcn.py) indicating an emphasis on capturing pose relations.
▪ models/stsae and models/transformer.py: Likely implement additional architectural models (e.g., motion transformer, autoencoder variants for pose reconstruction).
▪ models/common/components.py: Contains shared modules that are probably reused across model variants.
– utils: Collection of helper functions and modules for data handling, pre-/post-processing, evaluation, diffusion dynamics, argument parsing, and others.
– Environment and script files: Files like train_DCMD.py and eval_DCMD.py are the main entry points for training and evaluation respectively, while environment.yaml sets up dependencies.

##### Interactions & Data Flow
- How configuration files impact both training and evaluation scripts.
- The flow of data from the pre-processing utilities to the modeling components.
- Interaction between the diffusion process, motion condition, and transformer modules to generate predictions.
- The feedback loop during training where evaluation metrics could influence further training or settings adjustments.

##### Architectural Patterns & Technologies
- Diffusion models with reverse processes, motion transformers, and graph convolutional networks indicate advanced deep learning and computer vision architectures.
- The design promotes extensibility—configuration driving experiment setups per dataset and model component reusability is an important design aspect.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Layer
    subgraph "Configuration Layer"
        CFG["YAML Config Files"]:::config
    end

    %% Data Handling & Preprocessing
    subgraph "Data Handling & Preprocessing"
        DATA["Data Ingestion & Preprocessing"]:::preproc
        DATA1["data.py"]:::preproc
        DATA2["dataset.py"]:::preproc
        DATA3["dataset_utils.py"]:::preproc
        DATA4["preprocessing.py"]:::preproc
        DATA --> DATA1
        DATA --> DATA2
        DATA --> DATA3
        DATA --> DATA4
    end

    %% Modeling Layer
    subgraph "Modeling Layer"
        DCMD["DCMD Core Model"]:::model
        MT["Motion Transformer"]:::model
        GCAE["Graph Convolution (GCAE)"]:::model
        STSAE["STSAE Autoencoder Branches"]:::model
        SHARED["Shared Components"]:::model
        %% Indicate integration of dual conditioned streams into the diffusion model
        MT --> DCMD
        GCAE --> DCMD
        STSAE --> DCMD
        SHARED --> DCMD
    end

    %% Pipelines for Training and Evaluation
    subgraph "Pipelines"
        TRAIN["Training Pipeline"]:::pipeline
        EVAL["Evaluation Pipeline"]:::pipeline
    end

    %% Utility & Helper Functions
    subgraph "Utility & Helper Functions"
        DIFF["Diffusion Utils"]:::utility
        EMA["EMA Utilities"]:::utility
        ARGP["Arg Parser"]:::utility
        MODELUTIL["Model Utilities"]:::utility
    end

    %% Data Flow Connections
    CFG --> TRAIN
    CFG --> EVAL
    DATA --> DCMD
    DATA --> TRAIN
    DATA --> EVAL
    TRAIN --> DCMD
    DCMD --> EVAL
    TRAIN --> DIFF
    TRAIN --> EMA
    TRAIN --> ARGP
    TRAIN --> MODELUTIL
    EVAL --> DIFF
    EVAL --> MODELUTIL
    EVAL --> CFG

    %% Click Events
    click CFG "https://github.com/guijiejie/dual-conditioned-motion-diffusion/tree/main/config"
    click DATA1 "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/utils/data.py"
    click DATA2 "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/utils/dataset.py"
    click DATA3 "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/utils/dataset_utils.py"
    click DATA4 "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/utils/preprocessing.py"
    click DCMD "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/models/dcmd.py"
    click MT "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/models/transformer.py"
    click GCAE "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/models/gcae/stsgcn.py"
    click STSAE "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/models/stsae/stsae.py"
    click SHARED "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/models/common/components.py"
    click TRAIN "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/train_DCMD.py"
    click EVAL "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/eval_DCMD.py"
    click DIFF "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/utils/diffusion_utils.py"
    click EMA "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/utils/ema.py"
    click ARGP "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/utils/argparser.py"
    click MODELUTIL "https://github.com/guijiejie/dual-conditioned-motion-diffusion/blob/main/utils/model_utils.py"

    %% Styles
    classDef config fill:#CDEBFF,stroke:#000,stroke-width:2px;
    classDef preproc fill:#FFE4B5,stroke:#000,stroke-width:2px;
    classDef model fill:#B0E0E6,stroke:#000,stroke-width:2px;
    classDef pipeline fill:#FFFFE0,stroke:#000,stroke-width:2px;
    classDef utility fill:#E6E6FA,stroke:#000,stroke-width:2px;
```
