How wengzejia1/open-vclip works
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: models Models · run_net.py Run net · datasets Datasets · configs Configs
Components 26
Config & splits
YAML experiment configs and label/split assets that define datasets, methods, and zero-shot partitions.
- Configs · Dataset- and method-specific experiment definitions.
configs - Label DB · Supervised class-index mappings and dataset split CSVs.
label_db - ZS Label DB · Open-set and partial-split label partitions for zero-shot evaluation.
zs_label_db - Label distance · Label similarity metadata and helper scripts for class relationship analysis.
dataset_distance
Data pipeline
Video decoding, augmentation, dataset definitions, and loader construction.
- Datasets · 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 · Core model zoo, CLIP integration, heads, and alternate training regimes.
slowfast/models - CLIP core · Embedded CLIP code, tokenizer, and model assets used by Open-VCLIP.
slowfast/models/clip - CLIP video · Video-facing CLIP variants that inject temporal modeling into the backbone.
slowfast/models/clip_video_model.py - Temporal CLIP · Temporal modeling variants and adapter-style CLIP extensions.
slowfast/models/temporalclip_video_model.py - Custom ViT · Custom vision transformer and reversible MViT components for adapted video modeling.
slowfast/models/customize_visiontransformer.py - Legacy video · Classic PySlowFast and related video backbone builders.
slowfast/models/video_model_builder.py - SSL heads · Contrastive and masked pretraining/fine-tuning support.
slowfast/models/contrastive.py - Shared heads · 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 · Main config-driven dispatcher for train, validation, and test flows.
tools/run_net.py - Train net · Training wrapper around the shared model and data stack.
tools/train_net.py - Test net · Evaluation wrapper for checkpointed inference and reporting.
tools/test_net.py - Demo net · Interactive/demo inference entry point.
tools/demo_net.py - Benchmark · Performance benchmark entry point.
tools/benchmark.py - Submitit run · Cluster-friendly launch path for distributed jobs.
run_with_submitit.py - Train scripts · Reproducible launch scripts for temporal CLIP training variants.
script/training - Test scripts · Reproducible launch scripts for temporal and raw evaluation variants.
script/testing
Infra & tools
Distributed execution, checkpoints, averaging, visualization, and evaluation helpers.
- Distributed · Distributed execution, multiprocessing, and environment helpers.
slowfast/utils/distributed.py - Checkpoints · Checkpoint save/load and weight handling utilities.
slowfast/utils/checkpoint.py - Weight avg · Checkpoint averaging and interpolation support used by training/evaluation scripts.
weight_average_tool.py - Visualization · Demo, prediction visualization, Grad-CAM, and TensorBoard tooling.
slowfast/visualization - AVA eval · AVA-specific evaluation and metric computation helpers.
slowfast/utils/ava_evaluation
Connections 30
- 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.