# webber2933/st-clip architecture

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

- Interactive diagram: https://gitdiagram.com/webber2933/st-clip
- Repository: https://github.com/webber2933/st-clip

## Overview

##### Project Type and Purpose
- This is a research‐grade deep‐learning library and training/inference pipeline for zero‐shot action detection. It integrates a pretrained image‐language model (CLIP) with custom spatio‐temporal prompting modules and CUDA/C++ extensions to detect actions in video frames without task-specific finetuning.

##### Key Components (based on file tree & README)
a. External Dependencies
- PyTorch, torchvision, CUDA
- CLIP code (clip/ folder)
- timm (integrated under modeling/timm)
b. Configuration
- ST-CLIP.yaml (config_files/)
- defaults.py, paths_catalog.py (STCLIP/config/)
- setup.py, requirements.txt
c. Data & Annotation
- J-HMDB video frames & labels (annotation/)
- dataset/ (build, collate_batch, transforms, samplers)
- benchmarks/ (predefined train/test splits)
d. Core Model Code (STCLIP package)
- csrc/ (custom CPU & CUDA ops: ROIAlign3d, ROIPool3d, focal losses)
- modeling/
– detector/action_detector.py
– roi_heads/action_head (context prompting, loss, metric, inference)
– timm (vision backbones, losses, optimizers, schedulers)
- layers/ (Python wrappers for focal loss)
e. Engine & Solver
- engine/trainer.py, inference.py
- solver/build.py, lr_scheduler.py
f. Utilities
- utils/ (logging, checkpointing, registry, seeding, serialization)
g. Entry Points
- train_net.py, test_net.py

##### Relationships & Data Flow
- Data Preparation: annotation files → dataset build → transforms & samplers → PyTorch DataLoader
- Model Input: video frames + CLIP text prompts (prompt.py) → visual encoder (CLIP/timm backbone) + context prompting module
- Region Proposals & ROI: ROIAlign3d/ROIPool3d (custom C++/CUDA) extracts spatio-temporal features
- Action Head:
- Person-Context Interaction (combines visual tokens + context prompts)
- Interest Token Spotting (selects relevant tokens per action)
- Classification & localization
- Loss Computation: Sigmoid/Softmax focal losses (Python wrappers → CUDA kernels)
- Training Loop: engine/trainer uses solver (optimizer, scheduler)
- Inference Loop: engine/inference produces detections → evaluation (jhmdb_eval.py)

##### Architectural Patterns & Design Principles
- Modular registry pattern (modeling/registry.py, utils/registry.py) for pluggable detectors, backbones, optimizers
- Configuration‐driven experiments (YAML configs + defaults)
- Separation of concerns:
- Data I/O (dataset/)
- Model definition (modeling/)
- Training/inference orchestration (engine/, solver/)
- Native performance kernels (csrc/)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    subgraph "External Dependencies"
        style ED fill:#f9f,stroke:#333,stroke-width:1px
        PT["PyTorch"]:::external
        CLIP["CLIP Code"]:::external
        TIMM["timm Backbones"]:::external
    end

    %% Configuration
    subgraph "Configuration"
        style CFG fill:#cff,stroke:#333,stroke-width:1px
        YML["ST-CLIP.yaml"]:::config
        DFLT["defaults.py<br/>paths_catalog.py"]:::config
        SETUP["setup.py<br/>requirements.txt"]:::config
    end

    %% Data & Annotation Layer
    subgraph "Data & Annotation" 
        style DATA fill:#bbf,stroke:#333,stroke-width:1px
        ANNO[(annotation/)]:::data
        BMKS[(benchmarks/)]:::data
        DS["Dataset Build<br/>transforms, samplers"]:::data
    end

    %% Core Model Components
    subgraph "Model Components"
        style MODEL fill:#bfb,stroke:#333,stroke-width:1px
        REG["Registry Pattern"]:::model
        CLIP_BACK["CLIP & Vision Backbone"]:::model
        PROMPT["Context Prompting<br/>text_feature_gen"]:::model
        ROI3D["Spatio-Temporal ROI Ops"]:::ext
        ACT_DET["Action Detector"]:::model
        ROI_HEAD3D["3D ROI Heads Utils"]:::model
        LOSS_PY["Loss Wrappers"]:::model
        BBOX["Bounding Box Structs"]:::model
    end

    %% Engine & Solver
    subgraph "Engine & Solver"
        style ENG fill:#fb8,stroke:#333,stroke-width:1px
        TRAIN["trainer.py"]:::engine
        INF["inference.py"]:::engine
        BUILD["build.py"]:::engine
        SCHED["lr_scheduler.py"]:::engine
        UTILS["utils (logging, checkpoint)"]:::engine
    end

    %% Entry Points & Scripts
    subgraph "Entry Points"
        style ENTRY fill:#ffd,stroke:#333,stroke-width:1px
        TRAIN_SCRIPT["train_net.py"]:::engine
        TEST_SCRIPT["test_net.py"]:::engine
        PROMPT_LAUNCH["prompt.py"]:::model
    end

    %% Evaluation
    subgraph "Evaluation"
        style EVAL fill:#fdb,stroke:#333,stroke-width:1px
        EVAL_SCRIPT["jhmdb_eval.py"]:::eval
    end

    %% External Dependencies Links
    click CLIP "https://github.com/webber2933/st-clip/tree/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/clip/"
    click TIMM "https://github.com/webber2933/st-clip/tree/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/modeling/timm/"

    %% Configuration Links
    click YML "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/config_files/STCLIP.yaml"
    click DFLT "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/config/defaults.py"
    click DFLT "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/config/paths_catalog.py"
    click SETUP "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/setup.py"
    click SETUP "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/requirements.txt"

    %% Data & Annotation Links
    click ANNO "https://github.com/webber2933/st-clip/tree/main/ZS_JHMDB/annotation/"
    click DS "https://github.com/webber2933/st-clip/tree/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/dataset/"
    click BMKS "https://github.com/webber2933/st-clip/tree/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/benchmarks/"

    %% Core Model Links
    click ROI3D "https://github.com/webber2933/st-clip/tree/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/csrc/"
    click ACT_DET "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/modeling/detector/action_detector.py"
    click PROMPT "https://github.com/webber2933/st-clip/tree/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/modeling/roi_heads/action_head/"
    click ROI_HEAD3D "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/modeling/roi_heads/roi_heads_3d.py"
    click REG "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/modeling/registry.py"
    click REG "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/utils/registry.py"
    click LOSS_PY "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/layers/sigmoid_focal_loss.py"
    click LOSS_PY "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/layers/softmax_focal_loss.py"
    click BBOX "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/structures/bounding_box.py"

    %% Engine & Solver Links
    click TRAIN "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/engine/trainer.py"
    click INF "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/engine/inference.py"
    click BUILD "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/solver/build.py"
    click SCHED "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/solver/lr_scheduler.py"
    click UTILS "https://github.com/webber2933/st-clip/tree/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/STCLIP/utils/"

    %% Entry Points Links
    click TRAIN_SCRIPT "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/train_net.py"
    click TEST_SCRIPT "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/test_net.py"
    click PROMPT_LAUNCH "https://github.com/webber2933/st-clip/blob/main/ZS_JHMDB/ZS_JHMDB/ST-CLIP/prompt.py"

    %% Data Flow Relationships
    ANNO -->|video frames & labels| DS
    BMKS -->|splits| DS
    DS -->|DataLoader| TRAIN

    %% Config & Registry Flow
    YML --> REG
    DFLT --> REG
    SETUP --> REG

    %% Model Flow
    TRAIN -->|config & registry| REG
    PROMPT_LAUNCH --> REG
    PROMPT_LAUNCH --> PROMPT
    CLIP_BACK --> ACT_DET
    PROMPT --> ACT_DET
    ACT_DET --> ROI3D
    ROI3D --> ACT_DET
    ACT_DET --> LOSS_PY
    LOSS_PY --> TRAIN

    %% Engine & Solver
    TRAIN --> BUILD
    BUILD --> SCHED
    SCHED --> TRAIN
    TRAIN --> UTILS
    INF --> UTILS

    %% Entry Points to Engine
    TRAIN_SCRIPT --> TRAIN
    TEST_SCRIPT --> INF

    %% Evaluation
    TEST_SCRIPT --> EVAL_SCRIPT
    BMKS --> EVAL_SCRIPT
    EVAL_SCRIPT -.->|metrics| UTILS

    %% Styles
    classDef data fill:#bbf,stroke:#333,stroke-width:1px
    classDef model fill:#bfb,stroke:#333,stroke-width:1px
    classDef engine fill:#fb8,stroke:#333,stroke-width:1px
    classDef config fill:#cff,stroke:#333,stroke-width:1px
    classDef external fill:#f9f,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef ext fill:#f88,stroke:#900,stroke-width:1px
    classDef eval fill:#fdb,stroke:#333,stroke-width:1px
```
