### Install CLIP Library Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/actionclip/README.md Installs the CLIP library from its GitHub repository. This is a prerequisite for using ActionCLIP. ```shell pip install git+https://github.com/openai/CLIP.git ``` -------------------------------- ### Install and Inspect Tree Utility Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Installs the 'tree' utility to visualize directory structures and then displays the structure of the 'kinetics400_tiny' dataset. ```bash !apt-get -q install tree !tree kinetics400_tiny ``` -------------------------------- ### Install MMRazor from Source Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/knowledge_distillation/README.md Clone the MMRazor repository and install it from source. This method allows for direct modifications and development. ```shell git clone https://github.com/open-mmlab/mmrazor.git cd mmrazor pip install -v -e . ``` -------------------------------- ### Install MMAction2 and Dependencies Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/stad_tutorial/demo_stad.ipynb Installs necessary packages like openmim, mmengine, mmcv, and mmdet. Clones the MMAction2 repository and installs it in editable mode. Navigates to the tutorial directory. ```python %pip install -U openmim !mim install mmengine !mim install mmcv !mim install mmdet !git clone https://github.com/open-mmlab/mmaction2.git %cd mmaction2 %pip install -v -e . %cd projects/stad_tutorial ``` -------------------------------- ### Complete Finetuning Configuration Example Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/user_guides/finetune.md This is a complete configuration file example for finetuning, integrating all the previously discussed modifications for model head, dataset, training schedule, and pre-trained model loading. ```python _base_ = [ '../../_base_/models/tsn_r50.py', '../../_base_/schedules/sgd_100e.py', '../../_base_/default_runtime.py' ] # model settings model = dict( cls_head=dict( type='TSNHead', num_classes=101 # change from 400 to 101 )) ``` -------------------------------- ### Compose Pipeline Configuration Example Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/guide_to_framework.md Example configuration for an MMAction2 video processing pipeline using Compose. Demonstrates initialization and sampling transforms. ```python import os.path as osp from mmengine.dataset import Compose pipeline_cfg = [ dict(type='VideoInit'), dict(type='VideoSample', clip_len=16, num_clips=1, test_mode=False), ``` -------------------------------- ### Start Training Runner Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Initiates the training process using the configured runner. ```python runner.train() ``` -------------------------------- ### Example: Train TSN Model on Kinetics-400 Source: https://github.com/open-mmlab/mmaction2/blob/main/configs/recognition/tsn/README.md Example command for training a TSN model on the Kinetics-400 dataset with deterministic settings. Ensure the configuration file path is correct. ```shell python tools/train.py configs/recognition/tsn/tsn_imagenet-pretrained-r50_8xb32-1x1x3-100e_kinetics400-rgb.py \ --seed=0 --deterministic ``` -------------------------------- ### Install MMENGINE Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Installs the MMENGINE package, a foundational library for OpenMMLab projects. This command fetches the package from a specific index URL. ```bash pip install mmengine -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0.0/index.html ``` -------------------------------- ### Example Test Command for MViT on Kinetics-400 Source: https://github.com/open-mmlab/mmaction2/blob/main/configs/recognition/mvit/README.md This example demonstrates how to test an MViT model on the Kinetics-400 dataset and save the results to a pickle file. Ensure the paths to the config and checkpoint files are correct. ```shell python tools/test.py configs/recognition/mvit/mvit-small-p244_16x4x1_kinetics400-rgb.py \ checkpoints/SOME_CHECKPOINT.pth --dump result.pkl ``` -------------------------------- ### Install Tree Utility Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/stad_tutorial/demo_stad.ipynb Installs the 'tree' command-line utility, which is useful for visualizing directory structures. This is a prerequisite for the subsequent 'tree data' command. ```bash !apt-get -q install tree ``` -------------------------------- ### Install OpenMIM Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Installs the OpenMIM package, a dependency for managing models and configurations. Ensure you have a stable internet connection. ```bash pip install -r requirements/optional.txt ``` -------------------------------- ### Install MMAction2 from Source Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/installation.md Clone the MMAction2 repository and install it in editable mode using pip. This method is recommended for development and customization. ```shell git clone https://github.com/open-mmlab/mmaction2.git cd mmaction2 pip install -v -e . ``` -------------------------------- ### Example: Test LFB Model on AVA and Dump Results Source: https://github.com/open-mmlab/mmaction2/blob/main/configs/detection/lfb/README.md Example command for testing an LFB model on the AVA dataset with half-precision long-term feature banks. Results are dumped to a pkl file. ```shell python tools/test.py configs/detection/lfb/slowonly-lfb-nl_kinetics400-pretrained-r50_8xb12-4x16x1-20e_ava21-rgb.py \ checkpoints/SOME_CHECKPOINT.pth --dump result.pkl ``` -------------------------------- ### Configure SGD Optimizer Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/advanced_guides/customize_optimizer.md Use 'optim_wrapper' to configure optimization strategies. This example sets up a SGD optimizer with a specific learning rate and weight decay. ```python optim_wrapper = dict( type='OptimWrapper', optimizer=dict(type='SGD', lr=0.0003, weight_decay=0.0001) ) ``` -------------------------------- ### Example: Train LFB Model on AVA with Half-Precision Features Source: https://github.com/open-mmlab/mmaction2/blob/main/configs/detection/lfb/README.md Example command for training an LFB model on the AVA dataset using half-precision long-term feature banks. Includes setting a random seed and enabling deterministic operations. ```shell python tools/train.py configs/detection/lfb/slowonly-lfb-nl_kinetics400-pretrained-r50_8xb12-4x16x1-20e_ava21-rgb.py \ --seed 0 --deterministic ``` -------------------------------- ### Example: Test TSN Model and Dump Results Source: https://github.com/open-mmlab/mmaction2/blob/main/configs/recognition/tsn/README.md Example command for testing a TSN model on the Kinetics-400 dataset and saving the results to a pkl file. Replace 'SOME_CHECKPOINT.pth' with your actual checkpoint file. ```shell python tools/test.py configs/recognition/tsn/tsn_imagenet-pretrained-r50_8xb32-1x1x3-100e_kinetics400-rgb.py \ checkpoints/SOME_CHECKPOINT.pth --dump result.pkl ``` -------------------------------- ### Train a model with MMAction2 Source: https://github.com/open-mmlab/mmaction2/blob/main/configs/detection/slowfast/README.md Use this command to start the training process. Specify the configuration file and any optional arguments for customization. ```shell python tools/train.py ${CONFIG_FILE} [optional arguments] ``` ```shell python tools/train.py configs/detection/slowfast/slowfast_kinetics400-pretrained-r50_8xb16-4x16x1-20e_ava21-rgb.py \ --seed 0 --deterministic ``` -------------------------------- ### Initialize and Train Recognizer Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Initializes the work directory and builds the runner from the configuration object to start training. ```python import os.path as osp import mmengine from mmengine.runner import Runner # Create work_dir mmengine.mkdir_or_exist(osp.abspath(cfg.work_dir)) # build the runner from config runner = Runner.from_cfg(cfg) ``` -------------------------------- ### Initialize Pre-commit Hook Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/contribution_guide.md Install the pre-commit hook in the repository. This ensures that code linters and formatters are automatically enforced on every commit. ```shell pre-commit install ``` -------------------------------- ### Demo with STGCN and Faster R-CNN Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/README.md Example command to run the skeleton-based action recognition demo using STGCN as the action recognizer and Faster R-CNN for human detection. This configuration uses different action recognition checkpoints and configs compared to the PoseC3D example. ```shell python demo/demo_skeleton.py demo/demo_skeleton.mp4 demo/demo_skeleton_out.mp4 \ --config configs/skeleton/stgcn/stgcn_8xb16-joint-u100-80e_ntu60-xsub-keypoint-2d.py \ --checkpoint https://download.openmmlab.com/mmaction/v1.0/skeleton/stgcn/stgcn_8xb16-joint-u100-80e_ntu60-xsub-keypoint-2d/stgcn_8xb16-joint-u100-80e_ntu60-xsub-keypoint-2d_20221129-484a394a.pth \ --det-config demo/demo_configs/faster-rcnn_r50_fpn_2x_coco_infer.py \ --det-checkpoint http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_2x_coco/faster_rcnn_r50_fpn_2x_coco_bbox_mAP-0.384_20200504_210434-a5d8aa15.pth \ --det-score-thr 0.9 \ --det-cat-id 0 \ --pose-config demo/demo_configs/td-hm_hrnet-w32_8xb64-210e_coco-256x192_infer.py \ --pose-checkpoint https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w32_coco_256x192-c78dce93_20200708.pth \ --label-map tools/data/skeleton/label_map_ntu60.txt ``` -------------------------------- ### Start Multi-GPU Training Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/user_guides/train_test.md Use this script for multi-GPU training on a single machine. Specify the config file, number of GPUs, and optional Python arguments. ```shell bash tools/dist_train.sh ${CONFIG} ${GPUS} [PY_ARGS] ``` -------------------------------- ### Download and Preprocess Something-Something V2 with MIM Source: https://github.com/open-mmlab/mmaction2/blob/main/tools/data/sthv2/README.md Use OpenXlab CLI tools to download and preprocess the Something-Something V2 dataset. Ensure you have installed openxlab and logged in. ```bash # install OpenXlab CLI tools pip install -U openxlab # log in OpenXLab openxlab login # download and preprocess by MIM mim download mmaction2 --dataset sthv2 ``` -------------------------------- ### Install MMCV Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/faq.md Instructions for uninstalling existing mmcv and installing the correct version. Refer to the official installation guide for detailed steps. ```bash pip uninstall mmcv ``` -------------------------------- ### RecognizerZelda Initialization and Usage Example Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/guide_to_framework.md Demonstrates how to build, train, and test the RecognizerZelda model using a configuration dictionary. Includes data preprocessing and weight initialization. ```python import torch import copy from mmaction.registry import MODELS model_cfg = dict( type='RecognizerZelda', backbone=dict(type='BackBoneZelda'), cls_head=dict( type='ClsHeadZelda', num_classes=2, in_channels=128, average_clips='prob'), data_preprocessor = dict( type='DataPreprocessorZelda', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375])) model = MODELS.build(model_cfg) # Train model.train() model.init_weights() data_batch_train = copy.deepcopy(batched_packed_results) data = model.data_preprocessor(data_batch_train, training=True) loss = model(**data, mode='loss') print('loss dict: ', loss) # Test with torch.no_grad(): model.eval() data_batch_test = copy.deepcopy(batched_packed_results) data = model.data_preprocessor(data_batch_test, training=False) predictions = model(**data, mode='predict') print('Label of Sample[0]', predictions[0].gt_label) print('Scores of Sample[0]', predictions[0].pred_score) ``` -------------------------------- ### Train with Single GPU Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/knowledge_distillation/README.md Command to start training a knowledge distillation model using a single GPU. Specify the configuration file for the desired distillation setup. ```bash mim train mmrazor configs/kd_logits_tsm-res50_tsm-mobilenetv2_8xb16_k400.py ``` -------------------------------- ### Visualizer Configuration Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Sets up the visualizer, which utilizes the configured visualization backends. ```python visualizer = dict( ``` -------------------------------- ### Define Training Pipeline with Decord - MMAction2 Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/advanced_guides/customize_pipeline.md Example of a typical training data pipeline using Decord for video loading and various transformations. Ensure Decord is installed for this pipeline. ```python train_pipeline = [ dict(type='DecordInit',), dict(type='SampleFrames', clip_len=32, frame_interval=2, num_clips=1), dict(type='DecordDecode'), dict(type='Resize', scale=(-1, 256)), dict(type='RandomResizedCrop'), dict(type='Resize', scale=(224, 224), keep_ratio=False), dict(type='Flip', flip_ratio=0.5), dict(type='FormatShape', input_format='NCTHW'), dict(type='PackActionInputs') ] ``` -------------------------------- ### Building and Indexing Training Dataset Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/guide_to_framework.md Demonstrates how to build the training dataset using the configured dictionary and access the first data sample by index. It then prints the shape of the inputs and metadata. ```python from mmaction.registry import DATASETS train_dataset = DATASETS.build(train_dataset_cfg) packed_results = train_dataset[0] inputs = packed_results['inputs'] data_sample = packed_results['data_samples'] print('shape of the inputs: ', inputs.shape) # Get metainfo of the inputs print('image_shape: ', data_sample.img_shape) print('num_clips: ', data_sample.num_clips) print('clip_len: ', data_sample.clip_len) ``` -------------------------------- ### Install Core Dependencies with MIM Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/installation.md Install MMEngine, MMCV, MMDetection, and MMPose using the MIM package manager. This is a prerequisite for installing MMAction2. ```shell pip install -U openmim mim install mmengine mim install mmcv mim install mmdet mim install mmpose ``` -------------------------------- ### Recognize Video and Output to File Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/README.md Example showing how to run the video demo script and save the output to a specified MP4 file using the `--out-filename` argument. ```shell # The demo.mp4 and label_map_k400.txt are both from Kinetics-400 python demo/demo.py demo/demo_configs/tsn_r50_1x1x8_video_infer.py \ checkpoints/tsn_r50_8xb32-1x1x8-100e_kinetics400-rgb_20220818-2692d16c.pth \ demo/demo.mp4 tools/data/kinetics/label_map_k400.txt --out-filename demo/demo_out.mp4 ``` -------------------------------- ### Install MMAction2 Dependencies Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/stad_tutorial/demo_stad_zh_CN.ipynb Installs necessary packages including openmim, mmengine, mmcv, and mmdet using mim install. This is a prerequisite for setting up MMAction2. ```bash %pip install -U openmim !mim install mmengine !mim install mmcv !mim install mmdet ``` -------------------------------- ### Demo with PoseC3D and Faster R-CNN Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/README.md Example command to run the skeleton-based action recognition demo using PoseC3D as the action recognizer and Faster R-CNN for human detection. Ensure all specified config and checkpoint paths are correct. ```shell python demo/demo_skeleton.py demo/demo_skeleton.mp4 demo/demo_skeleton_out.mp4 \ --config configs/skeleton/posec3d/slowonly_r50_8xb16-u48-240e_ntu60-xsub-keypoint.py \ --checkpoint https://download.openmmlab.com/mmaction/skeleton/posec3d/slowonly_r50_u48_240e_ntu60_xsub_keypoint/slowonly_r50_u48_240e_ntu60_xsub_keypoint-f3adabf1.pth \ --det-config demo/demo_configs/faster-rcnn_r50_fpn_2x_coco_infer.py \ --det-checkpoint http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_2x_coco/faster_rcnn_r50_fpn_2x_coco_bbox_mAP-0.384_20200504_210434-a5d8aa15.pth \ --det-score-thr 0.9 \ --det-cat-id 0 \ --pose-config demo/demo_configs/td-hm_hrnet-w32_8xb64-210e_coco-256x192_infer.py \ --pose-checkpoint https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w32_coco_256x192-c78dce93_20200708.pth \ --label-map tools/data/skeleton/label_map_ntu60.txt ``` -------------------------------- ### Troubleshoot 'Please install XXCODEBASE' Error Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/zh_cn/get_started/faq.md This error indicates a missing dependency. Ensure mmcv and mmengine are installed before other OpenMMLAB codebases, following the official installation tutorial. -------------------------------- ### Run Webcam Demo Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/README.md Execute the webcam demo script with specified configuration, checkpoint, and label files. Optional arguments allow customization of device, camera ID, and prediction thresholds. ```shell python demo/webcam_demo.py ${CONFIG_FILE} ${CHECKPOINT_FILE} ${LABEL_FILE} \ [--device ${DEVICE_TYPE}] [--camera-id ${CAMERA_ID}] [--threshold ${THRESHOLD}] \ [--average-size ${AVERAGE_SIZE}] [--drawing-fps ${DRAWING_FPS}] [--inference-fps ${INFERENCE_FPS}] ``` -------------------------------- ### Install PyTorch on GPU Platforms Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/installation.md Install PyTorch and torchvision using Conda. This command automatically installs the latest compatible versions of PyTorch and cudatoolkit. Verify compatibility with your environment. ```shell conda install pytorch torchvision -c pytorch ``` -------------------------------- ### Inference Result Example Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/quick_run.md This is an example of the expected output format for inference results. ```json {'predictions': [{'rec_labels': [[6]], 'rec_scores': [[...]]}]} ``` -------------------------------- ### Visualizer Configuration Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Sets up the visualizer backend and type for action visualization. ```python vis_backends = [dict(type='LocalVisBackend')] visualizer = dict( type='ActionVisualizer', vis_backends=[dict(type='LocalVisBackend')]) ``` -------------------------------- ### Example Metric Output Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/guide_to_framework.md This is an example of the output format for the AccuracyMetric, showing top-1 and top-5 accuracy values. ```shell OrderedDict([('topk1', 0.5), ('topk5', 1.0)]) ``` -------------------------------- ### Visualizer Configuration with Multiple Backends Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/migration.md Sets up the visualizer with a specified type and a list of visualization backends, including local and TensorBoard options. ```python visualizer = dict( type='ActionVisualizer', vis_backends=[ dict(type='LocalVisBackend'), # Uncomment the below line to save the log and visualization results to TensorBoard. # dict(type='TensorboardVisBackend') ] ) ``` -------------------------------- ### Verify PyTorch, MMAction2, MMCV, and MMEngine Installation Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb This script checks the installation and versions of PyTorch (including CUDA availability), MMAction2, MMCV (compiling CUDA version and compiler version), and MMEngine. Ensure these libraries are installed correctly before proceeding. ```python # Check Pytorch installation import torch, torchvision print(torch.__version__, torch.cuda.is_available()) # Check MMAction2 installation import mmaction print(mmaction.__version__) # Check MMCV installation from mmcv.ops import get_compiling_cuda_version, get_compiler_version print(get_compiling_cuda_version()) print(get_compiler_version()) # Check MMEngine installation from mmengine.utils.dl_utils import collect_env print(collect_env()) ``` -------------------------------- ### Download Demo Files Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/installation.md Download the necessary configuration and checkpoint files for running the inference demo using MIM. Specify the config name and destination directory. ```shell mim download mmaction2 --config tsn_imagenet-pretrained-r50_8xb32-1x1x8-100e_kinetics400-rgb --dest . ``` -------------------------------- ### Install Pre-commit Hook Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/contribution_guide.md Install the pre-commit package to manage hooks. This is a prerequisite for enforcing code style and formatting. ```shell pip install -U pre-commit ``` -------------------------------- ### Video Demo with Output and Customization Source: https://context7.com/open-mmlab/mmaction2/llms.txt Performs a video demo, optionally saving the output video and customizing visualization parameters like font size and color. ```bash python demo/demo.py \ demo/demo_configs/tsn_r50_1x1x8_video_infer.py \ checkpoints/tsn_r50.pth \ demo/demo.mp4 \ tools/data/kinetics/label_map_k400.txt \ --out-filename demo/output.mp4 ``` ```bash python demo/demo.py \ demo/demo_configs/tsn_r50_1x1x8_video_infer.py \ checkpoints/tsn_r50.pth \ demo/demo.mp4 \ tools/data/kinetics/label_map_k400.txt \ --out-filename demo/output.mp4 \ --font-scale 1.0 \ --font-color white \ --target-resolution 1280 720 ``` -------------------------------- ### Install MMAction2 with Conda Source: https://github.com/open-mmlab/mmaction2/blob/main/README.md Follow these steps to install MMAction2 using Conda. Ensure your PyTorch and CUDA versions are compatible. ```shell conda create --name openmmlab python=3.8 -y conda activate openmmlab conda install pytorch torchvision -c pytorch # This command will automatically install the latest version PyTorch and cudatoolkit, please check whether they match your environment. pip install -U openmim mim install mmengine mim install mmcv mim install mmdet # optional mim install mmpose # optional git clone https://github.com/open-mmlab/mmaction2.git cd mmaction2 pip install -v -e . ``` -------------------------------- ### Clone and Install MMAction2 Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/stad_tutorial/demo_stad_zh_CN.ipynb Clones the MMAction2 repository from GitHub and installs it in editable mode. This command should be run after navigating into the cloned directory. ```bash !git clone https://github.com/open-mmlab/mmaction2.git %cd mmaction2 %pip install -v -e . %cd projects/stad_tutorial ``` -------------------------------- ### Optimizer and Learning Rate Scheduler Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/stad_tutorial/demo_stad.ipynb Sets up the learning rate scheduler and the optimizer wrapper. This example uses a ConstantLR scheduler and an SGD optimizer with specified learning rate, momentum, and weight decay. ```python param_scheduler = [ dict(type='ConstantLR', factor=1.0, by_epoch=False, begin=0, end=500) ] ``` ```python optim_wrapper = dict( type='OptimWrapper', optimizer=dict(type='SGD', lr=0.005, momentum=0.9, weight_decay=0.0001)) ``` -------------------------------- ### Action Visualizer Configuration Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/user_guides/config.md Sets up the action visualizer, specifying the type and the visualization backends to be employed. ```python visualizer = dict( type='ActionVisualizer', vis_backends=vis_backends) ``` -------------------------------- ### Basic Video Demo Source: https://context7.com/open-mmlab/mmaction2/llms.txt Runs a basic video demo using a specified configuration, checkpoint, video file, and label map. ```bash python demo/demo.py \ demo/demo_configs/tsn_r50_1x1x8_video_infer.py \ https://download.openmmlab.com/mmaction/v1.0/recognition/tsn/tsn_r50_8xb32-1x1x8-100e_kinetics400-rgb/tsn_r50_8xb32-1x1x8-100e_kinetics400-rgb_20220818-2692d16c.pth \ demo/demo.mp4 \ tools/data/kinetics/label_map_k400.txt ``` -------------------------------- ### Install Optional Requirements for MMAction2 Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Use this command to install additional requirements specified in the optional.txt file. This is useful for enabling extended functionalities. ```bash !pip install -r requirements/optional.txt ``` -------------------------------- ### Install PyTorch with CUDA 11.8 Support Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Installs PyTorch, TorchVision, and TorchAudio specifically compiled for CUDA 11.8. This is crucial for GPU acceleration. ```python # install dependencies: (if your colab has CUDA 11.8) %pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 ``` -------------------------------- ### Building and Indexing a Dataset Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/zh_cn/get_started/guide_to_framework.md Builds the training dataset using the configuration and then accesses the first sample by index. Prints information about the input data. ```python from mmaction.registry import DATASETS train_dataset = DATASETS.build(train_dataset_cfg) packed_results = train_dataset[0] inputs = packed_results['inputs'] data_sample = packed_results['data_samples'] print('shape of the inputs: ', inputs.shape) # 获取输入的信息 print('image_shape: ', data_sample.img_shape) print('num_clips: ', data_sample.num_clips) print('clip_len: ', data_sample.clip_len) # 获取输入的标签 print('label: ', data_sample.gt_label) ``` -------------------------------- ### Install MMRazor as a Python Package Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/knowledge_distillation/README.md Install MMRazor version 1.0.0 or higher using pip. This is a prerequisite for using the knowledge distillation features. ```shell mim install "mmrazor>=1.0.0" ``` -------------------------------- ### Install PyTorch on CPU Platforms Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/installation.md Install PyTorch and torchvision for CPU-only usage using Conda. This is suitable for environments without a compatible GPU. ```shell conda install pytorch torchvision cpuonly -c pytorch ``` -------------------------------- ### Weight Initialization Logs for RecognizerZelda Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/guide_to_framework.md Logs detailing the weight initialization process for different layers of the RecognizerZelda model, including Kaiming and Normal initialization strategies. ```shell 04/03 23:28:01 - mmengine - INFO - backbone.conv1.0.weight - torch.Size([64, 3, 3, 7, 7]): KaimingInit: a=0, mode=fan_out, nonlinearity=relu, distribution =normal, bias=0 04/03 23:28:01 - mmengine - INFO - backbone.conv1.0.bias - torch.Size([64]): KaimingInit: a=0, mode=fan_out, nonlinearity=relu, distribution =normal, bias=0 04/03 23:28:01 - mmengine - INFO - backbone.conv1.1.weight - torch.Size([64]): The value is the same before and after calling `init_weights` of RecognizerZelda 04/03 23:28:01 - mmengine - INFO - backbone.conv1.1.bias - torch.Size([64]): The value is the same before and after calling `init_weights` of RecognizerZelda 04/03 23:28:01 - mmengine - INFO - backbone.conv.0.weight - torch.Size([128, 64, 3, 3, 3]): KaimingInit: a=0, mode=fan_out, nonlinearity=relu, distribution =normal, bias=0 04/03 23:28:01 - mmengine - INFO - backbone.conv.0.bias - torch.Size([128]): KaimingInit: a=0, mode=fan_out, nonlinearity=relu, distribution =normal, bias=0 04/03 23:28:01 - mmengine - INFO - backbone.conv.1.weight - torch.Size([128]): The value is the same before and after calling `init_weights` of RecognizerZelda 04/03 23:28:01 - mmengine - INFO - backbone.conv.1.bias - torch.Size([128]): The value is the same before and after calling `init_weights` of RecognizerZelda 04/03 23:28:01 - mmengine - INFO - cls_head.fc.weight - torch.Size([2, 128]): NormalInit: mean=0, std=0.01, bias=0 04/03 23:28:01 - mmengine - INFO - cls_head.fc.bias - torch.Size([2]): NormalInit: mean=0, std=0.01, bias=0 loss dict: {'loss_cls': tensor(0.6853, grad_fn=)} Label of Sample[0] tensor([0]) Scores of Sample[0] tensor([0.5240, 0.4760]) ``` -------------------------------- ### Print Complete Config Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/user_guides/config.md Use this command to inspect the full configuration of a given config file. ```bash python tools/analysis_tools/print_config.py /PATH/TO/CONFIG ``` -------------------------------- ### Initialize Recognizer and Perform Inference Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/user_guides/inference.md Initializes a recognizer with a configuration and checkpoint, then performs inference on a video. Ensure the config and demo video are downloaded before running. The device can be set to 'cpu' or 'cuda:0'. ```python from mmaction.apis import inference_recognizer, init_recognizer config_path = 'configs/recognition/tsn/tsn_imagenet-pretrained-r50_8xb32-1x1x8-100e_kinetics400-rgb.py' checkpoint_path = 'https://download.openmmlab.com/mmaction/v1.0/recognition/tsn/tsn_imagenet-pretrained-r50_8xb32-1x1x8-100e_kinetics400-rgb/tsn_imagenet-pretrained-r50_8xb32-1x1x8-100e_kinetics400-rgb_20220906-2692d16c.pth' # can be a local path img_path = 'demo/demo.mp4' # you can specify your own picture path # build the model from a config file and a checkpoint file model = init_recognizer(config_path, checkpoint_path, device="cpu") # device can be 'cuda:0' # test a single image result = inference_recognizer(model, img_path) ``` -------------------------------- ### Install MMAction2 and Dependencies Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/mmaction2_tutorial.ipynb Installs MMEngine, MMCV, and MMAction2 using MIM and pip. This includes cloning the repository and setting up the package in editable mode. ```python # install MMEngine, MMCV and MMDetection using MIM %pip install -U openmim !mim install mmengine !mim install "mmcv>=2.0.0" # Install mmaction2 !rm -rf mmaction2 !git clone https://github.com/open-mmlab/mmaction2.git -b main %cd mmaction2 !pip install -e . ``` -------------------------------- ### Run Video Demo Script Source: https://github.com/open-mmlab/mmaction2/blob/main/demo/README.md Use this command to run the demo script for video recognition. Specify configuration, checkpoint, video, and label files. Optional arguments allow customization of device, FPS, text styling, resolution, and output file. ```shell python demo/demo.py ${CONFIG_FILE} ${CHECKPOINT_FILE} ${VIDEO_FILE} ${LABEL_FILE} \ [--device ${DEVICE_TYPE}] [--fps ${FPS}] [--font-scale ${FONT_SCALE}] [--font-color ${FONT_COLOR}] \ [--target-resolution ${TARGET_RESOLUTION}] [--out-filename ${OUT_FILE}] ``` -------------------------------- ### Install MoviePy for Video Processing Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/zh_cn/get_started/faq.md Install MoviePy using pip. For Windows, ensure ImageMagick is correctly configured. For Linux, adjust the ImageMagick policy file if necessary. ```bash pip install moviepy ``` -------------------------------- ### Optimizer Wrapper Configuration Source: https://github.com/open-mmlab/mmaction2/blob/main/projects/stad_tutorial/demo_stad.ipynb Sets up the optimizer wrapper using SGD with a learning rate of 0.005, momentum of 0.9, and weight decay of 0.0001. ```python optim_wrapper = dict( type='OptimWrapper', optimizer=dict(type='SGD', lr=0.005, momentum=0.9, weight_decay=0.0001)) ``` -------------------------------- ### Install MMCV with Pip for PyTorch 1.10.x and CUDA 11.3 Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/installation.md Use this command to install MMCV when not using MIM. It specifies the find-url based on the PyTorch and CUDA versions. ```shell pip install mmcv -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html ``` -------------------------------- ### Real-time Spatio-temporal Action Detection Webcam Demo Source: https://context7.com/open-mmlab/mmaction2/llms.txt Run a real-time spatio-temporal action detection demo using a webcam. This requires specifying the input video source (0 for webcam), model configuration, pre-trained checkpoint, and detection configurations. ```bash python demo/webcam_demo_spatiotemporal_det.py \ --input-video 0 \ --config configs/detection/slowonly/slowonly_kinetics400-pretrained-r101_8xb16-8x8x1-20e_ava21-rgb.py \ --checkpoint https://download.openmmlab.com/mmaction/detection/ava/slowonly_omnisource_pretrained_r101_8x8x1_20e_ava_rgb/slowonly_omnisource_pretrained_r101_8x8x1_20e_ava_rgb_20201217-16378594.pth \ --det-config demo/demo_configs/faster-rcnn_r50_fpn_2x_coco_infer.py \ --det-checkpoint http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_2x_coco/faster_rcnn_r50_fpn_2x_coco_bbox_mAP-0.384_20200504_210434-a5d8aa15.pth \ --det-score-thr 0.9 \ --action-score-thr 0.5 \ --label-map tools/data/ava/label_map.txt \ --predict-stepsize 40 \ --output-fps 20 \ --show ``` -------------------------------- ### Install MMAction2 as a Python Package Source: https://github.com/open-mmlab/mmaction2/blob/main/docs/en/get_started/installation.md Install MMAction2 directly as a Python package using pip. This is suitable for users who only need to import and use MMAction2's APIs. ```shell pip install mmaction2 ``` -------------------------------- ### Download AVA Videos with GNU Parallel Source: https://github.com/open-mmlab/mmaction2/blob/main/tools/data/ava/README.md Speeds up AVA video downloading using GNU Parallel, which may require installation via `sudo apt-get install parallel`. ```shell # sudo apt-get install parallel bash download_videos_gnu_parallel.sh ``` -------------------------------- ### Webcam Demo with I3D Source: https://context7.com/open-mmlab/mmaction2/llms.txt Run a webcam demo using the I3D model for accurate action recognition. Ensure you have the necessary configuration, checkpoint, and label map files. ```bash python demo/webcam_demo.py \ demo/demo_configs/i3d_r50_32x2x1_video_infer.py \ checkpoints/i3d_imagenet-pretrained-r50_8xb8-32x2x1-100e_kinetics400-rgb.pth \ tools/data/kinetics/label_map_k400.txt \ --average-size 5 \ --threshold 0.2 ``` -------------------------------- ### Create Directories and Symbolic Links for Rawframes Source: https://github.com/open-mmlab/mmaction2/blob/main/tools/data/kinetics/README.md Execute these commands to create directories for extracted rawframes and symbolic links to the data directory. Assumes the SSD is mounted at /mnt/SSD/. ```shell mkdir /mnt/SSD/${DATASET}_extracted_train/ ln -s /mnt/SSD/${DATASET}_extracted_train/ ../../../data/${DATASET}/rawframes_train/ mkdir /mnt/SSD/${DATASET}_extracted_val/ ln -s /mnt/SSD/${DATASET}_extracted_val/ ../../../data/${DATASET}/rawframes_val/ ```