### Define configuration YAML Source: https://context7.com/facebookresearch/slowfast/llms.txt Example configuration file structure for Kinetics dataset training. ```yaml # Example config: configs/Kinetics/SLOWFAST_8x8_R50.yaml TRAIN: ENABLE: True DATASET: kinetics BATCH_SIZE: 64 EVAL_PERIOD: 10 CHECKPOINT_PERIOD: 1 AUTO_RESUME: True DATA: NUM_FRAMES: 32 SAMPLING_RATE: 2 TRAIN_JITTER_SCALES: [256, 320] TRAIN_CROP_SIZE: 224 TEST_CROP_SIZE: 256 INPUT_CHANNEL_NUM: [3, 3] SLOWFAST: ALPHA: 4 # Frame rate ratio between Slow and Fast pathways BETA_INV: 8 # Channel reduction ratio FUSION_CONV_CHANNEL_RATIO: 2 FUSION_KERNEL_SZ: 7 MODEL: NUM_CLASSES: 400 ARCH: slowfast MODEL_NAME: SlowFast LOSS_FUNC: cross_entropy DROPOUT_RATE: 0.5 SOLVER: BASE_LR: 0.1 LR_POLICY: cosine MAX_EPOCH: 196 WARMUP_EPOCHS: 34.0 WEIGHT_DECAY: 1e-4 OPTIMIZING_METHOD: sgd TEST: ENABLE: True NUM_ENSEMBLE_VIEWS: 10 NUM_SPATIAL_CROPS: 3 NUM_GPUS: 8 NUM_SHARDS: 1 OUTPUT_DIR: . ``` -------------------------------- ### Build and Develop SlowFast Source: https://github.com/facebookresearch/slowfast/blob/main/INSTALL.md Clones the SlowFast repository, navigates into its directory, and then builds and installs the package in develop mode. This step is necessary after cloning the repository and setting up dependencies. ```bash git clone https://github.com/facebookresearch/slowfast cd SlowFast python setup.py build develop ``` -------------------------------- ### Install Core Dependencies for Detectron2 Source: https://github.com/facebookresearch/slowfast/blob/main/INSTALL.md Installs essential packages like PyTorch, torchvision, cython, fvcore, and the COCO API. It also clones the Detectron2 repository and installs it in editable mode. ```bash pip install -U torch torchvision cython pip install -U 'git+https://github.com/facebookresearch/fvcore.git' 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' git clone https://github.com/facebookresearch/detectron2 detectron2_repo pip install -e detectron2_repo ``` -------------------------------- ### Run a Basic Command Source: https://github.com/facebookresearch/slowfast/blob/main/GETTING_STARTED.md A simplified command to run a PySlowFast job, typically used for basic execution or initial setup. ```bash python \tools\run_net.py --cfg path/to/.yaml ``` -------------------------------- ### Train Video Models via CLI Source: https://context7.com/facebookresearch/slowfast/llms.txt Use the run_net.py script to initiate training for various architectures with specific configuration files and hardware settings. ```bash # Train a SlowFast model on Kinetics-400 python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50.yaml \ DATA.PATH_TO_DATA_DIR /path/to/kinetics400 \ NUM_GPUS 8 \ TRAIN.BATCH_SIZE 64 \ SOLVER.BASE_LR 0.1 \ SOLVER.MAX_EPOCH 196 \ OUTPUT_DIR /path/to/output # Train with mixed precision for faster training python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50.yaml \ DATA.PATH_TO_DATA_DIR /path/to/kinetics400 \ TRAIN.MIXED_PRECISION True \ NUM_GPUS 4 \ TRAIN.BATCH_SIZE 32 # Train MViT (Multiscale Vision Transformer) model python tools/run_net.py \ --cfg configs/Kinetics/MVITv2_S_16x4.yaml \ DATA.PATH_TO_DATA_DIR /path/to/kinetics400 \ NUM_GPUS 8 \ TRAIN.BATCH_SIZE 64 # Train X3D efficient model python tools/run_net.py \ --cfg configs/Kinetics/X3D_M.yaml \ DATA.PATH_TO_DATA_DIR /path/to/kinetics400 \ NUM_GPUS 8 \ TRAIN.BATCH_SIZE 32 ``` -------------------------------- ### Enable TensorBoard Visualization Source: https://context7.com/facebookresearch/slowfast/llms.txt Configure logging for training metrics or run standalone visualization tools for model analysis. ```bash # Enable TensorBoard logging during training python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50.yaml \ TENSORBOARD.ENABLE True \ TENSORBOARD.LOG_DIR /path/to/tensorboard_logs \ TENSORBOARD.MODEL_VIS.ENABLE True \ TENSORBOARD.MODEL_VIS.GRAD_CAM.ENABLE True \ TENSORBOARD.MODEL_VIS.GRAD_CAM.LAYER_LIST ["s5", "s5"] # Run visualization tool separately python tools/visualization.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50.yaml \ TEST.CHECKPOINT_FILE_PATH /path/to/checkpoint.pyth \ TENSORBOARD.ENABLE True \ TENSORBOARD.MODEL_VIS.ENABLE True \ TENSORBOARD.WRONG_PRED_VIS.ENABLE True ``` -------------------------------- ### Configure Demo for Video Inference Source: https://github.com/facebookresearch/slowfast/blob/main/VISUALIZATION_TOOLS.md Add this configuration to your YAML file to enable the demo mode for running inference on videos or webcam input. Specify input and output paths, and optionally enable multi-threading for video processing. ```yaml DEMO: ENABLE: True LABEL_FILE_PATH: # Path to json file providing class_name - id mapping. INPUT_VIDEO: # Path to input video file. OUTPUT_FILE: # Path to output video file to write results to. # Leave an empty string if you would like to display results to a window. THREAD_ENABLE: # Run video reader/writer in the background with multi-threading. NUM_VIS_INSTANCES: # Number of CPU(s)/processes use to run video visualizer. NUM_CLIPS_SKIP: # Number of clips to skip prediction/visualization # (mostly to smoothen/improve display quality with wecam input). ``` -------------------------------- ### Train MViTv2 Model from Scratch Source: https://github.com/facebookresearch/slowfast/blob/main/projects/mvitv2/README.md Use this command to train a standard MViTv2 model from scratch. Ensure you replace 'path_to_your_dataset' with the actual path to your dataset. ```bash python tools/run_net.py \ --cfg configs/Kinetics/MVITv2_S_16x4.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ ``` -------------------------------- ### Train a Standard Model from Scratch Source: https://github.com/facebookresearch/slowfast/blob/main/GETTING_STARTED.md Use this command to train a simple C2D model. Specify the dataset path and number of GPUs. You can also configure these in the YAML file. ```bash python tools/run_net.py \ --cfg configs/Kinetics/C2D_8x8_R50.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ NUM_GPUS 2 \ TRAIN.BATCH_SIZE 16 \ ``` ```yaml DATA: PATH_TO_DATA_DIR: path_to_your_dataset ``` ```yaml DATA_LOADER.NUM_WORKERS 0 \ NUM_GPUS 2 \ TRAIN.BATCH_SIZE 16 \ ``` -------------------------------- ### Run demo inference Source: https://context7.com/facebookresearch/slowfast/llms.txt Execute inference on video files, webcam streams, or AVA action detection tasks. ```bash # Run demo on a video file python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50.yaml \ TEST.CHECKPOINT_FILE_PATH /path/to/checkpoint.pyth \ DEMO.ENABLE True \ DEMO.INPUT_VIDEO /path/to/video.mp4 \ DEMO.LABEL_FILE_PATH /path/to/kinetics_labels.json \ DEMO.OUTPUT_FILE /path/to/output.mp4 \ NUM_GPUS 1 # Run demo from webcam python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50.yaml \ TEST.CHECKPOINT_FILE_PATH /path/to/checkpoint.pyth \ DEMO.ENABLE True \ DEMO.WEBCAM 0 \ DEMO.LABEL_FILE_PATH /path/to/labels.json \ NUM_GPUS 1 # AVA action detection demo with precomputed boxes python tools/run_net.py \ --cfg configs/AVA/SLOWFAST_32x2_R50_SHORT.yaml \ TEST.CHECKPOINT_FILE_PATH /path/to/ava_checkpoint.pyth \ DEMO.ENABLE True \ DEMO.INPUT_VIDEO /path/to/video.mp4 \ DEMO.PREDS_BOXES /path/to/precomputed_boxes.csv \ DETECTION.ENABLE True ``` -------------------------------- ### Enable Multigrid Training via CLI Source: https://github.com/facebookresearch/slowfast/blob/main/projects/multigrid/README.md Use these flags when running the training script to activate long and short cycles. Ensure the dataset path is correctly specified. ```bash python tools/run_net.py \ --cfg configs/Charades/SLOWFAST_16x8_R50.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ MULTIGRID.LONG_CYCLE True \ MULTIGRID.SHORT_CYCLE True \ ``` -------------------------------- ### Run MaskFeat Training and Fine-tuning Source: https://github.com/facebookresearch/slowfast/blob/main/projects/maskfeat/README.md Commands to execute pre-training and fine-tuning for MViT on Kinetics-400 and ViT on ImageNet using the run_net.py script. ```bash python tools/run_net.py \ --cfg configs/masked_ssl/k400_MVITv2_L_16x4_MaskFeat_PT.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_Kinetics_dataset ``` ```bash python tools/run_net.py \ --cfg configs/masked_ssl/k400_MVITv2_L_16x4_FT.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_Kinetics_dataset \ TRAIN.CHECKPOINT_FILE_PATH path_to_your_pretrain_checkpoint ``` ```bash python tools/run_net.py \ --cfg configs/masked_ssl/in1k_VIT_B_MaskFeat_PT.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_ImageNet_dataset ``` ```bash python tools/run_net.py \ --cfg configs/masked_ssl/in1k_VIT_B_FT.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_ImageNet_dataset \ TRAIN.CHECKPOINT_FILE_PATH path_to_your_pretrain_checkpoint ``` -------------------------------- ### Test and Evaluate Video Models Source: https://context7.com/facebookresearch/slowfast/llms.txt Perform multi-view testing on pretrained models using the run_net.py script with specific checkpoint paths and evaluation parameters. ```bash # Test a trained SlowFast model python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50.yaml \ DATA.PATH_TO_DATA_DIR /path/to/kinetics400 \ TEST.CHECKPOINT_FILE_PATH /path/to/checkpoint.pyth \ TRAIN.ENABLE False \ TEST.ENABLE True \ NUM_GPUS 8 # Multi-view testing with 10 temporal clips and 3 spatial crops python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50.yaml \ TEST.CHECKPOINT_FILE_PATH /path/to/model.pyth \ TEST.NUM_ENSEMBLE_VIEWS 10 \ TEST.NUM_SPATIAL_CROPS 3 \ TRAIN.ENABLE False # Test MViT model on Kinetics python tools/run_net.py \ --cfg configs/Kinetics/MVITv2_B_32x3.yaml \ TEST.CHECKPOINT_FILE_PATH /path/to/mvitv2_model.pyth \ TRAIN.ENABLE False \ TEST.ENABLE True \ NUM_GPUS 4 ``` -------------------------------- ### Configure programmatically Source: https://context7.com/facebookresearch/slowfast/llms.txt Load, override, and freeze configuration settings using the YACS-based system. ```python # Load and modify config programmatically from slowfast.config.defaults import get_cfg from slowfast.utils.parser import load_config, parse_args # Get default config cfg = get_cfg() # Load from YAML file cfg.merge_from_file("configs/Kinetics/SLOWFAST_8x8_R50.yaml") # Override with command line args cfg.merge_from_list(["NUM_GPUS", "4", "TRAIN.BATCH_SIZE", "32"]) # Freeze config cfg.freeze() ``` -------------------------------- ### Build Video Models Programmatically Source: https://context7.com/facebookresearch/slowfast/llms.txt Construct models using the build_model function and configuration objects. ```python from slowfast.models import build_model from slowfast.config.defaults import get_cfg # Build a SlowFast model cfg = get_cfg() cfg.MODEL.MODEL_NAME = "SlowFast" cfg.MODEL.ARCH = "slowfast" cfg.MODEL.NUM_CLASSES = 400 cfg.RESNET.DEPTH = 50 cfg.NUM_GPUS = 1 model = build_model(cfg) # Model is automatically moved to GPU and wrapped in DDP if NUM_GPUS > 1 # Build an MViT model cfg = get_cfg() cfg.MODEL.MODEL_NAME = "MViT" cfg.MVIT.DEPTH = 16 cfg.MVIT.EMBED_DIM = 96 cfg.MVIT.NUM_HEADS = 1 cfg.MODEL.NUM_CLASSES = 400 model = build_model(cfg) # Build X3D model cfg = get_cfg() cfg.MODEL.MODEL_NAME = "X3D" cfg.MODEL.ARCH = "x3d" cfg.X3D.WIDTH_FACTOR = 2.0 cfg.X3D.DEPTH_FACTOR = 2.2 model = build_model(cfg) ``` -------------------------------- ### Enable Tensorboard Support in Config Source: https://github.com/facebookresearch/slowfast/blob/main/VISUALIZATION_TOOLS.md Add this configuration to your YAML file to enable Tensorboard support for live monitoring of metrics and class-level performance during training, evaluation, and testing. ```yaml TENSORBOARD: ENABLE: True LOG_DIR: # Leave empty to use cfg.OUTPUT_DIR/runs-{cfg.TRAIN.DATASET} as path. CLASS_NAMES_PATH: # Path to json file providing class_name - id mapping. CONFUSION_MATRIX: ENABLE: True SUBSET_PATH: # Path to txt file contains class names separated by newline characters. # Only classes in this file will be visualized in the confusion matrix. HISTOGRAM: ENABLE: True TOP_K: 10 # Top-k most frequently predicted classes for each class in the dataset. SUBSET_PATH: # Path to txt file contains class names separated by newline characters. # Only classes in this file will be visualized with histograms. ``` -------------------------------- ### Configure Multigrid Training Source: https://context7.com/facebookresearch/slowfast/llms.txt Train models using multigrid schedules to accelerate convergence by varying mini-batch shapes. ```bash # Train with multigrid (short cycle only) python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50_stepwise_multigrid.yaml \ DATA.PATH_TO_DATA_DIR /path/to/kinetics400 \ MULTIGRID.SHORT_CYCLE True \ NUM_GPUS 8 # Train with multigrid long cycle python tools/run_net.py \ --cfg configs/Kinetics/SLOWFAST_8x8_R50_stepwise_multigrid.yaml \ MULTIGRID.LONG_CYCLE True \ MULTIGRID.SHORT_CYCLE True \ MULTIGRID.EPOCH_FACTOR 1.5 \ NUM_GPUS 8 ``` -------------------------------- ### Download AVA Annotations Source: https://github.com/facebookresearch/slowfast/blob/main/slowfast/datasets/DATASET.md Downloads official AVA annotation files, including training/validation CSVs and action lists, into the specified annotations directory. Creates the directory if it does not exist. ```bash DATA_DIR="../../data/ava/annotations" if [[ ! -d "${DATA_DIR}" ]]; then echo "${DATA_DIR} doesn't exist. Creating it."; mkdir -p ${DATA_DIR} fi wget https://research.google.com/ava/download/ava_train_v2.1.csv -P ${DATA_DIR} wget https://research.google.com/ava/download/ava_val_v2.1.csv -P ${DATA_DIR} wget https://research.google.com/ava/download/ava_action_list_v2.1_for_activitynet_2018.pbtxt -P ${DATA_DIR} wget https://research.google.com/ava/download/ava_train_excluded_timestamps_v2.1.csv -P ${DATA_DIR} wget https://research.google.com/ava/download/ava_val_excluded_timestamps_v2.1.csv -P ${DATA_DIR} ``` -------------------------------- ### Configure AVA Video Demo Source: https://github.com/facebookresearch/slowfast/blob/main/VISUALIZATION_TOOLS.md Defines the input paths and output settings for visualizing prediction results on AVA-format videos. ```yaml DEMO: ENABLE: True OUTPUT_FILE: yourPath/output.mp4 LABEL_FILE_PATH: yourPath/ava_classnames.json INPUT_VIDEO: yourPath/frames/HVAmkvLrthQ # Path to a video file or image folder PREDS_BOXES: yourPath/ava_detection_train_boxes_and_labels_include_negative.csv # Path to pre-computed bouding boxes in AVA format. GT_BOXES: yourPath/ava_train_v2.2.csv # Path to ground-truth boxes and labels in AVA format (optional). ``` -------------------------------- ### Train and test Rev-MViT video model Source: https://github.com/facebookresearch/slowfast/blob/main/projects/rev/README.md Command to execute training and testing for the Rev-MViT video model on Kinetics using the specified configuration. ```bash python tools/run_net.py \ --cfg configs/Kinetics/REV_MVIT_B_16x4_CONV.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ NUM_GPUS 1 \ ``` -------------------------------- ### Perform Testing with PySlowFast Source: https://github.com/facebookresearch/slowfast/blob/main/GETTING_STARTED.md Run this command for testing. Set TRAIN.ENABLE to False and provide the path to the model checkpoint for testing. ```bash python tools/run_net.py \ --cfg configs/Kinetics/C2D_8x8_R50.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ TEST.CHECKPOINT_FILE_PATH path_to_your_checkpoint \ TRAIN.ENABLE False \ ``` -------------------------------- ### Enable Model Analysis on Tensorboard Source: https://github.com/facebookresearch/slowfast/blob/main/VISUALIZATION_TOOLS.md Add this configuration to your YAML file to enable Tensorboard support for model analysis, including visualization of weights, activations, and Grad-CAM. ```yaml TENSORBOARD: ENABLE: True MODEL_VIS: ENABLE: True MODEL_WEIGHTS: # Set to True to visualize model weights. ACTIVATIONS: # Set to True to visualize feature maps. INPUT_VIDEO: # Set to True to visualize the input video(s) for the corresponding feature maps. LAYER_LIST: # List of layer names to visualize weights and activations for. GRAD_CAM: ENABLE: True LAYER_LIST: # List of CNN layers to use for Grad-CAM visualization method. # The number of layer must be equal to the number of pathway(s). ``` -------------------------------- ### Train AVA action detection Source: https://context7.com/facebookresearch/slowfast/llms.txt Command to initiate training for spatio-temporal action detection on the AVA dataset. ```bash # Train AVA action detection model python tools/run_net.py \ --cfg configs/AVA/SLOWFAST_32x2_R50_SHORT.yaml \ AVA.FRAME_DIR /path/to/ava_frames \ AVA.FRAME_LIST_DIR /path/to/frame_lists \ AVA.ANNOTATION_DIR /path/to/annotations \ TRAIN.CHECKPOINT_FILE_PATH /path/to/kinetics_pretrained.pyth \ NUM_GPUS 8 \ DETECTION.ENABLE True ``` -------------------------------- ### Download AVA Videos Source: https://github.com/facebookresearch/slowfast/blob/main/slowfast/datasets/DATASET.md Downloads the AVA dataset videos and organizes them into a specified directory. Ensures the directory exists before downloading. ```bash DATA_DIR="../../data/ava/videos" if [[ ! -d "${DATA_DIR}" ]]; then echo "${DATA_DIR} doesn't exist. Creating it."; mkdir -p ${DATA_DIR} fi wget https://s3.amazonaws.com/ava-dataset/annotations/ava_file_names_trainval_v2.1.txt for line in $(cat ava_file_names_trainval_v2.1.txt) do wget https://s3.amazonaws.com/ava-dataset/trainval/$line -P ${DATA_DIR} done ``` -------------------------------- ### Train and Test MViT-B Model Source: https://github.com/facebookresearch/slowfast/blob/main/projects/mvit/README.md Use this command to train and test an MViT-B model on your dataset. Ensure you have the correct configuration file and dataset path. ```bash python tools/run_net.py \ --cfg configs/Kinetics/MVIT-B.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ ``` -------------------------------- ### Run SlowFast Pipeline Source: https://github.com/facebookresearch/slowfast/blob/main/INSTALL.md Executes the SlowFast pipeline using a specified configuration file. This command requires the number of GPUs, batch size, learning rate, and the path to the data directory. ```bash python tools/run_net.py --cfg configs/Kinetics/C2D_8x8_R50.yaml NUM_GPUS 1 TRAIN.BATCH_SIZE 8 SOLVER.BASE_LR 0.0125 DATA.PATH_TO_DATA_DIR path_to_your_data_folder ``` -------------------------------- ### Train and Test X3D Model Source: https://github.com/facebookresearch/slowfast/blob/main/projects/x3d/README.md Use this command to train and test an extra small (XS) X3D model on your dataset. Ensure you have the correct configuration file and dataset path. ```bash python tools/run_net.py \ --cfg configs/Kinetics/X3D-XS.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ ``` -------------------------------- ### Perform Self-Supervised Learning Source: https://context7.com/facebookresearch/slowfast/llms.txt Execute contrastive pretraining or fine-tune models on downstream tasks using SSL workflows. ```bash # Pretrain with MoCo python tools/run_net.py \ --cfg configs/contrastive_ssl/MoCo_SlowR50_8x8.yaml \ DATA.PATH_TO_DATA_DIR /path/to/kinetics400 \ TASK ssl \ CONTRASTIVE.TYPE moco \ CONTRASTIVE.T 0.07 \ CONTRASTIVE.QUEUE_LEN 65536 \ NUM_GPUS 8 # Fine-tune on downstream task python tools/run_net.py \ --cfg configs/contrastive_ssl/finetune_SSv2_Slow_R50_syn8.yaml \ DATA.PATH_TO_DATA_DIR /path/to/ssv2 \ TRAIN.CHECKPOINT_FILE_PATH /path/to/ssl_pretrained.pyth \ TASK ssl_eval \ NUM_GPUS 8 ``` -------------------------------- ### Resume Training from a Checkpoint Source: https://github.com/facebookresearch/slowfast/blob/main/GETTING_STARTED.md Specify the path to your PyTorch or Caffe2 checkpoint to resume training. For Caffe2 checkpoints, also set the checkpoint type. ```bash TRAIN.CHECKPOINT_FILE_PATH path_to_your_PyTorch_checkpoint ``` ```bash TRAIN.CHECKPOINT_FILE_PATH path_to_your_Caffe2_checkpoint \ TRAIN.CHECKPOINT_TYPE caffe2 ``` -------------------------------- ### Cut AVA Videos to 15-Minute Segments Source: https://github.com/facebookresearch/slowfast/blob/main/slowfast/datasets/DATASET.md Processes downloaded AVA videos, cutting each to a 15-minute duration (900 seconds) and saving to an output directory. Skips processing if the output file already exists. ```bash IN_DATA_DIR="../../data/ava/videos" OUT_DATA_DIR="../../data/ava/videos_15min" if [[ ! -d "${OUT_DATA_DIR}" ]]; then echo "${OUT_DATA_DIR} doesn't exist. Creating it."; mkdir -p ${OUT_DATA_DIR} fi for video in $(ls -A1 -U ${IN_DATA_DIR}/*) do out_name="${OUT_DATA_DIR}/${video##*/}" if [ ! -f "${out_name}" ]; then ffmpeg -ss 900 -t 901 -i "${video}" "${out_name}" fi done ``` -------------------------------- ### Test AVA model Source: https://context7.com/facebookresearch/slowfast/llms.txt Execute detection testing on the AVA dataset using a specified configuration and checkpoint. ```bash python tools/run_net.py \ --cfg configs/AVA/SLOWFAST_32x2_R50_SHORT.yaml \ AVA.FRAME_DIR /path/to/ava_frames \ TEST.CHECKPOINT_FILE_PATH /path/to/ava_checkpoint.pyth \ TRAIN.ENABLE False \ TEST.ENABLE True \ DETECTION.ENABLE True ``` -------------------------------- ### Enable Confusion Matrix on Tensorboard Source: https://github.com/facebookresearch/slowfast/blob/main/VISUALIZATION_TOOLS.md Configure Tensorboard to display confusion matrices by setting ENABLE to True and providing a path to a JSON file for category-to-class mapping. ```yaml TENSORBOARD: ENABLE: True CATEGORIES_PATH: # Path to a json file for categories -> classes mapping # in the format {"parent_class": ["child_class1", "child_class2",...], ...}. CONFUSION_MATRIX: ENABLE: True ``` -------------------------------- ### Manage model checkpoints Source: https://context7.com/facebookresearch/slowfast/llms.txt Utilities for saving, loading, and verifying model checkpoints, including support for Caffe2 formats and weight inflation. ```python from slowfast.utils import checkpoint as cu from slowfast.models import build_model from slowfast.config.defaults import get_cfg cfg = get_cfg() model = build_model(cfg) # Save checkpoint optimizer = torch.optim.SGD(model.parameters(), lr=0.1) cu.save_checkpoint( path_to_job="/path/to/output", model=model, optimizer=optimizer, epoch=10, cfg=cfg, scaler=None # GradScaler for mixed precision ) # Saves to: /path/to/output/checkpoints/checkpoint_epoch_00011.pyth # Load checkpoint for training epoch = cu.load_checkpoint( path_to_checkpoint="/path/to/checkpoint.pyth", model=model, data_parallel=True, # True if using DistributedDataParallel optimizer=optimizer, inflation=False, # Set True to inflate 2D weights to 3D convert_from_caffe2=False ) # Load from Caffe2 checkpoint cu.load_checkpoint( path_to_checkpoint="/path/to/caffe2_model.pkl", model=model, data_parallel=True, convert_from_caffe2=True ) # Load test checkpoint (simplified) cu.load_test_checkpoint(cfg, model) # Check if checkpoint exists has_ckpt = cu.has_checkpoint("/path/to/output") last_ckpt = cu.get_last_checkpoint("/path/to/output", task="") ``` -------------------------------- ### Construct Data Loaders Source: https://context7.com/facebookresearch/slowfast/llms.txt Initialize data loaders for training, validation, and testing phases using the construct_loader function. ```python from slowfast.datasets import loader from slowfast.config.defaults import get_cfg cfg = get_cfg() cfg.TRAIN.DATASET = "kinetics" cfg.DATA.PATH_TO_DATA_DIR = "/path/to/kinetics400" cfg.DATA.NUM_FRAMES = 8 cfg.DATA.SAMPLING_RATE = 8 cfg.TRAIN.BATCH_SIZE = 32 cfg.DATA_LOADER.NUM_WORKERS = 8 # Construct training loader train_loader = loader.construct_loader(cfg, "train") # Construct validation loader val_loader = loader.construct_loader(cfg, "val") # Construct test loader cfg.TEST.DATASET = "kinetics" cfg.TEST.BATCH_SIZE = 64 test_loader = loader.construct_loader(cfg, "test") ``` -------------------------------- ### Clone SlowFast Repository Source: https://github.com/facebookresearch/slowfast/blob/main/INSTALL.md Clones the SlowFast video understanding repository. This is the main repository for the project. ```bash git clone https://github.com/facebookresearch/slowfast ``` -------------------------------- ### Fine-tune MAE ViT-L on Kinetics-400 Source: https://github.com/facebookresearch/slowfast/blob/main/projects/mae/README.md This command is used to fine-tune a pre-trained MAE ViT-L model. You need to provide the path to your Kinetics dataset and the pre-trained checkpoint file. ```bash python tools/run_net.py \ --cfg configs/masked_ssl/k400_VIT_L_16x4_FT.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_Kinetics_dataset \ TRAIN.CHECKPOINT_FILE_PATH path_to_your_pretrain_checkpoint ``` -------------------------------- ### Iterate through training batches Source: https://context7.com/facebookresearch/slowfast/llms.txt Standard loop for processing video data batches in a training loader. ```python # Iterate through batches for inputs, labels, video_idx, time, meta in train_loader: # inputs: list of tensors [slow_pathway, fast_pathway] for SlowFast # or single tensor for other models # labels: class labels # video_idx: video indices # meta: additional metadata (boxes for detection) pass ``` -------------------------------- ### Train and test Rev-ViT Base Image model Source: https://github.com/facebookresearch/slowfast/blob/main/projects/rev/README.md Command to execute training and testing for the Rev-ViT Base model on ImageNet using the specified configuration. ```bash python tools/run_net.py \ --cfg configs/ImageNet/REV_VIT_B.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ NUM_GPUS 1 \ ``` -------------------------------- ### Extract frames with ffmpeg Source: https://github.com/facebookresearch/slowfast/blob/main/slowfast/datasets/DATASET.md Use this command to extract video frames at 30 FPS for dataset preparation. ```bash ffmpeg -i "${video}" -r 30 -q:v 1 "${out_name}" ``` -------------------------------- ### Cite Multigrid Training Source: https://github.com/facebookresearch/slowfast/blob/main/projects/multigrid/README.md BibTeX entry for referencing the Multigrid method in academic research. ```BibTeX @inproceedings{multigrid2020, Author = {Chao-Yuan Wu and Ross Girshick and Kaiming He and Christoph Feichtenhofer and Philipp Kr\"{a}henb\"{u}hl}, Title = {{A Multigrid Method for Efficiently Training Video Models}}, Booktitle = {{CVPR}}, Year = {2020}} ``` -------------------------------- ### Clone PyTorch Repository Source: https://github.com/facebookresearch/slowfast/blob/main/INSTALL.md Clones the PyTorch repository with its submodules. This is a prerequisite for building PyTorch from source. ```bash git clone --recursive https://github.com/pytorch/pytorch ``` -------------------------------- ### Extract Frames from AVA Videos Source: https://github.com/facebookresearch/slowfast/blob/main/slowfast/datasets/DATASET.md Extracts frames from the processed AVA videos at 30 FPS and saves them as JPEG images in a structured directory. Handles both .webm and other video extensions. ```bash IN_DATA_DIR="../../data/ava/videos_15min" OUT_DATA_DIR="../../data/ava/frames" if [[ ! -d "${OUT_DATA_DIR}" ]]; then echo "${OUT_DATA_DIR} doesn't exist. Creating it."; mkdir -p ${OUT_DATA_DIR} fi for video in $(ls -A1 -U ${IN_DATA_DIR}/*) do video_name=${video##*/} if [[ $video_name = *".webm" ]]; then video_name=${video_name::-5} else video_name=${video_name::-4} fi out_video_dir=${OUT_DATA_DIR}/${video_name}/ mkdir -p "${out_video_dir}" out_name="${out_video_dir}/${video_name}_%06d.jpg" ffmpeg -i "${video}" -r 30 -q:v 1 "${out_name}" done ``` -------------------------------- ### BibTeX citation for Reversible Vision Transformers Source: https://github.com/facebookresearch/slowfast/blob/main/projects/rev/README.md BibTeX entry for citing the Reversible Vision Transformers paper. ```BibTeX @inproceedings{mangalam2022, title = {Reversible Vision Transformers}, author = {Mangalam, Karttikeya and Fan, Haoqi and Li, Yanghao and Wu, Chao-Yuan and Xiong, Bo and Feichtenhofer, Christoph and Malik, Jitendra}, booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition}, year = {2022}, } ``` -------------------------------- ### BibTeX Citation Source: https://github.com/facebookresearch/slowfast/blob/main/projects/maskfeat/README.md BibTeX entry for citing the MaskFeat research paper. ```BibTeX @InProceedings{wei2022masked, author = {Wei, Chen and Fan, Haoqi and Xie, Saining and Wu, Chao-Yuan and Yuille, Alan and Feichtenhofer, Christoph}, title = {Masked Feature Prediction for Self-Supervised Visual Pre-Training}, booktitle = {CVPR}, year = {2022}, } ``` -------------------------------- ### Train MAE ViT-L on Kinetics-400 Source: https://github.com/facebookresearch/slowfast/blob/main/projects/mae/README.md Use this command to train a Masked Autoencoder Vision Transformer Large model on the Kinetics-400 dataset. Ensure the path to your dataset is correctly specified. ```bash python tools/run_net.py \ --cfg configs/masked_ssl/k400_VIT_L_16x4_MAE_PT.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_Kinetics_dataset ``` -------------------------------- ### Train MoCo R50 Slow-only Model Source: https://github.com/facebookresearch/slowfast/blob/main/projects/contrastive_ssl/README.md Use this command to train a MoCo R50 Slow-only model with 8x8 sampling on your dataset. Ensure you replace 'path_to_your_dataset' with the actual path. ```bash python tools/run_net.py \ --cfg configs/Kinetics/contrastive_ssl/MoCo_SlowR50_8x8.yaml \ DATA.PATH_TO_DATA_DIR path_to_your_dataset \ ``` -------------------------------- ### Multiscale Vision Transformers Citation (ICCV 2021) Source: https://github.com/facebookresearch/slowfast/blob/main/projects/mvitv2/README.md Cite this paper when referencing the original multiscale vision transformers concept. This entry is for the ICCV 2021 publication. ```bibtex @inproceedings{fan2021multiscale, title={Multiscale vision transformers}, author={Fan, Haoqi and Xiong, Bo and Mangalam, Karttikeya and Li, Yanghao and Yan, Zhicheng and Malik, Jitendra and Feichtenhofer, Christoph}, booktitle={ICCV}, year={2021} } ``` -------------------------------- ### MViTv2 Citation (CVPR 2022) Source: https://github.com/facebookresearch/slowfast/blob/main/projects/mvitv2/README.md Cite this paper when using MViTv2 for your research. This entry is for the CVPR 2022 publication. ```bibtex @inproceedings{li2021improved, title={MViTv2: Improved multiscale vision transformers for classification and detection}, author={Li, Yanghao and Wu, Chao-Yuan and Fan, Haoqi and Mangalam, Karttikeya and Xiong, Bo and Malik, Jitendra and Feichtenhofer, Christoph}, booktitle={CVPR}, year={2022} } ``` -------------------------------- ### MViT Paper Citation Source: https://github.com/facebookresearch/slowfast/blob/main/projects/mvit/README.md BibTeX entry for citing the Multiscale Vision Transformers paper. Include this in your LaTeX documents for academic referencing. ```bibtex @Article{mvit2021, author = {Haoqi Fan, Bo Xiong, Karttikeya Mangalam, Yanghao Li, Zhicheng Yan, Jitendra Malik, Christoph Feichtenhofer}, title = {Multiscale Vision Transformers}, journal = {arXiv:2104.11227}, Year = {2021}, } ``` -------------------------------- ### Add SlowFast to PYTHONPATH Source: https://github.com/facebookresearch/slowfast/blob/main/INSTALL.md Appends the SlowFast directory to the PYTHONPATH environment variable, making it accessible for Python imports. ```bash export PYTHONPATH=/path/to/SlowFast/slowfast:$PYTHONPATH ``` -------------------------------- ### Kinetics CSV File Format Source: https://github.com/facebookresearch/slowfast/blob/main/slowfast/datasets/DATASET.md The CSV file format required for the Kinetics dataset. Each line should contain the path to a video file and its corresponding label. ```text path_to_video_1 label_1 path_to_video_2 label_2 path_to_video_3 label_3 ... path_to_video_N label_N ``` -------------------------------- ### X3D Paper Citation Source: https://github.com/facebookresearch/slowfast/blob/main/projects/x3d/README.md BibTeX entry for citing the X3D paper in academic work. Include this in your LaTeX document's bibliography. ```bibtex @inproceedings{x3d2020, Author = {Christoph Feichtenhofer}, Title = {{X3D}: Progressive Network Expansion for Efficient Video Recognition}, Booktitle = {{CVPR}}, Year = {2020}} ``` -------------------------------- ### MAE Paper Citation Source: https://github.com/facebookresearch/slowfast/blob/main/projects/mae/README.md BibTeX entry for citing the 'Masked Autoencoders As Spatiotemporal Learners' paper. Use this in your research publications if you find the work useful. ```bibtex @article{feichtenhofer2022masked, title={Masked Autoencoders As Spatiotemporal Learners}, author={Feichtenhofer, Christoph and Fan, Haoqi and Li, Yanghao and He, Kaiming}, journal={arXiv preprint arXiv:2205.09113}, year={2022} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.