### Install xtcocotools from Source (Python) Source: https://mmpose.readthedocs.io/en/latest/faq Provides instructions for installing the xtcocotools package from its GitHub repository when direct pip installation fails. This involves cloning the repository, navigating into the directory, and running the setup script. Ensure you have git and Python installed. ```shell git clone https://github.com/jin-s13/xtcocoapi cd xtcocoapi python setup.py install ``` -------------------------------- ### Install MMEngine using pip Source: https://mmpose.readthedocs.io/en/latest/installation Installs the MMEngine library using pip. This is an alternative to using MIM for installation. ```bash pip install mmengine ``` -------------------------------- ### Install MMPose from Source Source: https://mmpose.readthedocs.io/en/latest/installation Installs MMPose directly from its GitHub repository for development purposes. This involves cloning the repository, installing dependencies from 'requirements.txt', and then installing MMPose in editable mode. ```shell git clone https://github.com/open-mmlab/mmpose.git cd mmpose pip install -r requirements.txt pip install -v -e . ``` -------------------------------- ### Install MMPose from source on Google Colab Source: https://mmpose.readthedocs.io/en/latest/installation Installs MMPose from its GitHub repository directly within a Google Colab environment. This involves cloning the repository and performing an editable installation. ```python !git clone https://github.com/open-mmlab/mmpose.git %cd mmpose !pip install -e . ``` -------------------------------- ### Run MMPose Inference Demo from Source Source: https://mmpose.readthedocs.io/en/latest/installation Executes an image inference demo using MMPose when installed from source. It requires specifying the path to the image, configuration file, and checkpoint file, along with output options. ```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 MMEngine and MMCV using MIM Source: https://mmpose.readthedocs.io/en/latest/installation Installs the MMEngine and MMCV libraries using the MIM package manager. It's recommended to use MIM for installing these core components of the OpenMMLab ecosystem. ```shell pip install -U openmim mim install mmengine mim install "mmcv>=2.0.1" ``` -------------------------------- ### Install TensorBoard Source: https://mmpose.readthedocs.io/en/latest/user_guides/train_and_test Installs the TensorBoard library, a visualization tool for TensorFlow and PyTorch. This is a prerequisite for enabling TensorBoard visualization within the MMPose training process. ```bash pip install tensorboard ``` -------------------------------- ### Install and Configure Pre-commit Hooks Source: https://mmpose.readthedocs.io/en/latest/contribution_guide Installs pre-commit, configures it for local development, and runs all configured hooks on the project files. This ensures code style consistency according to OpenMMLab standards. ```shell pip install -U pre-commit pre-commit install pre-commit run --all-files ``` -------------------------------- ### Install SMPLX Tools Source: https://mmpose.readthedocs.io/en/latest/dataset_zoo/3d_body_keypoint This command installs the necessary SMPLX tools, which are required for certain 3D human pose estimation tasks, particularly when dealing with datasets that utilize SMPL-X models. ```bash pip install smplx ``` -------------------------------- ### Install Pre-commit with Alternative Mirrors Source: https://mmpose.readthedocs.io/en/latest/contribution_guide Provides alternative pip installation commands for pre-commit, useful for Chinese users facing network issues with default PyPI mirrors. It facilitates downloading pre-commit hooks from specified Tsinghua or USTC mirrors. ```shell pip install -U pre-commit -i https://pypi.tuna.tsinghua.edu.cn/simple ``` ```shell pip install -U pre-commit -i https://pypi.mirrors.ustc.edu.cn/simple ``` -------------------------------- ### Install MMDetection using MIM Source: https://mmpose.readthedocs.io/en/latest/installation Installs the MMDetection library using MIM. This is an optional step required if demo scripts in MMPose utilize MMDetection for human detection. ```shell mim install "mmdet>=3.1.0" ``` -------------------------------- ### Install PoseTrack Evaluation Tool Source: https://mmpose.readthedocs.io/en/latest/dataset_zoo/2d_body_keypoint Installs the official evaluation tool for PoseTrack from GitHub using pip. This is necessary for evaluating pose estimation results on the PoseTrack dataset. ```shell pip install git+https://github.com/svenkreiss/poseval.git ``` -------------------------------- ### Launch TensorBoard Visualization Source: https://mmpose.readthedocs.io/en/latest/user_guides/train_and_test Starts the TensorBoard server to visualize training logs and metrics. The command points to the directory containing the TensorBoard event files, typically located within the experiment's working directory. ```bash tensorboard --logdir ${WORK_DIR}/${TIMESTAMP}/vis_data ``` -------------------------------- ### Install MMEngine and MMCV on Google Colab using MIM Source: https://mmpose.readthedocs.io/en/latest/installation Installs MMEngine and MMCV on Google Colab using the MIM package manager. This is typically part of a larger MMPose setup process on Colab. ```python !pip3 install openmim !mim install mmengine !mim install "mmcv>=2.0.1" ``` -------------------------------- ### Save Visualization Results Locally Source: https://mmpose.readthedocs.io/en/latest/user_guides/inference This code snippet shows how to save pose estimation visualization results locally to a specified directory. The `vis_out_dir` argument is used to define the output folder. Results will be saved in the specified directory, for example, 'vis_results/'. ```python result_generator = inferencer(img_path, vis_out_dir='vis_results') result = next(result_generator) ``` -------------------------------- ### Download MMPose Model Assets Source: https://mmpose.readthedocs.io/en/latest/installation Downloads configuration and checkpoint files for a specific MMPose model using the 'mim download' command. These files are necessary for running inference demos. ```shell mim download mmpose --config td-hm_hrnet-w48_8xb32-210e_coco-256x192 --dest . ``` -------------------------------- ### Clone Forked Repository and Add Upstream Source: https://mmpose.readthedocs.io/en/latest/contribution_guide This snippet guides through cloning your forked MMPose repository from GitHub and adding the official OpenMMLab repository as an 'upstream' remote. This setup is crucial for synchronizing your local repository with the main project and for submitting pull requests. ```bash # clone the forked repository git clone https://github.com/username/mmpose.git # Add official repository as upstream remote cd mmpose git remote add upstream https://github.com/open-mmlab/mmpose.git ``` -------------------------------- ### Verify MMPose installation on Google Colab Source: https://mmpose.readthedocs.io/en/latest/installation Prints the installed MMPose version to verify a successful installation on Google Colab. This command should be run after MMPose has been installed. ```python import mmpose print(mmpose.__version__) ``` -------------------------------- ### Convert MMPose Models using MMDeploy Source: https://mmpose.readthedocs.io/en/latest/user_guides/how_to_deploy This script facilitates the conversion of MMPose models to various deployment backends. It requires paths to deployment configuration, model configuration, model checkpoint, and an input image. Optional arguments control the working directory, device, log level, and output options. Dependencies include MMDeploy and MMPose. ```shell python ./tools/deploy.py \ ${DEPLOY_CFG_PATH} \ ${MODEL_CFG_PATH} \ ${MODEL_CHECKPOINT_PATH} \ ${INPUT_IMG} \ --test-img ${TEST_IMG} \ --work-dir ${WORK_DIR} \ --calib-dataset-cfg ${CALIB_DATA_CFG} \ --device ${DEVICE} \ --log-level INFO \ --show \ --dump-info ``` -------------------------------- ### Install PyTorch for GPU Source: https://mmpose.readthedocs.io/en/latest/installation Installs PyTorch and torchvision for GPU platforms using Conda. It automatically installs the latest compatible versions of PyTorch and cudatoolkit, which users should verify against their environment. ```shell conda install pytorch torchvision -c pytorch ``` -------------------------------- ### Configure Visualization Backends for Real-time Training Curves Source: https://mmpose.readthedocs.io/en/latest/faq Enables real-time visualization of training accuracy and loss curves by modifying the `vis_backends` setting in the configuration file. It demonstrates how to include both local file-based visualization and TensorBoard logging. ```python vis_backends = [ dict(type='LocalVisBackend'), dict(type='TensorboardVisBackend') ] ``` -------------------------------- ### MultilevelPixelData Initialization and Data Handling Example Source: https://mmpose.readthedocs.io/en/latest/_modules/mmpose/structures/multilevel_pixel_data Demonstrates how to initialize and use the MultilevelPixelData class. It shows creating an instance with metadata and multi-level pixel data (heatmaps and masks), accessing data by level, retrieving the number of levels, and getting the shapes of the data at each level. It also illustrates setting additional data fields. ```python metainfo = dict(num_keypoints=17) sizes = [(64, 48), (128, 96), (256, 192)] heatmaps = [np.random.rand(17, h, w) for h, w in sizes] masks = [torch.rand(1, h, w) for h, w in sizes] data = MultilevelPixelData(metainfo=metainfo, heatmaps=heatmaps, masks=masks) # get data item heatmaps = data.heatmaps # A list of 3 numpy.ndarrays masks = data.masks # A list of 3 torch.Tensors # get level data_l0 = data[0] # PixelData with fields 'heatmaps' and 'masks' print(data.nlevel) # get shape print(data.shape) # set offset_maps = [torch.rand(2, h, w) for h, w in sizes] data.offset_maps = offset_maps ``` -------------------------------- ### Install PyTorch for CPU Source: https://mmpose.readthedocs.io/en/latest/installation Installs PyTorch and torchvision for CPU-only platforms using Conda. This option should be used when a GPU is not available. ```shell conda install pytorch torchvision cpuonly -c pytorch ``` -------------------------------- ### Install MMPose as a Python Package Source: https://mmpose.readthedocs.io/en/latest/installation Installs MMPose as a Python package using MIM, allowing it to be used as a dependency in other projects. The version specifier ensures compatibility. ```shell mim install "mmpose>=1.1.0" ``` -------------------------------- ### Install MMCV with specific PyTorch and CUDA versions using pip Source: https://mmpose.readthedocs.io/en/latest/installation Installs MMCV from a specific URL, compatible with PyTorch 1.10.x and CUDA 11.3. This method requires manually specifying the find-url based on the PyTorch and CUDA versions. ```bash pip install 'mmcv>=2.0.1' -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html ``` -------------------------------- ### Initialize MMPose Model in Python Source: https://mmpose.readthedocs.io/en/latest/installation Initializes an MMPose model within a Python script using the 'init_model' function. It requires the configuration file, checkpoint file, and the device ('cpu' or 'cuda'). 'register_all_modules' ensures all necessary components are loaded. ```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' ``` -------------------------------- ### Run 2D Face Keypoint Image Demo (General) Source: https://mmpose.readthedocs.io/en/latest/demos This is a general command template for running the 2D face keypoint estimation demo on images using mmdet for face detection. It requires paths to MMDetection and MMPose configuration files and checkpoints. Optional arguments allow specifying input/output paths, visualization, device, and saving predictions. ```python python demo/topdown_demo_with_mmdet.py \ ${MMDET_CONFIG_FILE} ${MMDET_CHECKPOINT_FILE} \ ${MMPOSE_CONFIG_FILE} ${MMPOSE_CHECKPOINT_FILE} \ --input ${INPUT_PATH} [--output-root ${OUTPUT_DIR}] \ [--show] [--device ${GPU_ID or CPU}] [--save-predictions] \ [--draw-heatmap ${DRAW_HEATMAP}] [--radius ${KPT_RADIUS}] \ [--kpt-thr ${KPT_SCORE_THR}] [--bbox-thr ${BBOX_SCORE_THR}] ``` -------------------------------- ### Install h5py Dependency Source: https://mmpose.readthedocs.io/en/latest/user_guides/dataset_tools Installs the 'h5py' library, which is a dependency for parsing certain dataset formats like COFW. ```bash pip install h5py ``` -------------------------------- ### Download Datasets with MIM (Shell) Source: https://mmpose.readthedocs.io/en/latest/user_guides/prepare_datasets This section provides commands for downloading datasets using the `mim` tool, which is part of the OpenXLab ecosystem. It includes upgrading MIM, installing OpenXLab CLI, logging in, and downloading specific datasets like COCO2017. ```shell # upgrade your MIM pip install -U openmim # install OpenXLab CLI tools pip install -U openxlab # log in OpenXLab openxlab login # download coco2017 and preprocess by MIM mim download mmpose --dataset coco2017 ``` ```shell mim download mmpose --dataset coco2017 ``` ```shell mim download mmpose --dataset mpii ``` ```shell mim download mmpose --dataset aic ``` ```shell mim download mmpose --dataset crowdpose ``` ```shell mim download mmpose --dataset lapa ``` ```shell mim download mmpose --dataset 300w ``` ```shell mim download mmpose --dataset wflw ``` ```shell mim download mmpose --dataset onehand10k ``` ```shell mim download mmpose --dataset freihand ``` ```shell mim download mmpose --dataset hagrid ``` ```shell mim download mmpose --dataset halpe ``` ```shell mim download mmpose --dataset ap10k ``` -------------------------------- ### Create and Activate Conda Environment Source: https://mmpose.readthedocs.io/en/latest/installation Creates a new Conda environment named 'openmmlab' with Python 3.8 and activates it. This is a prerequisite for installing PyTorch and other dependencies. ```shell conda create --name openmmlab python=3.8 -y conda activate openmmlab ``` -------------------------------- ### Run MMPose Docker container Source: https://mmpose.readthedocs.io/en/latest/installation Runs a Docker container for MMPose, enabling GPU access and shared memory. It also mounts a local data directory into the container for persistent data storage. ```bash docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmpose/data mmpose ```