### Build MMPose from Source Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Clones the MMPose repository, navigates into the directory, installs requirements, and then installs MMPose in editable mode. This method is recommended for development. ```shell git clone https://github.com/open-mmlab/mmpose.git cd mmpose pip install -r requirements.txt pip install -v -e . ``` -------------------------------- ### Launch TensorBoard for Visualization Source: https://github.com/spiideo/mmpose/blob/main/docs/en/user_guides/train_and_test.md Starts the TensorBoard server to visualize training progress. It requires the path to the log directory where TensorBoard event files are saved. ```shell tensorboard --logdir ${WORK_DIR}/${TIMESTAMP}/vis_data ``` -------------------------------- ### Install TensorBoard for Visualization Source: https://github.com/spiideo/mmpose/blob/main/docs/en/user_guides/train_and_test.md Installs the TensorBoard library, a tool for visualizing machine learning experiments. This is a prerequisite for enabling TensorBoard visualization in MMPose. ```shell pip install tensorboard ``` -------------------------------- ### Install rtmlib from PyPI Source: https://github.com/spiideo/mmpose/blob/main/projects/rtmpose/examples/rtmlib/README.md Installs the rtmlib library from the Python Package Index (PyPI) using pip. This is the simplest way to get started. ```shell pip install rtmlib -i https://pypi.org/simple ``` -------------------------------- ### Install MMEngine using Pip Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md This command installs the MMEngine library using pip, providing an alternative to using MIM for installation. Ensure pip is up-to-date before running this command. ```shell pip install mmengine ``` -------------------------------- ### Install MMEngine, MMCV, and MMDetection with MIM (Python) Source: https://github.com/spiideo/mmpose/blob/main/demo/MMPose_Tutorial.ipynb This code snippet demonstrates how to install MMEngine, MMCV, and MMDetection using the MIM package manager. It first installs or upgrades `openmim`, then proceeds to install the specified packages with version constraints. Ensure you have Python and pip installed. ```python %pip install -U openmim !mim install mmengine !mim install "mmcv>=2.0.0" !mim install "mmdet>=3.0.0" ``` -------------------------------- ### Install xtcocotools from source Source: https://github.com/spiideo/mmpose/blob/main/docs/en/faq.md Provides instructions to clone the `xtcocoapi` repository and install `xtcocotools` from its source code. This method is useful when PyPI installation encounters issues or for developers needing the latest changes. ```bash git clone https://github.com/jin-s13/xtcocoapi cd xtcocoapi python setup.py install ``` -------------------------------- ### Install PyTorch with CUDA Support Source: https://github.com/spiideo/mmpose/blob/main/demo/MMPose_Tutorial.ipynb This code installs PyTorch, torchvision, and torchaudio, specifying a CUDA version. It's essential for users with CUDA-enabled GPUs to leverage hardware acceleration for pose estimation tasks. Ensure the CUDA version specified matches your system's setup. ```python # install dependencies: (if your colab has CUDA 11.8) %pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 ``` -------------------------------- ### MMPose Full Configuration Example with Codec Source: https://github.com/spiideo/mmpose/blob/main/docs/en/advanced_guides/codecs.md This is a comprehensive example of an MMPose configuration file, illustrating the setup of a 'TopdownPoseEstimator'. It includes definitions for the codec, model architecture (backbone, neck, head), data preprocessor, and training/testing pipelines. The codec is utilized in both the target generation and the model head, demonstrating its central role in the pose estimation workflow. ```Python # codec settings codec = dict(type='RegressionLabel', input_size=(192, 256)) ## definition ## # model settings model = dict( type='TopdownPoseEstimator', data_preprocessor=dict( type='PoseDataPreprocessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True), backbone=dict( type='ResNet', depth=50, init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), ), neck=dict(type='GlobalAveragePooling'), head=dict( type='RLEHead', in_channels=2048, num_joints=17, loss=dict(type='RLELoss', use_target_weight=True), decoder=codec), ## Head ## test_cfg=dict( flip_test=True, shift_coords=True, )) # base dataset settings dataset_type = 'CocoDataset' data_mode = 'topdown' data_root = 'data/coco/' backend_args = dict(backend='local') # pipelines train_pipeline = [ dict(type='LoadImage', backend_args=backend_args), dict(type='GetBBoxCenterScale'), dict(type='RandomFlip', direction='horizontal'), dict(type='RandomHalfBody'), dict(type='RandomBBoxTransform'), dict(type='TopdownAffine', input_size=codec['input_size']), dict(type='GenerateTarget', encoder=codec), ## Generate Target ## dict(type='PackPoseInputs') ] test_pipeline = [ dict(type='LoadImage', backend_args=backend_args), dict(type='GetBBoxCenterScale'), dict(type='TopdownAffine', input_size=codec['input_size']), dict(type='PackPoseInputs') ] ``` -------------------------------- ### Run MMPose Inference Demo from Source (Shell) Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md This shell command executes an image inference demo using MMPose installed from source. It takes an image file, configuration file, and checkpoint file as input, and outputs a visualization with predicted keypoints and heatmaps. Ensure you are in the '$MMPOSE' directory. ```shell python demo/image_demo.py \ tests/data/coco/000000000785.jpg \ td-hm_hrnet-w48_8xb32-210e_coco-256x192.py \ td-hm_hrnet-w48_8xb32-210e_coco-256x192-0e67c616_20220913.pth \ --out-file vis_results.jpg \ --draw-heatmap ``` -------------------------------- ### Install MMPose from Source on Google Colab Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Clones the MMPose repository and installs it in editable mode. This command assumes the previous dependency installation steps have been completed. ```shell !git clone https://github.com/open-mmlab/mmpose.git %cd mmpose !pip install -e . ``` -------------------------------- ### Install SMPLX Tools Source: https://github.com/spiideo/mmpose/blob/main/docs/en/dataset_zoo/3d_body_keypoint.md Installs the necessary SMPLX library, which is a dependency for generating 3D keypoints from the UBody dataset. This ensures that the 3D human models can be processed correctly. ```shell pip install smplx ``` -------------------------------- ### Install MMPose Dependencies using MIM Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Installs core MMPose dependencies, MMEngine and MMCV, using the MIM package manager. It also shows how to install MMDetection if needed for demo scripts. ```shell pip install -U openmim mim install mmengine mim install "mmcv>=2.0.1" mim install "mmdet>=3.1.0" ``` -------------------------------- ### MMPose Data Pipeline Configuration Example Source: https://github.com/spiideo/mmpose/blob/main/docs/en/advanced_guides/customize_transforms.md Illustrates how to configure a data pipeline in MMPose's configuration files, including RandomFlip, RandomHalfBody, RandomBBoxTransform, and TopdownAffine for data augmentation and transformation. ```python train_pipeline_stage2 = [ ... dict(type='RandomFlip', direction='horizontal'), dict(type='RandomHalfBody'), dict( type='RandomBBoxTransform', shift_factor=0., scale_factor=[0.75, 1.25], rotate_factor=60), dict( type='TopdownAffine', input_size=codec['input_size']), ... ] ``` -------------------------------- ### Verify MMPose Installation Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Checks if MMPose has been installed correctly by printing its version number. This is a simple verification step after installation. ```python import mmpose print(mmpose.__version__) ``` -------------------------------- ### Install Dependencies for Pose Anything Source: https://github.com/spiideo/mmpose/blob/main/projects/pose_anything/README.md Installs the 'timm' library, a common dependency for machine learning projects, after MMPose has been set up. Ensure a virtual environment is used for better dependency management. ```bash pip install timm ``` -------------------------------- ### Download Example Videos Source: https://github.com/spiideo/mmpose/blob/main/projects/just_dance/just_dance_demo.ipynb Downloads sample videos for student and teacher actions using `wget`. It ensures the 'resources' directory exists before downloading. These videos are used for pose estimation tasks. ```python # download example videos from mmengine.utils import mkdir_or_exist mkdir_or_exist('resources') ! wget -O resources/student_video.mp4 https://download.openmmlab.com/mmpose/v1/projects/just_dance/tom.mp4 ! wget -O resources/teacher_video.mp4 https://download.openmmlab.com/mmpose/v1/projects/just_dance/idol_producer.mp4 # ! wget -O resources/student_video.mp4 https://download.openmmlab.com/mmpose/v1/projects/just_dance/tsinghua_30fps.mp4 student_video = 'resources/student_video.mp4' teacher_video = 'resources/teacher_video.mp4' ``` -------------------------------- ### Install Cython before xtcocotools Source: https://github.com/spiideo/mmpose/blob/main/docs/en/faq.md This snippet shows the necessary step of installing `cython` before attempting to install `xtcocotools` from source. This is a prerequisite for compiling `xtcocotools` when direct pip installation fails due to missing cython modules. ```bash pip install cython git clone https://github.com/jin-s13/xtcocoapi cd xtcocoapi python setup.py install ``` -------------------------------- ### Install rtmlib from Source Source: https://github.com/spiideo/mmpose/blob/main/projects/rtmpose/examples/rtmlib/README.md Installs rtmlib from its source code. This involves cloning the repository, installing requirements, and then performing a local installation. It also includes optional installations for GPU acceleration with onnxruntime or openvino. ```shell git clone https://github.com/Tau-J/rtmlib.git cd rtmlib pip install -r requirements.txt pip install -e . # [optional] # pip install onnxruntime-gpu # pip install openvino ``` -------------------------------- ### Train MMPose Model with Single GPU Source: https://github.com/spiideo/mmpose/blob/main/projects/example_project/README.md Command to initiate model training using a single GPU with MMPose. It requires specifying the configuration file for the model. ```shell mim train mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py ``` -------------------------------- ### Custom Dataset Info Configuration Example (Python) Source: https://github.com/spiideo/mmpose/blob/main/docs/en/advanced_guides/customize_datasets.md Provides a simplified example of a `dataset_info` configuration file in Python, which is essential for defining metadata about a custom dataset. It outlines the structure for `keypoint_info`, `skeleton_info`, `joint_weights`, and `sigmas`, crucial for visualization, data augmentation, and evaluation. ```python dataset_info = dict( dataset_name='coco', paper_info=dict( author='Lin, Tsung-Yi and Maire, Michael and ' 'Belongie, Serge and Hays, James and ' 'Perona, Pietro and Ramanan, Deva and ' r'Doll{\'a}r, Piotr and Zitnick, C Lawrence', title='Microsoft coco: Common objects in context', container='European conference on computer vision', year='2014', homepage='http://cocodataset.org/', ), keypoint_info={ 0: dict(name='nose', id=0, color=[51, 153, 255], type='upper', swap=''), 1: dict( name='left_eye', id=1, color=[51, 153, 255], type='upper', swap='right_eye'), ... 16: dict( name='right_ankle', id=16, color=[255, 128, 0], type='lower', swap='left_ankle') }, skeleton_info={ 0: dict(link=('left_ankle', 'left_knee'), id=0, color=[0, 255, 0]), ... 18: dict( link=('right_ear', 'right_shoulder'), id=18, color=[51, 153, 255]) }, joint_weights=[ 1., 1., 1., 1., 1., 1., 1., 1.2, 1.2, 1.5, 1.5, 1., 1., 1.2, 1.2, 1.5, 1.5 ], sigmas=[ 0.026, 0.025, 0.025, 0.035, 0.035, 0.079, 0.079, 0.072, 0.072, 0.062, 0.062, 0.107, 0.107, 0.087, 0.087, 0.089, 0.089 ]) ``` -------------------------------- ### MMPose Training Configuration Examples (Python) Source: https://github.com/spiideo/mmpose/blob/main/configs/body_2d_keypoint/topdown_heatmap/coco/hrnet_coco_aic.md Python configuration files for training MMPose models. These examples demonstrate how to merge or combine COCO and AI Challenger datasets for training. ```python # Example for coco-aic-merge # This configuration leverages AIC data with partial keypoints as auxiliary data to train a COCO model # File path: /configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-aic-256x192-merge.py ``` ```python # Example for coco-aic-combine # This configuration constructs a combined dataset whose keypoints are the union of COCO and AIC keypoints to train a model that predicts keypoints of both datasets. # File path: /configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-aic-256x192-combine.py ``` -------------------------------- ### C++ Pose Detection with MMDeploy SDK Source: https://github.com/spiideo/mmpose/blob/main/projects/rtmpose/README.md This C++ example demonstrates pose detection using the MMDeploy SDK. It integrates with OpenCV for image handling and includes utility functions for argument parsing. The code initializes a PoseDetector, applies it to an image (optionally with a bounding box), and draws the detected keypoints. To build this example, ensure MMDeploy is configured in your CMake project. ```cpp #include "mmdeploy/pose_detector.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/imgproc.hpp" #include "utils/argparse.h" // See: https://github.com/open-mmlab/mmdeploy/blob/main/demo/csrc/cpp/utils/argparse.h DEFINE_ARG_string(model_path, "Model path"); DEFINE_ARG_string(image_path, "Input image path"); DEFINE_STRING(device_name, "cpu", R"(Device name, e.g. "cpu", "cuda")"); DEFINE_int32(bbox_x, -1, R"(x position of the bounding box)"); DEFINE_int32(bbox_y, -1, R"(y position of the bounding box)"); DEFINE_int32(bbox_w, -1, R"(width of the bounding box)"); DEFINE_int32(bbox_h, -1, R"(height of the bounding box)"); int main(int argc, char* argv[]) { if (!utils::ParseArguments(argc, argv)) { return -1; } cv::Mat img = cv::imread(ARGS_image_path); mmdeploy::PoseDetector detector(mmdeploy::Model{ARGS_model_path}, mmdeploy::Device{FLAGS_device_name, 0}); mmdeploy::PoseDetector::Result result{0, 0, nullptr}; if (FLAGS_bbox_x == -1 || FLAGS_bbox_y == -1 || FLAGS_bbox_w == -1 || FLAGS_bbox_h == -1) { result = detector.Apply(img); } else { // convert (x, y, w, h) -> (left, top, right, bottom) mmdeploy::cxx::Rect rect; rect.left = FLAGS_bbox_x; rect.top = FLAGS_bbox_y; rect.right = FLAGS_bbox_x + FLAGS_bbox_w; rect.bottom = FLAGS_bbox_y + FLAGS_bbox_h; result = detector.Apply(img, {rect}); } // Draw circles at detected keypoints for (size_t i = 0; i < result[0].length; ++i) { cv::Point keypoint(result[0].point[i].x, result[0].point[i].y); cv::circle(img, keypoint, 1, cv::Scalar(0, 255, 0), 2); // Draw filled circle } // Save the output image cv::imwrite("output_pose.png", img); return 0; } ``` ```cmake find_package(MMDeploy REQUIRED) target_link_libraries(${name} PRIVATE mmdeploy ${OpenCV_LIBS}) ``` -------------------------------- ### Run MMPose Inference Demo with Pip (Python) Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md This Python code snippet demonstrates how to perform top-down inference using MMPose installed via pip. It initializes the model with specified configuration and checkpoint files and then runs inference on an input image. The results contain predicted keypoint locations and scores. ```python from mmpose.apis import inference_topdown, init_model from mmpose.utils import register_all_modules register_all_modules() config_file = 'td-hm_hrnet-w48_8xb32-210e_coco-256x192.py' checkpoint_file = 'td-hm_hrnet-w48_8xb32-210e_coco-256x192-0e67c616_20220913.pth' model = init_model(config_file, checkpoint_file, device='cpu') # or device='cuda:0' # please prepare an image with person results = inference_topdown(model, 'demo.jpg') ``` -------------------------------- ### Launch Multi-GPU Training with MMPose (Shell) Source: https://github.com/spiideo/mmpose/blob/main/docs/en/user_guides/train_and_test.md Starts distributed training across multiple GPUs using torch.distributed.launch. Requires the configuration file and the number of GPUs. Additional Python arguments for tools/train.py can be passed. Environment variables like PORT can be set to customize the launcher's communication port. ```shell bash ./tools/dist_train.sh ${CONFIG_FILE} ${GPU_NUM} [PY_ARGS] ``` ```shell PORT=29666 bash ./tools/dist_train.sh ${CONFIG_FILE} ${GPU_NUM} [PY_ARGS] ``` ```shell CUDA_VISIBLE_DEVICES=0,1,2,3 PORT=29500 bash ./tools/dist_train.sh ${CONFIG_FILE1} 4 [PY_ARGS] CUDA_VISIBLE_DEVICES=4,5,6,7 PORT=29501 bash ./tools/dist_train.sh ${CONFIG_FILE2} 4 [PY_ARGS] ``` -------------------------------- ### Download MMPose Config and Checkpoint Files Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md This command downloads the necessary configuration and checkpoint files for MMPose to run inference demos. The download time depends on network speed, and it results in .py and .pth files in the current directory. ```shell mim download mmpose --config td-hm_hrnet-w48_8xb32-210e_coco-256x192 --dest . ``` -------------------------------- ### mmpose Configuration Example (Python) Source: https://github.com/spiideo/mmpose/blob/main/configs/wholebody_2d_keypoint/topdown_heatmap/coco-wholebody/cspnext_udp_coco-wholebody.md Example Python configuration file for training a pose estimation model on the COCO-WholeBody dataset using the CSPNeXt-M UDP architecture. This file specifies model, data, and training parameters. ```python '/configs/wholebody_2d_keypoint/topdown_heatmap/coco-wholebody/cspnext-m_udp_8xb64-210e_coco-wholebody-256x192.py' ``` -------------------------------- ### Run rtmlib Web UI Source: https://github.com/spiideo/mmpose/blob/main/projects/rtmpose/examples/rtmlib/README.md Launches the rtmlib web user interface, which requires the 'gradio' library to be installed. This provides an interactive way to test pose estimation. ```shell # Please make sure you have installed gradio # pip install gradio python webui.py ``` -------------------------------- ### MMDeploy SDK Inference Example (Python) Source: https://github.com/spiideo/mmpose/blob/main/projects/rtmpose/README.md Provides a basic Python code structure for performing inference using the MMDeploy SDK. This snippet assumes that the model has been converted and the necessary SDK files (pipeline.json, deploy.json, detail.json) have been dumped. ```python # SDK Python API example # ... code to follow ... ``` -------------------------------- ### Data Preprocessor Configuration Example Source: https://github.com/spiideo/mmpose/blob/main/docs/en/guide_to_framework.md A configuration dictionary for the PoseDataPreprocessor. It specifies the type of preprocessor and parameters for image normalization (mean, std) and channel order conversion (bgr_to_rgb). This is used to prepare input data for the model. ```python data_preprocessor=dict( type='PoseDataPreprocessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True), ``` -------------------------------- ### Install MMPose and Dependencies Source: https://context7.com/spiideo/mmpose/llms.txt Installs MMPose and its required dependencies using pip and mim. This includes MMEngine, MMCV, and MMDetection for detection models. It also shows how to install from source and verify the installation. ```bash # Install with pip pip install -U openmim mim install mmengine mim install "mmcv>=2.0.0" mim install mmdet # Required for detection models pip install -v -e . # Or install from source git clone https://github.com/open-mmlab/mmpose.git cd mmpose pip install -r requirements.txt pip install -v -e . # Verify installation python -c "import mmpose; print(mmpose.__version__)" # Download a pretrained model (example) mim download mmpose --config rtmpose-m_8xb256-420e_coco-256x192 \ --dest checkpoints/ ``` -------------------------------- ### View Git Version Source: https://github.com/spiideo/mmpose/blob/main/docs/en/contribution_guide.md Checks the installed Git version on your system. This is a basic command to verify Git installation. ```shell git --version ``` -------------------------------- ### Install Gradio for Web Application Source: https://github.com/spiideo/mmpose/blob/main/projects/just_dance/README.md Install the Gradio library, a dependency for building the interactive web application that allows for dance comparison with webcam input. ```shell pip install gradio ``` -------------------------------- ### Example YOLOX-Pose Inference Source: https://github.com/spiideo/mmpose/blob/main/projects/yolox_pose/README.md An example command demonstrating how to run YOLOX-Pose inference on a specific image. It specifies the input image, configuration file, checkpoint URL, scope, and output directory for visualizations. ```shell python demo/inferencer_demo.py ../../tests/data/coco/000000000785.jpg \ --pose2d configs/yolox-pose_s_8xb32-300e_coco.py \ --pose2d-weights https://download.openmmlab.com/mmpose/v1/projects/yolox-pose/yolox-pose_s_8xb32-300e_coco-9f5e3924_20230321.pth \ --scope mmyolo --vis-out-dir vis_results ``` -------------------------------- ### mmpose Configuration File Example (Python) Source: https://github.com/spiideo/mmpose/blob/main/configs/fashion_2d_keypoint/topdown_heatmap/deepfashion2/res50_deepfashion2.md This snippet shows an example of an mmpose configuration file for the DeepFashion2 dataset using a ResNet-50 backbone for top-down heatmap-based pose estimation. It specifies dataset, model architecture, input size, and training parameters. ```python td-hm_res50_6xb64-210e_deepfasion2-short-sleeved-shirt-256x192.py ``` -------------------------------- ### Test MMPose Model with Multiple GPUs Source: https://github.com/spiideo/mmpose/blob/main/projects/example_project/README.md Command to test a trained MMPose model using multiple GPUs with the PyTorch launcher. It requires the configuration file and the checkpoint path. ```shell mim test mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py $CHECKPOINT --launcher pytorch --gpus 8 ``` -------------------------------- ### Test MMPose Model with Single GPU Source: https://github.com/spiideo/mmpose/blob/main/projects/example_project/README.md Command to test a trained MMPose model using a single GPU. It requires the configuration file and the path to the checkpoint file. ```shell mim test mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py $CHECKPOINT ``` -------------------------------- ### Install PoseTrack Official Evaluation Tool Source: https://github.com/spiideo/mmpose/blob/main/docs/en/dataset_zoo/2d_body_keypoint.md This shell command demonstrates how to install the official evaluation tool for PoseTrack using pip from a GitHub repository. This tool is necessary for evaluating pose estimation and tracking results on the PoseTrack dataset. ```shell pip install git+https://github.com/svenkreiss/poseval.git ``` -------------------------------- ### Example: Run 2D Animal Pose Image Demo with Specific Models Source: https://github.com/spiideo/mmpose/blob/main/demo/docs/en/2d_animal_demo.md This example demonstrates running the 2D animal pose estimation demo with pre-trained models for mmdetection (RTMDET) and mmpose (HRNet-W32). It specifies an input image, enables visualization, heatmap drawing, and sets the detection category ID to 15 (cat). ```shell python demo/topdown_demo_with_mmdet.py \ demo/mmdetection_cfg/rtmdet_m_8xb32-300e_coco.py \ https://download.openmmlab.com/mmdetection/v3.0/rtmdet/rtmdet_m_8xb32-300e_coco/rtmdet_m_8xb32-300e_coco_20220719_112220-229f527c.pth \ configs/animal_2d_keypoint/topdown_heatmap/animalpose/td-hm_hrnet-w32_8xb64-210e_animalpose-256x256.py \ https://download.openmmlab.com/mmpose/animal/hrnet/hrnet_w32_animalpose_256x256-1aa7f075_20210426.pth \ --input tests/data/animalpose/ca110.jpeg \ --show --draw-heatmap --det-cat-id=15 ``` -------------------------------- ### Example Inference for UniFormer Pose Estimation Source: https://github.com/spiideo/mmpose/blob/main/projects/uniformer/README.md This is a concrete example of running the inference script for pose estimation. It specifies an input image, a UniFormer configuration file, and a path to the pretrained weights, directing visualization outputs to 'vis_results'. ```shell python demo/inferencer_demo.py tests/data/coco/000000000785.jpg \ --pose2d projects/uniformer/configs/td-hm_uniformer-s-8xb128-210e_coco-256x192.py \ --pose2d-weights https://download.openmmlab.com/mmpose/v1/projects/uniformer/top_down_256x192_global_small-d4a7fdac_20230724.pth \ --vis-out-dir vis_results ``` -------------------------------- ### Override Training Configuration Options Source: https://context7.com/spiideo/mmpose/llms.txt This command-line example shows how to override specific training configuration options, such as the maximum number of epochs and the learning rate, when launching the training script. ```shell python tools/train.py \ configs/body_2d_keypoint/rtmpose/coco/rtmpose-s_8xb256-420e_coco-256x192.py \ --cfg-options train_cfg.max_epochs=500 optim_wrapper.optimizer.lr=0.001 ``` -------------------------------- ### Train MMPose Model with Multiple GPUs Source: https://github.com/spiideo/mmpose/blob/main/projects/example_project/README.md Command to initiate model training using multiple GPUs with MMPose. It utilizes the PyTorch launcher and specifies the number of GPUs to use. ```shell mim train mmpose configs/example-head-loss_hrnet-w32_8xb64-210e_coco-256x192.py --launcher pytorch --gpus 8 ``` -------------------------------- ### Run MMPose Docker Container Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Runs a Docker container with GPU support and shared memory, mounting a local data directory. This command starts an MMPose environment within a Docker container. ```shell docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmpose/data mmpose ``` -------------------------------- ### Run Pose Tracking Inference on Video with MMDeploy CLI Source: https://github.com/spiideo/mmpose/blob/main/projects/rtmpose/README.md This command-line interface (CLI) example demonstrates how to perform pose tracking inference on a video file using the `pose_tracker` executable. It requires paths to the object detection and pose estimation models, the input video file, and allows configuration of the device and output settings. Webcam input is supported by passing '0' to the input argument. ```shell # go to the mmdeploy folder cd ${PATH_TO_MMDEPLOY}/build/bin/ # inference for a video ./pose_tracker rtmpose-ort/rtmdet-nano/ rtmpose-ort/rtmpose-m/ your_video.mp4 --device cpu required arguments: det_model Object detection model path [string] pose_model Pose estimation model path [string] input Input video path or camera index [string] optional arguments: --device Device name, e.g. "cpu", "cuda" [string = "cpu"] --output Output video path or format string [string = ""] --output_size Long-edge of output frames [int32 = 0] --flip Set to 1 for flipping the input horizontally [int32 = 0] --show Delay passed to `cv::waitKey` when using `cv::imshow`; -1: disable [int32 = 1] --skeleton Path to skeleton data or name of predefined skeletons: "coco", "coco-wholebody" [string = "coco"] --background Output background, "default": original image, "black": black background [string = "default"] --det_interval Detection interval [int32 = 1] --det_label Detection label use for pose estimation [int32 = 0] (0 refers to 'person' in coco) --det_thr Detection score threshold [double = 0.5] --det_min_bbox_size Detection minimum bbox size [double = -1] --det_nms_thr NMS IOU threshold for merging detected bboxes and bboxes from tracked targets [double = 0.7] --pose_max_num_bboxes Max number of bboxes used for pose estimation per frame [int32 = -1] --pose_kpt_thr Threshold for visible key-points [double = 0.5] --pose_min_keypoints Min number of key-points for valid poses, -1 indicates ceil(n_kpts/2) [int32 = -1] --pose_bbox_scale Scale for expanding key-points to bbox [double = 1.25] --pose_min_bbox_size Min pose bbox size, tracks with bbox size smaller than the threshold will be dropped [double = -1] --pose_nms_thr NMS OKS/IOU threshold for suppressing overlapped poses, useful when multiple pose estimations collapse to the same target [double = 0.5] --track_iou_thr IOU threshold for associating missing tracks [double = 0.4] --track_max_missing Max number of missing frames before a missing tracks is removed [int32 = 10] ``` -------------------------------- ### Install MMPose Dependencies on Google Colab Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Installs MMEngine, MMCV, and MMPose on Google Colab using MIM. This is a prerequisite for using MMPose in a Colab environment. ```shell !pip3 install openmim !mim install mmengine !mim install "mmcv>=2.0.1" ``` -------------------------------- ### Install MMPose as a Python Package Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Installs MMPose as a Python package using pip with the MIM package manager. This is the standard method for using MMPose as a dependency in other projects. ```shell mim install "mmpose>=1.1.0" ``` -------------------------------- ### Testing and Evaluating Models Source: https://context7.com/spiideo/mmpose/llms.txt These command-line examples demonstrate how to test and evaluate trained models on test datasets. They cover single GPU testing, multi-GPU testing using a distributed script, saving predictions to a file, visualizing predictions, and overriding testing configurations. ```shell # Single GPU testing python tools/test.py \ configs/body_2d_keypoint/rtmpose/coco/rtmpose-s_8xb256-420e_coco-256x192.py \ work_dirs/rtmpose_s/best_coco_AP_epoch_420.pth # Multi-GPU testing (4 GPUs) bash tools/dist_test.sh \ configs/body_2d_keypoint/rtmpose/coco/rtmpose-s_8xb256-420e_coco-256x192.py \ work_dirs/rtmpose_s/best_coco_AP_epoch_420.pth \ 4 # Save predictions to file python tools/test.py \ configs/body_2d_keypoint/rtmpose/coco/rtmpose-s_8xb256-420e_coco-256x192.py \ work_dirs/rtmpose_s/best_coco_AP_epoch_420.pth \ --out results.pkl # Visualize predictions during testing python tools/test.py \ configs/body_2d_keypoint/rtmpose/coco/rtmpose-s_8xb256-420e_coco-256x192.py \ work_dirs/rtmpose_s/best_coco_AP_epoch_420.pth \ --show-dir vis_test # Override config for testing python tools/test.py \ configs/body_2d_keypoint/rtmpose/coco/rtmpose-s_8xb256-420e_coco-256x192.py \ work_dirs/rtmpose_s/best_coco_AP_epoch_420.pth \ --cfg-options test_dataloader.batch_size=32 ``` -------------------------------- ### Train an MMPose Model Source: https://github.com/spiideo/mmpose/blob/main/docs/en/quick_run.md This bash command initiates the training process for an MMPose model using a specified configuration file. It assumes a single GPU setup by default but can be extended for distributed training. The command leverages the 'train.py' script provided by MMPose. ```Bash python tools/train.py configs/body_2d_keypoint/topdown_regression/coco/td-reg_res50_rle-8xb64-210e_coco-256x192.py ``` -------------------------------- ### Install PyTorch on CPU-only Platforms Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Installs PyTorch and torchvision for CPU-only environments using conda. This is suitable for systems without dedicated GPUs or when GPU support is not required. ```shell conda install pytorch torchvision cpuonly -c pytorch ``` -------------------------------- ### Install PyTorch on GPU Platforms Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Installs PyTorch and torchvision for GPU-enabled systems using conda. This command automatically selects the latest compatible versions of PyTorch and cudatoolkit. Users should verify compatibility with their environment. ```shell conda install pytorch torchvision -c pytorch ``` -------------------------------- ### Initialize MMPose Runner from Config Source: https://github.com/spiideo/mmpose/blob/main/demo/MMPose_Tutorial.ipynb Python code demonstrating how to import necessary classes from mmengine and initialize an MMPose runner using a configuration object (cfg). It also shows how to set data preprocessor configurations. ```python from mmengine.config import Config, DictAction from mmengine.runner import Runner # set preprocess configs to model cfg.model.setdefault('data_preprocessor', cfg.get('preprocess_cfg', {})) # build the runner from config runner = Runner.from_cfg(cfg) ``` -------------------------------- ### Install MMCV with Pip for Specific PyTorch and CUDA Versions Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md This command installs the MMCV library using pip, specifically for a given PyTorch and CUDA version. It uses a find-url to locate the correct pre-built wheels. This method is an alternative to using MIM and requires careful selection of the find-url based on your environment. ```shell pip install 'mmcv>=2.0.1' -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html ``` -------------------------------- ### Install MMPose and MMDetection for OpenPose Skeleton Generation Source: https://github.com/spiideo/mmpose/blob/main/projects/mmpose4aigc/README.md Installs the necessary MMPose and MMDetection libraries along with their dependencies. It also downloads pre-trained models required for skeleton generation. This setup is crucial for the OpenPose-style skeleton generation process. ```shell # install mmpose mmdet pip install openmim git clone https://github.com/open-mmlab/mmpose.git cd mmpose mim install -e . mim install "mmdet>=3.0.0rc6" # download models bash download_models.sh ``` -------------------------------- ### Run Pose Anything Demo with Custom Images Source: https://github.com/spiideo/mmpose/blob/main/projects/pose_anything/README.md Executes the demo script for Pose Anything using specified support and query images, a configuration file, and a pretrained checkpoint. This script allows for on-the-fly testing with custom inputs. ```bash python demo.py --support [path_to_support_image] --query [path_to_query_image] --config configs/demo_b.py --checkpoint [path_to_pretrained_ckpt] ``` -------------------------------- ### Build MMPose Docker Image Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Builds a Docker image for MMPose, including PyTorch, CUDA, and CUDNN. This command uses the provided Dockerfile to create a reproducible environment. ```shell docker build -t mmpose mmpose docker/ ``` -------------------------------- ### Run Webcam Pose Estimation with MMPose Demo Script Source: https://github.com/spiideo/mmpose/blob/main/demo/docs/en/webcam_api_demo.md This example demonstrates how to use a MMPose demo script, specifically `topdown_demo_with_mmdet.py`, for webcam-based pose estimation. It requires specifying 'webcam' as the input and includes model configuration and checkpoint paths. The `--show` argument displays the results. ```shell python demo/topdown_demo_with_mmdet.py \ projects/rtmpose/rtmdet/person/rtmdet_nano_320-8xb32_coco-person.py \ https://download.openmmlab.com/mmpose/v1/projects/rtmpose/rtmdet_nano_8xb32-100e_coco-obj365-person-05d8511e.pth \ projects/rtmpose/rtmpose/body_2d_keypoint/rtmpose-m_8xb256-420e_coco-256x192.py \ https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/rtmpose-m_simcc-aic-coco_pt-aic-coco_420e-256x192-63eb25f7_20230126.pth \ --input webcam \ --show ``` -------------------------------- ### Perform Inference with a Pretrained MMPose Model Source: https://github.com/spiideo/mmpose/blob/main/docs/en/quick_run.md This bash script demonstrates how to perform pose estimation on an image using a pretrained MMPose model. It requires the image path, the model configuration file, and the path to the pretrained model weights. The output is a visualized result of the pose estimation. ```Bash python demo/image_demo.py \ tests/data/coco/000000000785.jpg \ configs/body_2d_keypoint/topdown_regression/coco/td-reg_res50_rle-8xb64-210e_coco-256x192.py \ https://download.openmmlab.com/mmpose/top_down/deeppose/deeppose_res50_coco_256x192_rle-2ea9bb4a_20220616.pth ``` -------------------------------- ### Create and Activate Conda Environment Source: https://github.com/spiideo/mmpose/blob/main/docs/en/installation.md Creates a new conda environment named 'openmmlab' with Python 3.8 and activates it. This ensures a clean and isolated environment for the project dependencies. ```shell conda create --name openmmlab python=3.8 -y conda activate openmmlab ``` -------------------------------- ### MMPose Configuration Inheritance Example Source: https://github.com/spiideo/mmpose/blob/main/docs/en/user_guides/configs.md Demonstrates how to inherit the default runtime configuration in MMPose projects. The `_base_` variable is used to specify the path to the base configuration file, providing a starting point for your project's settings. ```Python _base_ = ['../../../_base_/default_runtime.py'] # take the config file as the starting point of the relative path ``` -------------------------------- ### Train DWPose with First Stage Distillation Source: https://github.com/spiideo/mmpose/blob/main/configs/wholebody_2d_keypoint/dwpose/README.md This command initiates the training process for DWPose using the first stage of distillation. It requires a configuration file and the number of processes to use for distributed training. The output is a trained model checkpoint. ```bash bash tools/dist_train.sh configs/wholebody_2d_keypoint/dwpose/ubody/s1_dis/rtmpose_x_dis_l_coco-ubody-384x288.py 8 ``` -------------------------------- ### Check System Environment Versions Source: https://github.com/spiideo/mmpose/blob/main/demo/MMPose_Tutorial.ipynb This snippet checks the versions of essential development tools like NVCC, GCC, and Python within the current Conda environment. These checks are crucial for ensuring compatibility and proper setup before installing MMPose and its dependencies. ```shell # check NVCC version !nvcc -V # check GCC version !gcc --version # check python in conda environment !which python ``` -------------------------------- ### Resolve 'No module named 'mmcv.ops'' Error Source: https://github.com/spiideo/mmpose/blob/main/docs/zh_cn/faq.md Outlines the steps to fix 'No module named 'mmcv.ops'' or 'No module named 'mmcv._ext'' errors. It requires uninstalling the current 'mmcv' and then reinstalling 'mmcv-full' according to the official installation guide. ```bash pip uninstall mmcv # Follow the official installation instruction to install mmcv-full ``` -------------------------------- ### Run 2D Hand Demo on CPU (Shell) Source: https://github.com/spiideo/mmpose/blob/main/demo/docs/en/2d_hand_demo.md This command demonstrates running the 2D hand keypoint detection demo using the CPU. It specifies the MMDetection and MMPose configuration files and checkpoint URLs, an input image, and explicitly sets the device to 'cpu'. ```shell python demo/topdown_demo_with_mmdet.py \ demo/mmdetection_cfg/rtmdet_nano_320-8xb32_hand.py \ https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/rtmdet_nano_8xb32-300e_hand-267f9c8f.pth \ configs/hand_2d_keypoint/rtmpose/hand5/rtmpose-m_8xb256-210e_hand5-256x256.py \ https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/rtmpose-m_simcc-hand5_pt-aic-coco_210e-256x256-74fb594_20230320.pth \ --input tests/data/onehand10k/9.jpg \ --show --draw-heatmap --device cpu ``` -------------------------------- ### Multi-Dataset Evaluation with MMPose Source: https://github.com/spiideo/mmpose/blob/main/docs/en/user_guides/train_and_test.md This Python code demonstrates how to set up MMPose for evaluating a model across multiple datasets, specifically COCO and AIC. It configures validation datasets and specifies metrics for each, aligning them with the dataset order. It also includes an example of using KeypointConverter to align AIC keypoints with COCO keypoints. ```python # Set up validation datasets coco_val = dict(type='CocoDataset', ...) aic_val = dict(type='AicDataset', ...) val_dataset = dict( type='CombinedDataset', datasets=[coco_val, aic_val], pipeline=val_pipeline, ...) # configurate the evaluator val_evaluator = dict( type='MultiDatasetEvaluator', metrics=[ dict(type='CocoMetric', ann_file='data/coco/annotations/person_keypoints_val2017.json'), dict(type='CocoMetric', ann_file='data/aic/annotations/aic_val.json', use_area=False, prefix='aic') ], datasets=[coco_val, aic_val], ) aic_to_coco_converter = dict( type='KeypointConverter', num_keypoints=17, mapping=[ (0, 6), (1, 8), (2, 10), (3, 5), (4, 7), (5, 9), (6, 12), (7, 14), (8, 16), (9, 11), (10, 13), (11, 15), ]) ``` -------------------------------- ### MMPose Configuration for AnimalKingdom P3 Mammals (HRNet-W32) Source: https://github.com/spiideo/mmpose/blob/main/configs/animal_2d_keypoint/topdown_heatmap/ak/hrnet_animalkingdom.md This Python configuration file details the training setup for an HRNet-W32 model on the AnimalKingdom dataset, focusing on the P3 mammals category. It includes specifications for the dataset, model, training epochs, batch size, and input size. This is a configuration file used to guide the training process. ```python configs/animal_2d_keypoint/topdown_heatmap/ak/td-hm_hrnet-w32_8xb32-300e_animalkingdom_P3_mammal-256x256.py ``` -------------------------------- ### Enable Heatmap Visualization via Command Line Source: https://github.com/spiideo/mmpose/blob/main/docs/en/quick_run.md This command-line option allows enabling heatmap visualization for MMPose without modifying configuration files directly. Appending `--cfg-options='model.test_cfg.output_heatmaps=True'` to the test script command will activate heatmap output. ```bash python tools/test.py \ \ \ --cfg-options='model.test_cfg.output_heatmaps=True' ``` -------------------------------- ### MMPose Environment and Visualization Settings Source: https://github.com/spiideo/mmpose/blob/main/demo/MMPose_Tutorial.ipynb Configures the environment settings, including CUDA behavior, multiprocessing, and distribution strategy. It also sets up visualization backends and the visualizer instance. ```python env_cfg = dict( cudnn_benchmark=False, mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0), dist_cfg=dict(backend='nccl')) vis_backends = [dict(type='LocalVisBackend')] visualizer = dict( type='PoseLocalVisualizer', vis_backends=[dict(type='LocalVisBackend')], name='visualizer') ``` -------------------------------- ### Train DWPose with Second Stage Distillation Source: https://github.com/spiideo/mmpose/blob/main/configs/wholebody_2d_keypoint/dwpose/README.md This command starts the training for DWPose with the second stage of distillation. It uses a specific configuration file for the second stage and specifies the number of distributed training processes. This step refines the pose estimation further. ```bash bash tools/dist_train.sh configs/wholebody_2d_keypoint/dwpose/ubody/s2_dis/dwpose_l-ll_coco-ubody-384x288.py 8 ``` -------------------------------- ### Verify MMPose Installation and Dependencies Source: https://github.com/spiideo/mmpose/blob/main/demo/MMPose_Tutorial.ipynb This Python script verifies the installation of MMPose and its core dependencies: PyTorch, torchvision, and mmcv. It checks their versions and CUDA availability. Ensure that these libraries are installed in your environment before running this script. ```python # Check Pytorch installation import torch, torchvision print('torch version:', torch.__version__, torch.cuda.is_available()) print('torchvision version:', torchvision.__version__) # Check MMPose installation import mmpose print('mmpose version:', mmpose.__version__) # Check mmcv installation from mmcv.ops import get_compiling_cuda_version, get_compiler_version print('cuda version:', get_compiling_cuda_version()) print('compiler information:', get_compiler_version()) ``` -------------------------------- ### Install mim Tool Source: https://github.com/spiideo/mmpose/blob/main/projects/rtmpose/examples/onnxruntime/README.md Installs the 'mim' tool, which is a dependency for downloading MMPose models. ```bash pip install -U openmim ``` -------------------------------- ### Config Inheritance Example in Python Source: https://github.com/spiideo/mmpose/blob/main/docs/en/user_guides/configs.md Demonstrates how to inherit configurations from other Python files using the `_base_` attribute in MMPose. This allows for modular configuration management, where settings from one file can be applied to another without explicit repetition. ```Python optimizer_cfg.py: optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001) ``` ```Python resnet50.py: _base_ = ['optimizer_cfg.py'] model = dict(type='ResNet', depth=50) ``` ```Python from mmengine import Config cfg = Config.fromfile('resnet50.py') print(cfg.optimizer) ``` -------------------------------- ### Printing Complete Configuration with MMPose Tools Source: https://github.com/spiideo/mmpose/blob/main/docs/en/user_guides/configs.md Shows how to use the `print_config.py` tool to inspect the complete configuration of a specific experiment. This is useful for understanding how base configurations are inherited and merged. ```bash python tools/analysis_tools/print_config.py /PATH/TO/CONFIG ```