### Setup mmdeploy SDK for ONNX Inference Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/rtmpose/README.md Download and set up the mmdeploy SDK for ONNX inference on Linux. This involves downloading pre-compiled files, initializing the environment, and optionally installing OpenCV. ```shell # Download pre-compiled files wget https://github.com/open-mmlab/mmdeploy/releases/download/v1.0.0/mmdeploy-1.0.0-linux-x86_64-cxx11abi.tar.gz # Unzip files tar -xzvf mmdeploy-1.0.0-linux-x86_64-cxx11abi.tar.gz # Go to the sdk folder cd mmdeploy-1.0.0-linux-x86_64-cxx11abi # Init environment source set_env.sh # If opencv 3+ is not installed on your system, execute the following command. # If it is installed, skip this command bash install_opencv.sh # Compile executable programs bash build_sdk.sh ``` -------------------------------- ### Install xtcocotools from Source (Alternative) Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/faq.md If you encounter 'No matching distribution found for xtcocotools>=1.6', first install cython, then attempt installation from source. Ensure you have git installed. ```bash pip install cython ``` ```bash git clone https://github.com/jin-s13/xtcocoapi cd xtcocoapi python setup.py install ``` -------------------------------- ### Install xtcocotools from Source Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/faq.md If `pip install xtcocotools` fails, try cloning the repository and installing from source. Ensure you have git installed. ```bash git clone https://github.com/jin-s13/xtcocoapi cd xtcocoapi python setup.py install ``` -------------------------------- ### Example: AMP Training Command Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/user_guides/train_and_test.md A concrete example of a training command with AMP enabled, specifying a configuration file. ```shell python tools/train.py configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_res50_8xb64-210e_coco-256x192.py --amp ``` -------------------------------- ### Install ONNXRuntime (CPU) Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/rtmpose/examples/onnxruntime/README_CN.md Install the CPU version of ONNXRuntime by downloading and extracting the binary. Set environment variables for the runtime directory and library path. ```bash wget https://github.com/microsoft/onnxruntime/releases/download/v1.8.1/onnxruntime-linux-x64-1.8.1.tgz tar -zxvf onnxruntime-linux-x64-1.8.1.tgz export ONNXRUNTIME_DIR=$(pwd)/onnxruntime-linux-x64-1.8.1 export LD_LIBRARY_PATH=$ONNXRUNTIME_DIR/lib:$LD_LIBRARY_PATH ``` -------------------------------- ### Install TensorBoard Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/user_guides/train_and_test.md Install the TensorBoard library using pip. This is a prerequisite for using TensorBoard visualization. ```shell pip install tensorboard ``` -------------------------------- ### C++ SDK API Example Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/rtmpose/README.md A basic example demonstrating how to use the MMDeploy SDK's C++ API for pose detection. ```C++ #include "mmdeploy/detector.hpp" #include "opencv2/imgcodecs/imgcodecs.hpp" #include "utils/argparse.h" #include "utils/visualize.h" DEFINE_ARG_string(model, "Model path"); DEFINE_ARG_string(image, "Input image path"); DEFINE_STRING(device, "cpu", R"(Device name, e.g. "cpu", "cuda")"); DEFINE_STRING(output, "detector_output.jpg", "Output image path"); DEFINE_double(det_thr, .5, "Detection score threshold"); int main(int argc, char* argv[]) { if (!utils::ParseArguments(argc, argv)) { return -1; } cv::Mat img = cv::imread(ARGS_image); if (img.empty()) { fprintf(stderr, "failed to load image: %s\n", ARGS_image.c_str()); return -1; } // construct a detector instance mmdeploy::Detector detector(mmdeploy::Model{ARGS_model}, mmdeploy::Device{FLAGS_device}); // apply the detector, the result is an array-like class holding references to // `mmdeploy_detection_t`, will be released automatically on destruction mmdeploy::Detector::Result dets = detector.Apply(img); // visualize utils::Visualize v; auto sess = v.get_session(img); int count = 0; for (const mmdeploy_detection_t& det : dets) { if (det.score > FLAGS_det_thr) { // filter bboxes sess.add_det(det.bbox, det.label_id, det.score, det.mask, count++); } } if (!FLAGS_output.empty()) { cv::imwrite(FLAGS_output, sess.get()); } return 0; } ``` -------------------------------- ### Install MMPose and Dependencies Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/mmpose4aigc/README.md Installs MMPose, MMDetection, and downloads necessary models. Ensure you have GCC and cmake installed. ```shell pip install openmim git clone https://github.com/open-mmlab/mmpose.git cd mmpose mim install -e . mim install "mmdet>=3.0.0rc6" bash download_models.sh ``` -------------------------------- ### Install mim tool Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/rtmpose/examples/onnxruntime/README_CN.md Install the 'mim' tool, which is used for downloading models. ```bash pip install -U openmim ``` -------------------------------- ### Install MMPreTrain Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/configs/body_2d_keypoint/topdown_heatmap/coco/vitpose_coco.md Install the required version of MMPreTrain using mim. This is a prerequisite for using ViTPose. ```shell mim install 'mmpretrain>=1.0.0' ``` -------------------------------- ### Install TensorFlow Source: https://github.com/idea-research/dwpose/blob/onnx/ControlNet-v1-1-nightly/annotator/zoe/zoedepth/models/base_models/midas_repo/mobile/ios/README.md Install the TensorFlow library using pip. Ensure Python 3 is set as the default. ```shell pip install tensorflow ``` -------------------------------- ### Example Inference with YOLOX-Pose Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/yolox_pose/README.md An example command to run inference on a specific image using a YOLOX-Pose configuration and checkpoint, saving visualization results. ```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 ``` -------------------------------- ### Install OpenVINO for OpenVINO Model Source: https://github.com/idea-research/dwpose/blob/onnx/ControlNet-v1-1-nightly/annotator/zoe/zoedepth/models/base_models/midas_repo/README.md Install the OpenVINO library using pip. This is required if you plan to use the OpenVINO model for inference on Intel CPUs. ```shell pip install openvino ``` -------------------------------- ### Install MMPose Dependencies via MIM Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/MMPose_Tutorial.ipynb Installs MMEngine, MMCV, and MMDetection using the MIM package manager. This ensures compatibility and proper setup of core components. ```python # install MMEngine, MMCV and MMDetection using MIM %pip install -U openmim !mim install mmengine !mim install "mmcv>=2.0.0" !mim install "mmdet>=3.0.0" ``` -------------------------------- ### General Configuration Example Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/user_guides/configs.md This snippet shows the default general configurations including hooks, environment settings, visualizer, and logging. ```Python # General default_scope = 'mmpose' default_hooks = dict( timer=dict(type='IterTimerHook'), # time the data processing and model inference logger=dict(type='LoggerHook', interval=50), # interval to print logs param_scheduler=dict(type='ParamSchedulerHook'), # update lr checkpoint=dict( type='CheckpointHook', interval=1, save_best='coco/AP', # interval to save ckpt rule='greater'), # rule to judge the metric sampler_seed=dict(type='DistSamplerSeedHook')) # set the distributed seed env_cfg = dict( cudnn_benchmark=False, # cudnn benchmark flag mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0), # num of opencv threads dist_cfg=dict(backend='nccl')) # distributed training backend vis_backends = [dict(type='LocalVisBackend')] # visualizer backend visualizer = dict( # Config of visualizer type='PoseLocalVisualizer', vis_backends=[dict(type='LocalVisBackend')], name='visualizer') log_processor = dict( # Format, interval to log type='LogProcessor', window_size=50, by_epoch=True, num_digits=6) log_level = 'INFO' # The level of logging ``` -------------------------------- ### Training Configuration Example Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/user_guides/configs.md Sets parameters for resuming training, loading pre-trained weights, defining training epochs and validation intervals, and configuring learning rate schedules and optimizers. ```Python resume = False # resume checkpoints from a given path, the training will be resumed from the epoch when the checkpoint's is saved load_from = None # load models as a pre-trained model from a given path train_cfg = dict(by_epoch=True, max_epochs=210, val_interval=10) # max epochs of training, interval to validate param_scheduler = [ dict( # warmup strategy type='LinearLR', begin=0, end=500, start_factor=0.001, by_epoch=False), dict( # scheduler type='MultiStepLR', begin=0, end=210, milestones=[170, 200], gamma=0.1, by_epoch=True) ] optim_wrapper = dict(optimizer=dict(type='Adam', lr=0.0005)) # optimizer and initial lr auto_scale_lr = dict(base_batch_size=512) # auto scale the lr according to batch size ``` -------------------------------- ### Setup mmdeploy SDK for TensorRT Inference Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/rtmpose/README.md Download and set up the mmdeploy SDK for TensorRT inference on Linux with CUDA support. This involves downloading pre-compiled files, initializing the environment, and optionally installing OpenCV. ```shell # Download pre-compiled files wget https://github.com/open-mmlab/mmdeploy/releases/download/v1.0.0/mmdeploy-1.0.0-linux-x86_64-cxx11abi-cuda11.3.tar.gz # Unzip files tar -xzvf mmdeploy-1.0.0-linux-x86_64-cxx11abi-cuda11.3.tar.gz # Go to the sdk folder cd mmdeploy-1.0.0-linux-x86_64-cxx11abi-cuda11.3 # Init environment source set_env.sh # If opencv 3+ is not installed on your system, execute the following command. # If it is installed, skip this command bash install_opencv.sh # Compile executable programs bash build_sdk.sh ``` -------------------------------- ### Launch TensorBoard Visualization Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/user_guides/train_and_test.md Start the TensorBoard server to visualize training data. The log directory should point to the experiment's visualization data. ```shell tensorboard --logdir ${WORK_DIR}/${TIMESTAMP}/vis_data ``` -------------------------------- ### Create a config file Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/MMPose_Tutorial.ipynb This section shows an example of a configuration file used in MMPose. It details the structure and parameters for setting up a pose estimation model. ```yaml model = type='TopdownPoseEstimator' data_preprocessor=dict(type='PoseDataPreprocessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375]) backbone=dict(type='HRNet', in_channels=3, extra=dict(final_conv_kernel=1, with_norm_tree=True, num_branches=4, multiscale_mode='dfrac', module_name='modules.HRModule'), enc_modules=dict(modules=[dict(type='SpatialFusionModule', in_channels=32, num_modules=1, fuse_channels=32), dict(type='SpatialFusionModule', in_channels=64, num_modules=1, fuse_channels=64), dict(type='SpatialFusionModule', in_channels=128, num_modules=1, fuse_channels=128)], freeze_modules='all'), init_cfg=dict(type='Pretrained', checkpoint='https://download.openmmlab.com/mmpose/v1/models/hrnet/hrnet_w32-35412687_20220915.pth')) head=dict(type='TopdownHeatmapHead', num_classes=17, in_channels=32, loss=dict(type='KeypointLoss', name_value=0.5, use_target_weight=True), endpoint_decoder=dict(type='TopdownHeatmap', in_channels=32, out_channels=17), decoder=dict(type='TopdownHeatmapDecoder', num_classes=17, threshold=0.5, num_parts=17, topk=100), train_cfg=dict(num_epochs=210, lr_factor=0.1, warm_up_epochs=5), test_cfg=dict(flip_test=True, flip_mode='regress')) dataset_type='CocoDataset' log_level='INFO' load_from='https://download.openmmlab.com/mmpose/v1/models/hrnet/hrnet_w32-35412687_20220915.pth' resume=False # dataset settings backend_args=dict(backend='local') train_dataloader=dict(batch_size=64, num_workers=10, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), dataset=dict(type='CocoDataset', data_root='/home/PJLAB/jiangtao/Documents/git-clone/mmpose/data/coco/', data_prefix=dict(img='train2017/'), ann_file='annotations/person_keypoints_train2017.json', data_cfg=dict(type='bottomup', num_joints=17, dataset_class_name='coco', joint_pairs=[[1, 2], [2, 3], [3, 4], [1, 5], [5, 6], [6, 7], [1, 8], [8, 9], [9, 10], [1, 11], [11, 12], [12, 13], [1, 0], [0, 14], [14, 16], [0, 15], [15, 17]]), pipeline=[dict(type='LoadImage'), dict(type='LoadAnnotations', with_bbox=True, with_keypoints=True), dict(type='RandomHorizontalFlip', prob=0.5), dict(type='RandomFlip', direction='vertical', prob=0.5), dict(type='RandomScale', scale_factor=(-0.3, 0.3)), dict(type='RandomResolution', aspect_ratio_range=[0.75, 1.3333333333333333], scale_range=[0.5, 1.5]), dict(type='RandomCrop', crop_size=[256, 192], allow_negative_crop=True), dict(type='CropIndividualInstances', scale=3.0, allow_negative_crop=True), dict(type='PhotoMetricDistortion', contrast_prob=0.2, brightness_prob=0.2, saturation_prob=0.2, hue_prob=0.2), dict(type='GenerateKeypointTarget', sigma=3), dict(type='PackPoseInputs')])) val_dataloader=dict(batch_size=1, num_workers=10, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict(type='CocoDataset', data_root='/home/PJLAB/jiangtao/Documents/git-clone/mmpose/data/coco/', data_prefix=dict(img='val2017/'), ann_file='annotations/person_keypoints_val2017.json', data_cfg=dict(type='bottomup', num_joints=17, dataset_class_name='coco', joint_pairs=[[1, 2], [2, 3], [3, 4], [1, 5], [5, 6], [6, 7], [1, 8], [8, 9], [9, 10], [1, 11], [11, 12], [12, 13], [1, 0], [0, 14], [14, 16], [0, 15], [15, 17]]), pipeline=[dict(type='LoadImage'), dict(type='LoadAnnotations', with_bbox=True, with_keypoints=True), dict(type='PackPoseInputs')])) test_dataloader=dict(batch_size=1, num_workers=10, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict(type='CocoDataset', data_root='/home/PJLAB/jiangtao/Documents/git-clone/mmpose/data/coco/', data_prefix=dict(img='val2017/'), ann_file='annotations/person_keypoints_val2017.json', data_cfg=dict(type='bottomup', num_joints=17, dataset_class_name='coco', joint_pairs=[[1, 2], [2, 3], [3, 4], [1, 5], [5, 6], [6, 7], [1, 8], [8, 9], [9, 10], [1, 11], [11, 12], [12, 13], [1, 0], [0, 14], [14, 16], [0, 15], [15, 17]]), pipeline=[dict(type='LoadImage'), dict(type='LoadAnnotations', with_bbox=True, with_keypoints=True), dict(type='PackPoseInputs')])) # runtime settings vis_backends=[dict(type='LocalVisBackend')], visualizer=dict(type='PoseLocalVisualizer', vis_backends=[dict(type='LocalVisBackend')], name='visualizer'), log_processor=dict(type='LogProcessor', window_size=50, by_epoch=True), log_handler=dict(type='FileHandler', init_kwargs=dict(filename='train.log')), # training settings train_cfg=dict(by_epoch=True, max_epochs=210, val_interval=10), val_cfg=dict(), test_cfg=dict()) ``` -------------------------------- ### Verify MMPose Installation Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/installation.md Check the installed MMPose version after installation. ```python import mmpose print(mmpose.__version__) ``` -------------------------------- ### Example: Run 2D Pose Estimation with MMDetection on Video Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/docs/en/2d_wholebody_pose_demo.md This command demonstrates running the 2D pose estimation demo with MMDetection on a video file. It uses a remote video URL as input and specifies output directory and display options. ```shell python demo/topdown_demo_with_mmdet.py \ demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py \ https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ configs/wholebody_2d_keypoint/topdown_heatmap/coco-wholebody/td-hm_hrnet-w48_dark-8xb32-210e_coco-wholebody-384x288.py \ https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth \ --input https://user-images.githubusercontent.com/87690686/137440639-fb08603d-9a35-474e-b65f-46b5c06b68d6.mp4 \ --output-root vis_results/ --show ``` -------------------------------- ### Full Configuration Example with Codec Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/advanced_guides/codecs.md A comprehensive configuration file snippet demonstrating the definition of a codec and its subsequent use in both the pipeline's GenerateTarget module and the model's head as a decoder. ```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') ] ``` -------------------------------- ### Install Tree Package Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/MMPose_Tutorial.ipynb This command installs the 'tree' package, which is useful for visualizing directory structures. It shows the output of the installation process. ```bash Reading package lists... Building dependency tree... Reading state information... The following package was automatically installed and is no longer required: libnvidia-common-460 Use 'apt autoremove' to remove it. The following NEW packages will be installed: tree 0 upgraded, 1 newly installed, 0 to remove and 32 not upgraded. Need to get 40.7 kB of archives. After this operation, 105 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 tree amd64 1.7.0-5 [40.7 kB] Fetched 40.7 kB in 0s (161 kB/s) Selecting previously unselected package tree. (Reading database ... 155685 files and directories currently installed.) Preparing to unpack .../tree_1.7.0-5_amd64.deb ... Unpacking tree (1.7.0-5) ... Setting up tree (1.7.0-5) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... data/coco_tiny ├── images │   ├── 000000012754.jpg │   ├── 000000017741.jpg │   ├── 000000019157.jpg │   ├── 000000019523.jpg │   ├── 000000019608.jpg │   ├── 000000022816.jpg │   ├── 000000031092.jpg │   ├── 000000032124.jpg │   ├── 000000037209.jpg │   ├── 000000050713.jpg │   ├── 000000057703.jpg │   ├── 000000064909.jpg │   ├── 000000076942.jpg │   ├── 000000079754.jpg │   ├── 000000083935.jpg │   ├── 000000085316.jpg │   ├── 000000101013.jpg │   ├── 000000101172.jpg │   ├── 000000103134.jpg │   ├── 000000103163.jpg │   ├── 000000105647.jpg │   ├── 000000107960.jpg │   ├── 000000117891.jpg │   ├── 000000118181.jpg │   ├── 000000120021.jpg │   ├── 000000128119.jpg │   ├── 000000143908.jpg │   ├── 000000145025.jpg │   ├── 000000147386.jpg │   ├── 000000147979.jpg │   ├── 000000154222.jpg │   ├── 000000160190.jpg │   ├── 000000161112.jpg │   ├── 000000175737.jpg │   ├── 000000177069.jpg │   ├── 000000184659.jpg │   ├── 000000209468.jpg │   ├── 000000210060.jpg │   ├── 000000215867.jpg │   ├── 000000216861.jpg │   ├── 000000227224.jpg │   ├── 000000246265.jpg │   ├── 000000254919.jpg │   ├── 000000263687.jpg │   ├── 000000264628.jpg │   ├── 000000268927.jpg │   ├── 000000271177.jpg │   ├── 000000275219.jpg │   ├── 000000277542.jpg │   ├── 000000279140.jpg │   ├── 000000286813.jpg │   ├── 000000297980.jpg │   ├── 000000301641.jpg │   ├── 000000312341.jpg │   ├── 000000325768.jpg │   ├── 000000332221.jpg │   ├── 000000345071.jpg │   ├── 000000346965.jpg │   ├── 000000347836.jpg │   ├── 000000349437.jpg │   ├── 000000360735.jpg │   ├── 000000362343.jpg │   ├── 000000364079.jpg │   ├── 000000364113.jpg │   ├── 000000386279.jpg │   ├── 000000386968.jpg │   ├── 000000388619.jpg │   ├── 000000390137.jpg │   ├── 000000390241.jpg │   ├── 000000390298.jpg │   ├── 000000390348.jpg │   ├── 000000398606.jpg │   ├── 000000400456.jpg │   ├── 000000402514.jpg │   ├── 000000403255.jpg │   ├── 000000403432.jpg │   ├── 000000410350.jpg │   ├── 000000453065.jpg │   ├── 000000457254.jpg │   ├── 000000464153.jpg │   ├── 000000464515.jpg │   ├── 000000465418.jpg │   ├── 000000480591.jpg │   ├── 000000484279.jpg │   ├── 000000494014.jpg │   ├── 000000515289.jpg │   ├── 000000516805.jpg │   ├── 000000521994.jpg │   ├── 000000528962.jpg │   ├── 000000534736.jpg │   ├── 000000535588.jpg │   ├── 000000537548.jpg │   ├── 000000553698.jpg │   ├── 000000555622.jpg │   ├── 000000566456.jpg │   ├── 000000567171.jpg │   └── 000000568961.jpg train.json └── val.json 1 directory, 99 files ``` -------------------------------- ### CheckpointHook Configuration Example Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/user_guides/configs.md Demonstrates how to configure CheckpointHook with specific save_best metric, rule, and max_keep_ckpts. ```Python default_hooks = dict(checkpoint=dict(save_best='PCK', rule='greater', max_keep_ckpts=1)) ``` -------------------------------- ### Install MMPose as a Python Package Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/installation.md Install MMPose using pip for use as a dependency or third-party package. Ensure you have mim installed. ```shell mim install "mmpose>=1.1.0" ``` -------------------------------- ### Data Configuration Example Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/user_guides/configs.md Defines data storage backend, dataset type, data root, codec for target generation, and training/testing pipelines. Includes dataloader configurations for training and validation. ```Python backend_args = dict(backend='local') # data storage backend dataset_type = 'CocoDataset' # name of dataset data_mode = 'topdown' # type of the model data_root = 'data/coco/' # root of the dataset # config of codec,to generate targets and decode preds into coordinates codec = dict( type='MSRAHeatmap', input_size=(192, 256), heatmap_size=(48, 64), sigma=2) train_pipeline = [ # data aug in training dict(type='LoadImage', backend_args=backend_args), # image loading dict(type='GetBBoxCenterScale'), # calculate center and scale of bbox dict(type='RandomBBoxTransform'), # config of scaling, rotation and shifing dict(type='RandomFlip', direction='horizontal'), # config of random flipping dict(type='RandomHalfBody'), # config of half-body aug dict(type='TopdownAffine', input_size=codec['input_size']), # update inputs via transform matrix dict( type='GenerateTarget', # generate targets via transformed inputs # typeof targets encoder=codec, # get encoder from codec dict(type='PackPoseInputs') # pack targets ] test_pipeline = [ # data aug in testing dict(type='LoadImage', backend_args=backend_args), # image loading dict(type='GetBBoxCenterScale'), # calculate center and scale of bbox dict(type='TopdownAffine', input_size=codec['input_size']), # update inputs via transform matrix dict(type='PackPoseInputs') # pack targets ] train_dataloader = dict( batch_size=64, # batch size of each single GPU during training num_workers=2, # workers to pre-fetch data for each single GPU persistent_workers=True, # workers will stay around (with their state) waiting for another call into that dataloader. sampler=dict(type='DefaultSampler', shuffle=True), # data sampler, shuffle in traning dataset=dict( type=dataset_type , # name of dataset data_root=data_root, # root of dataset data_mode=data_mode, # type of the model ann_file='annotations/person_keypoints_train2017.json', # path to annotation file data_prefix=dict(img='train2017/'), # path to images pipeline=train_pipeline )) val_dataloader = dict( batch_size=32, # batch size of each single GPU during validation num_workers=2, # workers to pre-fetch data for each single GPU persistent_workers=True, # workers will stay around (with their state) waiting for another call into that dataloader. drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False), # data sampler dataset=dict( type=dataset_type , # name of dataset data_root=data_root, # root of dataset data_mode=data_mode, # type of the model ann_file='annotations/person_keypoints_val2017.json', # path to annotation file bbox_file= 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json', # bbox file use for evaluation data_prefix=dict(img='val2017/'), # path to images test_mode=True, pipeline=test_pipeline )) test_dataloader = val_dataloader # use val as test by default ``` -------------------------------- ### Install MMPose Dependencies with MIM Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/installation.md Install MMEngine, MMCV, and optionally MMDetection using the MIM package manager. Ensure MIM is installed or updated first. ```shell pip install -U openmim ``` ```shell mim install mmengine ``` ```shell mim install "mmcv>=2.0.1" ``` ```shell mim install "mmdet>=3.1.0" ``` -------------------------------- ### Install PyTorch on GPU Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/installation.md Install PyTorch and torchvision using conda. This command automatically installs the latest compatible PyTorch and cudatoolkit versions. Verify compatibility with your environment. ```shell conda install pytorch torchvision -c pytorch ``` -------------------------------- ### Example: Run 2D Pose Estimation with MMDetection on Image Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/docs/en/2d_wholebody_pose_demo.md An example command for running the 2D pose estimation demo with MMDetection on a specific image. It includes paths to MMDetection and MMPose configurations and checkpoints, input image, and output root. ```shell python demo/topdown_demo_with_mmdet.py \ demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py \ https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ configs/wholebody_2d_keypoint/topdown_heatmap/coco-wholebody/td-hm_hrnet-w48_dark-8xb32-210e_coco-wholebody-384x288.py \ https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth \ --input tests/data/coco/000000196141.jpg \ --output-root vis_results/ --show ``` -------------------------------- ### Clone MMPose and Install Dependencies Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/MMPose_Tutorial.ipynb This snippet clones the MMPose repository, navigates into the directory, and installs all required packages listed in requirements.txt. It then installs MMPose in editable mode for local development. ```python !git clone https://github.com/open-mmlab/mmpose.git # The master branch is version 1.x %cd mmpose %pip install -r requirements.txt %pip install -v -e . # "-v" means verbose, or more output # "-e" means installing a project in editable mode, # thus any local modifications made to the code will take effect without reinstallation. ``` -------------------------------- ### Install Requirements Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/rtmpose/examples/onnxruntime/README_CN.md Install the necessary Python dependencies for running the inference script. ```bash pip install -r requirements.txt ``` -------------------------------- ### Download Config and Checkpoint Files Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/installation.md Download necessary configuration and checkpoint files for running inference demos. Specify the model config and destination folder. ```shell mim download mmpose --config td-hm_hrnet-w48_8xb32-210e_coco-256x192 --dest . ``` -------------------------------- ### Print Configuration Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/user_guides/configs.md Use this command to inspect the complete configuration of a given config file. ```Bash python tools/analysis/print_config.py /PATH/TO/CONFIG ``` -------------------------------- ### Install PyTorch on CPU Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/installation.md Install PyTorch and torchvision for CPU-only platforms using conda. ```shell conda install pytorch torchvision cpuonly -c pytorch ``` -------------------------------- ### Example: 2D Human Pose Top-Down Demo with MMDetection Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/demos.md Example execution of the top-down demo using MMDetection for detection and MMpose for pose estimation on an image. Includes visualization. ```shell python demo/topdown_demo_with_mmdet.py \ demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py \ https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \ configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192.py \ https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w32_coco_256x192-c78dce93_20200708.pth \ --input tests/data/coco/000000197388.jpg --show --draw-heatmap \ --output-root vis_results/ ``` -------------------------------- ### Install MMEngine with Pip Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/docs/en/installation.md Use this command to install MMEngine using pip when not using MIM. ```shell pip install mmengine ``` -------------------------------- ### Run 2D Face Image Demo with Specific Models Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/docs/en/2d_face_demo.md Run the demo with specific pre-trained models for face detection (YOLOX-S) and face keypoint estimation (HRNetV2-W18). This example visualizes keypoints and heatmaps for a given image. ```shell python demo/topdown_demo_with_mmdet.py \ demo/mmdetection_cfg/yolox-s_8xb8-300e_coco-face.py \ https://download.openmmlab.com/mmpose/mmdet_pretrained/yolo-x_8xb8-300e_coco-face_13274d7c.pth \ configs/face_2d_keypoint/topdown_heatmap/aflw/td-hm_hrnetv2-w18_8xb64-60e_aflw-256x256.py \ https://download.openmmlab.com/mmpose/face/hrnetv2/hrnetv2_w18_aflw_256x256-f2bbc62b_20210125.pth \ --input tests/data/cofw/001766.jpg \ --show --draw-heatmap ``` -------------------------------- ### C++ SDK API Example Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/projects/rtmpose/README.md This C++ code snippet shows how to initialize and use the MMDeploy Detector for inference. It includes argument parsing for model and image paths, device selection, and visualization of detection results. ```cpp #include "mmdeploy/detector.hpp" #include "opencv2/imgcodecs/imgcodecs.hpp" #include "utils/argparse.h" #include "utils/visualize.h" DEFINE_ARG_string(model, "Model path"); DEFINE_ARG_string(image, "Input image path"); DEFINE_string(device, "cpu", R"(Device name, e.g. "cpu", "cuda")"); DEFINE_string(output, "detector_output.jpg", "Output image path"); DEFINE_double(det_thr, .5, "Detection score threshold"); int main(int argc, char* argv[]) { if (!utils::ParseArguments(argc, argv)) { return -1; } cv::Mat img = cv::imread(ARGS_image); if (img.empty()) { fprintf(stderr, "failed to load image: %s\n", ARGS_image.c_str()); return -1; } // construct a detector instance mmdeploy::Detector detector(mmdeploy::Model{ARGS_model}, mmdeploy::Device{FLAGS_device}); // apply the detector, the result is an array-like class holding references to // `mmdeploy_detection_t`, will be released automatically on destruction mmdeploy::Detector::Result dets = detector.Apply(img); // visualize utils::Visualize v; auto sess = v.get_session(img); int count = 0; for (const mmdeploy_detection_t& det : dets) { if (det.score > FLAGS_det_thr) { // filter bboxes sess.add_det(det.bbox, det.label_id, det.score, det.mask, count++); } } if (!FLAGS_output.empty()) { cv::imwrite(FLAGS_output, sess.get()); } return 0; } ``` -------------------------------- ### Run 2D Animal Pose Demo on CPU Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/docs/en/2d_animal_demo.md This command demonstrates how to run the 2D animal pose estimation demo using the CPU instead of a GPU. Append the `--device cpu` argument to the standard command. ```shell python demo/topdown_demo_with_mmdet.py \ demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py \ https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.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 --device cpu ``` -------------------------------- ### Install Python Scripts Source: https://github.com/idea-research/dwpose/blob/onnx/ControlNet-v1-1-nightly/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt Installs Python scripts to the specified destination within the ROS package. ```cmake catkin_install_python(PROGRAMS scripts/my_python_script DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) ``` -------------------------------- ### Install MMPose Dependencies Source: https://github.com/idea-research/dwpose/blob/onnx/INSTALL.md Installs PyTorch with specific CUDA version and other requirements for the MMPose environment. ```bash pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html pip install -r requirements.txt ``` -------------------------------- ### Run 2D Face Demo on CPU Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/docs/en/2d_face_demo.md Execute the demo script using the CPU for processing. Set the `--device` argument to 'cpu'. This is useful when a GPU is not available. ```shell python demo/topdown_demo_with_mmdet.py \ demo/mmdetection_cfg/yolox-s_8xb8-300e_coco-face.py \ https://download.openmmlab.com/mmpose/mmdet_pretrained/yolo-x_8xb8-300e_coco-face_13274d7c.pth \ configs/face_2d_keypoint/topdown_heatmap/aflw/td-hm_hrnetv2-w18_8xb64-60e_aflw-256x256.py \ https://download.openmmlab.com/mmpose/face/hrnetv2/hrnetv2_w18_aflw_256x256-f2bbc62b_20210125.pth \ --input tests/data/cofw/001766.jpg \ --show --draw-heatmap --device=cpu ``` -------------------------------- ### MMPose Configuration Example Source: https://github.com/idea-research/dwpose/blob/onnx/mmpose/demo/MMPose_Tutorial.ipynb This snippet shows a configuration for a pose estimation model, including dataset and pipeline settings. It is used to define the model architecture, data loading, and evaluation metrics. ```python input_size=(192, 256), heatmap_size=(48, 64), sigma=2)), dict(type='PackPoseInputs') ])) val_dataloader = dict( batch_size=16, num_workers=2, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False, round_up=False), dataset=dict( type='TinyCocoDataset', data_root='data/coco_tiny', data_mode='topdown', ann_file='val.json', bbox_file=None, data_prefix=dict(img='images/'), test_mode=True, pipeline=[ dict(type='LoadImage', file_client_args=dict(backend='disk')), dict(type='GetBBoxCenterScale'), dict(type='TopdownAffine', input_size=(192, 256)), dict(type='PackPoseInputs') ])) test_dataloader = dict( batch_size=16, num_workers=2, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False, round_up=False), dataset=dict( type='TinyCocoDataset', data_root='data/coco_tiny', data_mode='topdown', ann_file='val.json', bbox_file=None, data_prefix=dict(img='images/'), test_mode=True, pipeline=[ dict(type='LoadImage', file_client_args=dict(backend='disk')), dict(type='GetBBoxCenterScale'), dict(type='TopdownAffine', input_size=(192, 256)), dict(type='PackPoseInputs') ])) val_evaluator = dict(type='PCKAccuracy') test_evaluator = dict(type='PCKAccuracy') work_dir = 'work_dirs/hrnet_w32_coco_tiny_256x192' randomness = dict(seed=0) ``` -------------------------------- ### Install Other Files Source: https://github.com/idea-research/dwpose/blob/onnx/ControlNet-v1-1-nightly/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt Installs miscellaneous files, such as launch or bag files, to the package's share destination. ```cmake install(FILES # myfile1 # myfile2 DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) ``` -------------------------------- ### Install Executable Target Source: https://github.com/idea-research/dwpose/blob/onnx/ControlNet-v1-1-nightly/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt Installs a specific executable target to the ROS package's binary destination. ```cmake install(TARGETS ${PROJECT_NAME}_node RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) ```