# wengzejia1/open-vclip architecture

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

- Interactive diagram: https://gitdiagram.com/wengzejia1/open-vclip
- Repository: https://github.com/wengzejia1/open-vclip

## Overview

1. **What this repo is**
   - Open-VCLIP is a config-driven video recognition codebase that adapts CLIP into a video classifier, especially for zero-shot/open-vocabulary evaluation.
   - The core runtime is PyTorch on top of PySlowFast, with CLIP as the base vision-language backbone.

2. **Primary execution path**
   - Most experiments go through `tools/run_net.py`, which dispatches to training, validation, or testing based on config.
   - `tools/train_net.py`, `tools/test_net.py`, `tools/demo_net.py`, and `tools/benchmark.py` are thin task wrappers around the same model/data stack.
   - `run_with_submitit.py` and the shell scripts under `script/training` / `script/testing` provide cluster-friendly job submission and reproducible experiment launchers.

3. **Configuration layer**
   - The architecture is organized around YAML configs in `configs/`, grouped by dataset and method family: Kinetics, UCF/HMDB, SSv2, AVA, ImageNet, contrastive SSL, and masked SSL.
   - These configs control dataset roots, decoding backend, model type, temporal modeling mode, optimization, and evaluation-time patching/interpolation behavior.
   - This makes the system highly modular: the same training pipeline can instantiate very different video models and evaluation protocols.

4. **Data assets and label boundaries**
   - `label_db/` and `zs_label_db/` are not code, but they are central architecture inputs: they hold class-index mappings, CSV split files, and zero-shot/open-set label partitions.
   - `label_db/` contains standard supervised splits such as Kinetics-400/600, UCF101, and ImageNet label mappings.
   - `zs_label_db/` contains zero-shot and partial-split variants for HMDB, UCF101, Kinetics-600, and Something-Something V2, enabling open-vocabulary evaluation and split-based experiments.
   - `dataset_distance/` contains label similarity analysis utilities and CSV/JSON label metadata used to reason about class relationships.

5. **Data ingestion pipeline**
   - The `slowfast/datasets/` package is the input boundary from video files to model-ready tensors.
   - Key responsibilities here are video decoding (`decoder.py`, `video_container.py`), dataset definitions (`kinetics.py`, `ucf101`, `hmdb`, `ssv2`, `ava_dataset.py`, `imagenet.py`), augmentation/transforms (`transform.py`, `rand_augment.py`, `random_erasing.py`, `mixup.py`), and loader construction (`build.py`, `loader.py`).
   - The pipeline is designed for video clips and supports PyAV-based decoding, multigrid training, and dataset-specific label handling.

6. **Model stack**
   - `slowfast/models/` contains the model zoo and is the main compute boundary.
   - The legacy video backbones live in `video_model_builder.py`, `custom_video_model_builder.py`, `resnet_helper.py`, `stem_helper.py`, `nonlocal_helper.py`, and `mvit`-style components.
   - Open-VCLIP-specific logic is in `clip/`, `clip_video_model.py`, `temporalclip_video_model.py`, `customize_visiontransformer.py`, and `reversible_mvit.py`.
   - `contrastive.py` and `masked.py` support alternate training regimes shown in the config families for SSL and masked pretraining/fine-tuning.
   - `head_helper.py`, `losses.py`, `optimizer.py`, and `batchnorm_helper.py` provide shared heads, losses, optimizer behavior, and normalization utilities across model variants.

7. **How CLIP is integrated**
   - The CLIP subpackage embeds the OpenAI CLIP code and tokenizer, including model weights/tokenization assets under `slowfast/models/clip/`.
   - Open-VCLIP extends the image-language backbone into video via temporal modeling modules, rather than replacing the whole CLIP stack.
   - The README’s `MODEL.TEMPORAL_MODELING_TYPE` setting is a key architectural switch: it selects the mechanism used to inject time into the CLIP backbone.

8. **Training and evaluation flow**
   - Training starts from a config, builds the dataset loader, instantiates a model, and runs the standard PySlowFast optimization loop with checkpointing and metric logging.
   - Evaluation follows the same path but loads a checkpoint, applies zero-shot or finetuned inference, and writes results to the output directory.
   - The repo’s scripts show that evaluation often uses multiple ensemble views and spatial crops, so inference is a multi-pass aggregation step rather than a single forward pass.

9. **Open-vocabulary / interpolation-specific behavior**
   - A defining Open-VCLIP mechanism is weight interpolation during training or evaluation, controlled by options such as `TRAIN.LINEAR_CONNECT_*` and `TEST.PATCHING_*`.
   - This means the model can blend pretrained CLIP weights with adapted video weights, making “patching ratio” an explicit inference-time control.
   - `weight_average_tool.py` and the checkpoint scripts support this post-training averaging / SWA-style step.

10. **Distributed and large-scale infrastructure**
   - The codebase assumes multi-GPU execution and includes distributed helpers in `slowfast/utils/distributed.py`, multiprocessing helpers, checkpoint utilities, and environment setup.
   - `run_with_submitit.py` plus the `script/training/submitit_*` folder indicate Slurm/Submitit support for cluster submission.
   - Mixed precision is supported in the training scripts, which matters for throughput on larger video models.

11. **Evaluation targets and datasets**
   - The repo is structured around action recognition and video classification benchmarks: Kinetics-400/600, UCF-101, HMDB-51, Something-Something V2, Charades, and AVA.
   - Some configs under `configs/ImageNet/` and `label_db/imagenet-simple-labels/` indicate image-only or image-adjacent experiments as auxiliary experiments, not the main path.
   - AVA evaluation has a dedicated utility stack in `slowfast/utils/ava_evaluation/`, showing support for detection-style video action evaluation in addition to classification.

12. **Auxiliary tooling**
   - `slowfast/visualization/` contains demo, prediction visualization, TensorBoard hooks, and Grad-CAM-style tooling for inspecting outputs.
   - `tools/demo_net.py` and visualization helpers form a separate inference/inspection boundary from training and benchmark scripts.
   - `blip_llama2_caption/` contains pre-generated captions used for the Open-VCLIP++ direction; it is an artifact directory rather than a runtime subsystem.

13. **Repository boundary summary for a diagram**
   - The main flow is: config and label DB → dataset loaders/decoders → CLIP-augmented video model → training/evaluation loop → checkpoints/results.
   - Around that core are supporting systems for distributed execution, checkpoint averaging, visualization, and dataset/label processing.
   - The repo’s architecture is best drawn as a PySlowFast-based training platform with Open-VCLIP-specific model extensions and a substantial data/label preparation layer.

Main entry points: [`slowfast/models`](https://github.com/wengzejia1/open-vclip/tree/main/slowfast/models) (Models), [`tools/run_net.py`](https://github.com/wengzejia1/open-vclip/blob/main/tools/run_net.py) (Run net), [`slowfast/datasets`](https://github.com/wengzejia1/open-vclip/tree/main/slowfast/datasets) (Datasets), [`configs`](https://github.com/wengzejia1/open-vclip/tree/main/configs) (Configs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_config["Config & splits"]
  node_configs["Configs<br/>yaml config set"]
  node_label_db[("Label DB<br/>label assets")]
  node_zs_label_db[("ZS Label DB<br/>zero-shot splits")]
  node_dataset_distance["Label distance<br/>analysis assets"]
end

subgraph group_data["Data pipeline"]
  node_datasets["Datasets<br/>input pipeline"]
end

subgraph group_model["Model stack"]
  node_models["Models<br/>compute stack"]
  node_clip_pkg["CLIP core<br/>vision-language backbone"]
  node_clip_video["CLIP video<br/>temporal adaptation"]
  node_temporalclip["Temporal CLIP<br/>temporal adaptation"]
  node_custom_vit["Custom ViT<br/>transformer variants"]
  node_legacy_video["Legacy video<br/>video backbones"]
  node_ssl_heads["SSL heads<br/>auxiliary regimes<br/>[contrastive.py]"]
  node_common_heads["Shared heads<br/>shared modules<br/>[head_helper.py]"]
end

subgraph group_runtime["Execution"]
  node_run_net["Run net<br/>entrypoint<br/>[run_net.py]"]
  node_train_net["Train net<br/>entrypoint<br/>[train_net.py]"]
  node_test_net["Test net<br/>entrypoint<br/>[test_net.py]"]
  node_demo_net["Demo net<br/>entrypoint<br/>[demo_net.py]"]
  node_benchmark_tool["Benchmark<br/>entrypoint<br/>[benchmark.py]"]
  node_submitit_run["Submitit run<br/>launcher"]
  node_training_scripts["Train scripts<br/>shell launchers"]
  node_testing_scripts["Test scripts<br/>shell launchers"]
end

subgraph group_infra["Infra & tools"]
  node_distributed_utils["Distributed<br/>runtime utils<br/>[distributed.py]"]
  node_checkpointing["Checkpoints<br/>runtime utils<br/>[checkpoint.py]"]
  node_weight_average["Weight avg<br/>postprocess tool"]
  node_visualization["Visualization<br/>inspection tools"]
  node_ava_eval["AVA eval<br/>evaluation utils"]
end

node_run_net -->|"reads config"| node_configs
node_run_net -->|"builds input"| node_datasets
node_run_net -->|"builds model"| node_models
node_run_net -->|"loads/saves"| node_checkpointing
node_train_net -->|"wraps"| node_run_net
node_test_net -->|"wraps"| node_run_net
node_demo_net -->|"uses"| node_visualization
node_benchmark_tool -->|"measures"| node_datasets
node_submitit_run -->|"orchestrates"| node_distributed_utils
node_training_scripts -->|"launches"| node_submitit_run
node_testing_scripts -->|"launches"| node_test_net
node_configs -->|"binds labels"| node_label_db
node_configs -->|"binds ZS splits"| node_zs_label_db
node_configs -->|"selects datasets"| node_datasets
node_configs -->|"selects models"| node_models
node_datasets -->|"reads splits"| node_label_db
node_datasets -->|"reads open-set"| node_zs_label_db
node_datasets -->|"uses metadata"| node_dataset_distance
node_models -->|"embeds CLIP"| node_clip_pkg
node_models -->|"extends"| node_clip_video
node_models -->|"extends"| node_temporalclip
node_models -->|"uses"| node_custom_vit
node_models -->|"includes"| node_legacy_video
node_models -->|"supports"| node_ssl_heads
node_models -->|"shares modules"| node_common_heads
node_weight_average -->|"updates"| node_checkpointing
node_visualization -->|"loads models"| node_checkpointing
node_ava_eval -->|"supports eval"| node_test_net
node_train_net -->|"writes"| node_checkpointing
node_test_net -->|"reads"| node_checkpointing

click node_run_net "https://github.com/wengzejia1/open-vclip/blob/main/tools/run_net.py"
click node_train_net "https://github.com/wengzejia1/open-vclip/blob/main/tools/train_net.py"
click node_test_net "https://github.com/wengzejia1/open-vclip/blob/main/tools/test_net.py"
click node_demo_net "https://github.com/wengzejia1/open-vclip/blob/main/tools/demo_net.py"
click node_benchmark_tool "https://github.com/wengzejia1/open-vclip/blob/main/tools/benchmark.py"
click node_submitit_run "https://github.com/wengzejia1/open-vclip/blob/main/run_with_submitit.py"
click node_training_scripts "https://github.com/wengzejia1/open-vclip/tree/main/script/training"
click node_testing_scripts "https://github.com/wengzejia1/open-vclip/tree/main/script/testing"
click node_configs "https://github.com/wengzejia1/open-vclip/tree/main/configs"
click node_label_db "https://github.com/wengzejia1/open-vclip/tree/main/label_db"
click node_zs_label_db "https://github.com/wengzejia1/open-vclip/tree/main/zs_label_db"
click node_dataset_distance "https://github.com/wengzejia1/open-vclip/tree/main/dataset_distance"
click node_datasets "https://github.com/wengzejia1/open-vclip/tree/main/slowfast/datasets"
click node_models "https://github.com/wengzejia1/open-vclip/tree/main/slowfast/models"
click node_clip_pkg "https://github.com/wengzejia1/open-vclip/tree/main/slowfast/models/clip"
click node_clip_video "https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/clip_video_model.py"
click node_temporalclip "https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/temporalclip_video_model.py"
click node_custom_vit "https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/customize_visiontransformer.py"
click node_legacy_video "https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/video_model_builder.py"
click node_ssl_heads "https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/contrastive.py"
click node_common_heads "https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/head_helper.py"
click node_distributed_utils "https://github.com/wengzejia1/open-vclip/blob/main/slowfast/utils/distributed.py"
click node_checkpointing "https://github.com/wengzejia1/open-vclip/blob/main/slowfast/utils/checkpoint.py"
click node_weight_average "https://github.com/wengzejia1/open-vclip/blob/main/weight_average_tool.py"
click node_visualization "https://github.com/wengzejia1/open-vclip/tree/main/slowfast/visualization"
click node_ava_eval "https://github.com/wengzejia1/open-vclip/tree/main/slowfast/utils/ava_evaluation"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_configs,node_label_db,node_zs_label_db,node_dataset_distance toneBlue
class node_datasets toneAmber
class node_models,node_clip_pkg,node_clip_video,node_temporalclip,node_custom_vit,node_legacy_video,node_ssl_heads,node_common_heads toneMint
class node_run_net,node_train_net,node_test_net,node_demo_net,node_benchmark_tool,node_submitit_run,node_training_scripts,node_testing_scripts toneRose
class node_distributed_utils,node_checkpointing,node_weight_average,node_visualization,node_ava_eval toneIndigo
```

## Components

### Config & splits

YAML experiment configs and label/split assets that define datasets, methods, and zero-shot partitions.

- [Configs](https://github.com/wengzejia1/open-vclip/tree/main/configs): yaml config set · Dataset- and method-specific experiment definitions. · `configs`
- [Label DB](https://github.com/wengzejia1/open-vclip/tree/main/label_db): label assets · Supervised class-index mappings and dataset split CSVs. · `label_db`
- [ZS Label DB](https://github.com/wengzejia1/open-vclip/tree/main/zs_label_db): zero-shot splits · Open-set and partial-split label partitions for zero-shot evaluation. · `zs_label_db`
- [Label distance](https://github.com/wengzejia1/open-vclip/tree/main/dataset_distance): analysis assets · Label similarity metadata and helper scripts for class relationship analysis. · `dataset_distance`

### Data pipeline

Video decoding, augmentation, dataset definitions, and loader construction.

- [Datasets](https://github.com/wengzejia1/open-vclip/tree/main/slowfast/datasets): input pipeline · Video decoding, augmentations, dataset definitions, and loader building. · `slowfast/datasets`

### Model stack

PySlowFast model zoo plus Open-VCLIP CLIP-augmented video models and training heads.

- [Models](https://github.com/wengzejia1/open-vclip/tree/main/slowfast/models): compute stack · Core model zoo, CLIP integration, heads, and alternate training regimes. · `slowfast/models`
- [CLIP core](https://github.com/wengzejia1/open-vclip/tree/main/slowfast/models/clip): vision-language backbone · Embedded CLIP code, tokenizer, and model assets used by Open-VCLIP. · `slowfast/models/clip`
- [CLIP video](https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/clip_video_model.py): temporal adaptation · Video-facing CLIP variants that inject temporal modeling into the backbone. · `slowfast/models/clip_video_model.py`
- [Temporal CLIP](https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/temporalclip_video_model.py): temporal adaptation · Temporal modeling variants and adapter-style CLIP extensions. · `slowfast/models/temporalclip_video_model.py`
- [Custom ViT](https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/customize_visiontransformer.py): transformer variants · Custom vision transformer and reversible MViT components for adapted video modeling. · `slowfast/models/customize_visiontransformer.py`
- [Legacy video](https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/video_model_builder.py): video backbones · Classic PySlowFast and related video backbone builders. · `slowfast/models/video_model_builder.py`
- [SSL heads](https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/contrastive.py): auxiliary regimes · Contrastive and masked pretraining/fine-tuning support. · `slowfast/models/contrastive.py`
- [Shared heads](https://github.com/wengzejia1/open-vclip/blob/main/slowfast/models/head_helper.py): shared modules · Heads, losses, optimizer, and normalization helpers shared across model variants. · `slowfast/models/head_helper.py`

### Execution

Train/test/demo entry points and launch scripts.

- [Run net](https://github.com/wengzejia1/open-vclip/blob/main/tools/run_net.py): entrypoint · Main config-driven dispatcher for train, validation, and test flows. · `tools/run_net.py`
- [Train net](https://github.com/wengzejia1/open-vclip/blob/main/tools/train_net.py): entrypoint · Training wrapper around the shared model and data stack. · `tools/train_net.py`
- [Test net](https://github.com/wengzejia1/open-vclip/blob/main/tools/test_net.py): entrypoint · Evaluation wrapper for checkpointed inference and reporting. · `tools/test_net.py`
- [Demo net](https://github.com/wengzejia1/open-vclip/blob/main/tools/demo_net.py): entrypoint · Interactive/demo inference entry point. · `tools/demo_net.py`
- [Benchmark](https://github.com/wengzejia1/open-vclip/blob/main/tools/benchmark.py): entrypoint · Performance benchmark entry point. · `tools/benchmark.py`
- [Submitit run](https://github.com/wengzejia1/open-vclip/blob/main/run_with_submitit.py): launcher · Cluster-friendly launch path for distributed jobs. · `run_with_submitit.py`
- [Train scripts](https://github.com/wengzejia1/open-vclip/tree/main/script/training): shell launchers · Reproducible launch scripts for temporal CLIP training variants. · `script/training`
- [Test scripts](https://github.com/wengzejia1/open-vclip/tree/main/script/testing): shell launchers · Reproducible launch scripts for temporal and raw evaluation variants. · `script/testing`

### Infra & tools

Distributed execution, checkpoints, averaging, visualization, and evaluation helpers.

- [Distributed](https://github.com/wengzejia1/open-vclip/blob/main/slowfast/utils/distributed.py): runtime utils · Distributed execution, multiprocessing, and environment helpers. · `slowfast/utils/distributed.py`
- [Checkpoints](https://github.com/wengzejia1/open-vclip/blob/main/slowfast/utils/checkpoint.py): runtime utils · Checkpoint save/load and weight handling utilities. · `slowfast/utils/checkpoint.py`
- [Weight avg](https://github.com/wengzejia1/open-vclip/blob/main/weight_average_tool.py): postprocess tool · Checkpoint averaging and interpolation support used by training/evaluation scripts. · `weight_average_tool.py`
- [Visualization](https://github.com/wengzejia1/open-vclip/tree/main/slowfast/visualization): inspection tools · Demo, prediction visualization, Grad-CAM, and TensorBoard tooling. · `slowfast/visualization`
- [AVA eval](https://github.com/wengzejia1/open-vclip/tree/main/slowfast/utils/ava_evaluation): evaluation utils · AVA-specific evaluation and metric computation helpers. · `slowfast/utils/ava_evaluation`

## Connections

- Run net → Configs: reads config · Experiment entry point loads YAML-driven setup.
- Run net → Datasets: builds input · Dispatches to the data pipeline for train/val/test.
- Run net → Models: builds model · Instantiates the configured video model.
- Run net → Checkpoints: loads/saves · Uses checkpoints during train and eval runs.
- Train net → Run net: wraps · Thin task wrapper around the shared execution path.
- Test net → Run net: wraps · Thin task wrapper around the shared execution path.
- Demo net → Visualization: uses · Demo and inspection flow depends on visualization helpers.
- Benchmark → Datasets: measures · Benchmarks the input pipeline and model execution.
- Submitit run → Distributed: orchestrates · Cluster launcher sets up distributed jobs.
- Train scripts → Submitit run: launches · Shell scripts provide reproducible training entry points.
- Test scripts → Test net: launches · Shell scripts provide reproducible evaluation entry points.
- Configs → Label DB: binds labels · Configs reference supervised class mappings and splits.
- Configs → ZS Label DB: binds ZS splits · Configs reference open-set and partial-split labels.
- Configs → Datasets: selects datasets · Config families choose dataset roots, decoding, and augmentation.
- Configs → Models: selects models · Config families choose backbone and temporal modeling variant.
- Datasets → Label DB: reads splits · Dataset loaders consume class mappings and CSV annotations.
- Datasets → ZS Label DB: reads open-set · Zero-shot loaders use partial/open-set label partitions.
- Datasets → Label distance: uses metadata · Label-analysis assets support dataset relationship reasoning.
- Models → CLIP core: embeds CLIP · Open-VCLIP builds on the embedded CLIP backbone and tokenizer.
- Models → CLIP video: extends · Video CLIP variants adapt the backbone for temporal input.
- Models → Temporal CLIP: extends · Temporal adapter-style CLIP models live here.
- Models → Custom ViT: uses · Transformer-based variants and reversible MViT components are part of the compute stack.
- Models → Legacy video: includes · Retains classic PySlowFast-style video backbones.
- Models → SSL heads: supports · Contrastive and masked SSL regimes share the same model stack.
- Models → Shared heads: shares modules · Common heads, losses, optimizer, and normalization utilities are reused.
- Weight avg → Checkpoints: updates · Averaged weights feed back into checkpoint-based evaluation.
- Visualization → Checkpoints: loads models · Visualization tools inspect trained checkpoints.
- AVA eval → Test net: supports eval · AVA evaluation integrates with the testing flow.
- Train net → Checkpoints: writes · Training persists intermediate and final checkpoints.
- Test net → Checkpoints: reads · Evaluation loads trained weights before inference.
