How 1adrianb/video-transformers works
Project Type and Purpose
• XViT is a deep‐learning library and tooling suite for video recognition built on PyTorch, extending the SlowFast codebase.
• Its purpose is to implement the XViT Video Transformer architecture, train and evaluate on large video datasets (Kinetics, Something‐Something v2), and provide pre‐trained model checkpoints.
Key Architectural Layers and Directories
• configs/ : YAML configuration files per dataset/model variant. Acts as the central configuration registry.
• slowfast/ : Core library module, subdivided into:
• config/ – configuration defaults and merge utilities
• datasets/ – data ingestion pipeline (decoding, augmentation, loader)
• models/ – model builder, transformer blocks, heads, losses, optimizers
• utils/ – distributed training, checkpointing, logging, metrics, environment management
• visualization/ – Grad‐CAM, tensorboard hooks, video visualizer
• tools/ : CLI entry‐points for training (train_net.py), evaluation (test_net.py), benchmarking (benchmark.py), and general run_nets.
• External dependencies: PyTorch, torchvision, fvcore, PyAV/ffmpeg, detectron2, tensorboard, h5py for video frame storage.
Data Flow and Component Interactions
1. Configuration Loader (tools/run_net.py → slowfast/config)
2. Dataset Preparation
• Video files or packed h5 files
• slowfast/datasets/decoder → cv2/image_decoder → transform → loader
3. Model Building
• slowfast/models/build → video_model_builder → transformer & head modules
4. Training/Evaluation Loop (tools/train_net.py / test_net.py)
• Forward pass → loss computation (slowfast/models/losses) → backward pass → optimizer update (slowfast/models/optimizer)
• Metrics and logging (slowfast/utils/meters, logging, tensorboard_vis)
• Checkpointing (slowfast/utils/checkpoint)
5. Visualization & Debugging
• GradCAM, video_visualizer for qualitative analysis (slowfast/visualization)
Architectural Patterns and Design Principles
• Config-driven design: All hyperparameters and file paths are defined in YAML, merged at runtime.
• Modular layering: Clear separation of data pipeline, model definition, training logic, and utilities.
• Plugin architecture: Easy to extend new datasets, models, or transforms by adding modules under the respective package.
• Distributed training support: Utilities abstract CUDA process groups and spawning.
Essential Details
• Every top‐level module: configs, datasets, models, utils, visualization, tools.
• How tools orchestrate the library: a “Tooling Layer” that invokes the core library.
• Two XViT‐specific innovations: local temporal windowing and space‐time mixing attention in the model block.