mmpose icon indicating copy to clipboard operation
mmpose copied to clipboard

[Bug] Why inference_demo.py ,num_instances can only be set to 0/1,Otherwise, a ValueError error is reported.

Open QKLXG opened this issue 11 months ago • 4 comments
trafficstars

Prerequisite

  • [X] I have searched Issues and Discussions but cannot get the expected help.
  • [X] The bug has not been fixed in the latest version(https://github.com/open-mmlab/mmpose).

Environment

OrderedDict([('sys.platform', 'win32'), ('Python', '3.8.19 (default, Mar 20 2024, 19:55:45) [MSC v.1916 64 bit (AMD64)]'), ('CUDA available', True), ('MUSA available', False), ('n umpy_random_seed', 2147483648), ('GPU 0', 'NVIDIA GeForce RTX 4060 Laptop GPU'), ('CUDA_HOME', None), ('GCC', 'n/a'), ('PyTorch', '1.13.1'), ('PyTorch compiling details', 'PyTorch built with:\n - C++ Version: 199711\n - MSVC 192829337\n - Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications\n - Intel(R) MKL-DNN v2.6.0 (Git Hash 52b5f107dd9cf10910aaa19cb47f3abf9b349815)\n - OpenMP 2019\n - LAPACK is enabled (usually provided by MKL)\n - CPU capability usage: AVX2\n - CUDA Runtime 11.7\n - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_6 1,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_ 37,code=compute_37\n - CuDNN 8.5\n - Magma 2.5.4\n - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=C:/cb/pytorch_10000 00000000/work/tmp_bin/sccache-cl.exe, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -DUSE_PTHREADPOOL -openmp:experimental -IC:/cb/pytorch_1000000000000/work/mkl/include -DNDE BUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DUSE_FBGEMM -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, P ERF_WITH_AVX512=1, TORCH_VERSION=1.13.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=OFF, USE_OPENMP=ON, USE_ROCM=OFF, \n'), ('TorchVision', '0.14.1'), ('OpenCV', '4.9.0'), ('MMEngine', '0.10.3'), ('MMPose', '1.3.1+unknown')]) Package Version


addict 2.4.0 aliyun-python-sdk-core 2.15.0 aliyun-python-sdk-kms 2.16.2 Brotli 1.0.9 certifi 2024.2.2 cffi 1.16.0 charset-normalizer 2.0.4 chumpy 0.70 click 8.1.7 colorama 0.4.6 contourpy 1.1.1 coverage 7.2.2 crcmod 1.7 cryptography 42.0.5 cycler 0.12.1 Cython 3.0.9 debugpy 1.8.1 einops 0.8.0 exceptiongroup 1.2.0 flake8 7.0.0 fonttools 4.50.0 h5py 3.11.0 idna 3.4 importlib_metadata 7.1.0 importlib_resources 6.4.0 iniconfig 1.1.1 isort 4.3.21 jmespath 0.10.0 joblib 1.4.2 json-tricks 3.17.3 kiwisolver 1.4.5 Markdown 3.6 markdown-it-py 3.0.0 mat4py 0.6.0 matplotlib 3.7.5 mccabe 0.7.0 mdurl 0.1.2 mkl-fft 1.3.8 mkl-random 1.2.4 mkl-service 2.4.0 mmcv 2.1.0 mmdet 3.3.0 mmengine 0.10.3 mmpose 1.3.1 mmpretrain 1.2.0 model-index 0.1.11 modelindex 0.0.2 munkres 1.1.4 numpy 1.24.3 opencv-python 4.9.0.80 opendatalab 0.0.10 openmim 0.3.9 openxlab 0.0.37 ordered-set 4.1.0 oss2 2.17.0 packaging 23.2 pandas 2.0.3 parameterized 0.8.1 pillow 10.2.0 pip 23.3.1 platformdirs 4.2.0 pluggy 1.0.0 pycocotools 2.0.7 pycodestyle 2.11.1 pycparser 2.21 pycryptodome 3.20.0 pyflakes 3.2.0 Pygments 2.17.2 pyparsing 3.1.2 PySocks 1.7.1 pytest 7.4.0 pytest-runner 6.0.0 python-dateutil 2.9.0.post0 pytz 2023.4 pywin32 306 PyYAML 6.0.1 regex 2023.12.25 requests 2.28.2 rich 13.4.2 scikit-learn 1.3.2 scipy 1.10.1 setuptools 60.2.0 shapely 2.0.3 six 1.16.0 spacepy 0.6.0 tabulate 0.9.0 termcolor 2.4.0 terminaltables 3.1.10 threadpoolctl 3.5.0 tomli 2.0.1 torch 1.13.1 torchaudio 0.13.1 torchvision 0.14.1 tqdm 4.65.2 typing_extensions 4.9.0 tzdata 2024.1 urllib3 1.26.18 wheel 0.41.2 win-inet-pton 1.1.0 xtcocotools 1.14.3 yapf 0.40.2 zipp 3.18.1

Reproduces the problem - code sample

Copyright (c) OpenMMLab. All rights reserved.

from argparse import ArgumentParser from typing import Dict

from mmpose.apis.inferencers import MMPoseInferencer, get_model_aliases

filter_args = dict(bbox_thr=0.3, nms_thr=0.3, pose_based_nms=False) POSE2D_SPECIFIC_ARGS = dict( yoloxpose=dict(bbox_thr=0.01, nms_thr=0.65, pose_based_nms=True), rtmo=dict(bbox_thr=0.1, nms_thr=0.65, pose_based_nms=True), )

def parse_args(): parser = ArgumentParser() parser.add_argument( '--inputs', type=str, default='D:\githubProgram\mmpose-main\tests\data\crowdpose\100033.jpg', nargs='?', help='Input image/video path or folder path.')

# init args
parser.add_argument(
    '--pose2d',
    type=str,
    default="D:\\githubProgram\\mmpose-main\\configs\\body_2d_keypoint\\topdown_heatmap\coco\\td-hm_hrformer-base_8xb32-210e_coco-256x192.py",
    help='Pretrained 2D pose estimation algorithm. It\'s the path to the '
    'config file or the model name defined in metafile.')
parser.add_argument(
    '--pose2d-weights',
    type=str,
    default="D:\githubProgram\mmpose-main\hrformer_base_coco_256x192-6f5f1169_20220316.pth",
    help='Path to the custom checkpoint file of the selected pose model. '
    'If it is not specified and "pose2d" is a model name of metafile, '
    'the weights will be loaded from metafile.')
parser.add_argument(
    '--pose3d',
    type=str,
    default='D:\githubProgram\mmpose-main\motionbert_dstformer-ft-243frm_8xb32-120e_h36m.py',
    help='Pretrained 3D pose estimation algorithm. It\'s the path to the '
    'config file or the model name defined in metafile.')
parser.add_argument(
    '--pose3d-weights',
    type=str,
    default='D:\githubProgram\motionbert_ft_h36m-d80af323_20230531.pth',
    help='Path to the custom checkpoint file of the selected pose model. '
    'If it is not specified and "pose3d" is a model name of metafile, '
    'the weights will be loaded from metafile.')
parser.add_argument(
    '--det-model',
    type=str,
    default=None,
    help='Config path or alias of detection model.')
parser.add_argument(
    '--det-weights',
    type=str,
    default=None,
    help='Path to the checkpoints of detection model.')
parser.add_argument(
    '--det-cat-ids',
    type=int,
    nargs='+',
    default=0,
    help='Category id for detection model.')
parser.add_argument(
    '--scope',
    type=str,
    default='mmpose',
    help='Scope where modules are defined.')
parser.add_argument(
    '--device',
    type=str,
    default='cpu',
    help='Device used for inference. '
    'If not specified, the available device will be automatically used.')
parser.add_argument(
    '--show-progress',
    action='store_true',
    help='Display the progress bar during inference.')

# The default arguments for prediction filtering differ for top-down
# and bottom-up models. We assign the default arguments according to the
# selected pose2d model
args, _ = parser.parse_known_args()
for model in POSE2D_SPECIFIC_ARGS:
    if model in args.pose2d:
        filter_args.update(POSE2D_SPECIFIC_ARGS[model])
        break

# call args
parser.add_argument(
    '--show',
    action='store_true',
    help='Display the image/video in a popup window.')
parser.add_argument(
    '--draw-bbox',
    action='store_true',
    default=False,
    help='Whether to draw the bounding boxes.')
parser.add_argument(
    '--draw-heatmap',
    action='store_true',
    default=True,
    help='Whether to draw the predicted heatmaps.')
parser.add_argument(
    '--bbox-thr',
    type=float,
    default=filter_args['bbox_thr'],
    help='Bounding box score threshold')
parser.add_argument(
    '--nms-thr',
    type=float,
    default=filter_args['nms_thr'],
    help='IoU threshold for bounding box NMS')
parser.add_argument(
    '--pose-based-nms',
    type=lambda arg: arg.lower() in ('true', 'yes', 't', 'y', '1'),
    default=filter_args['pose_based_nms'],
    help='Whether to use pose-based NMS')
parser.add_argument(
    '--kpt-thr', type=float, default=0.3, help='Keypoint score threshold')
parser.add_argument(
    '--tracking-thr', type=float, default=0.3, help='Tracking threshold')
parser.add_argument(
    '--use-oks-tracking',
    action='store_true',
    help='Whether to use OKS as similarity in tracking')
parser.add_argument(
    '--disable-norm-pose-2d',
    action='store_true',
    help='Whether to scale the bbox (along with the 2D pose) to the '
    'average bbox scale of the dataset, and move the bbox (along with the '
    '2D pose) to the average bbox center of the dataset. This is useful '
    'when bbox is small, especially in multi-person scenarios.')
parser.add_argument(
    '--disable-rebase-keypoint',
    action='store_true',
    default=False,
    help='Whether to disable rebasing the predicted 3D pose so its '
    'lowest keypoint has a height of 0 (landing on the ground). Rebase '
    'is useful for visualization when the model do not predict the '
    'global position of the 3D pose.')
parser.add_argument(
    '--num-instances',
    type=int,
    default=-1,
    help='The number of 3D poses to be visualized in every frame. If '
    'less than 0, it will be set to the number of pose results in the '
    'first frame.')
parser.add_argument(
    '--radius',
    type=int,
    default=4,
    help='Keypoint radius for visualization.')
parser.add_argument(
    '--thickness',
    type=int,
    default=2,
    help='Link thickness for visualization.')
parser.add_argument(
    '--skeleton-style',
    default='mmpose',
    type=str,
    choices=['mmpose', 'openpose'],
    help='Skeleton style selection')
parser.add_argument(
    '--black-background',
    action='store_true',
    help='Plot predictions on a black image')
parser.add_argument(
    '--vis-out-dir',
    type=str,
    default='D:\\githubProgram\\mmpose-main\\result_img',
    help='Directory for saving visualized results.')
parser.add_argument(
    '--pred-out-dir',
    type=str,
    default=None,
    help='Directory for saving inference results.')
parser.add_argument(
    '--show-alias',
    action='store_true',
    help='Display all the available model aliases.')

call_args = vars(parser.parse_args())

init_kws = [
    'pose2d', 'pose2d_weights', 'scope', 'device', 'det_model',
    'det_weights', 'det_cat_ids', 'pose3d', 'pose3d_weights',
    'show_progress'
]
init_args = {}
for init_kw in init_kws:
    init_args[init_kw] = call_args.pop(init_kw)

display_alias = call_args.pop('show_alias')

return init_args, call_args, display_alias

def display_model_aliases(model_aliases: Dict[str, str]) -> None: """Display the available model aliases and their corresponding model names.""" aliases = list(model_aliases.keys()) max_alias_length = max(map(len, aliases)) print(f'{"ALIAS".ljust(max_alias_length + 2)}MODEL_NAME') for alias in sorted(aliases): print(f'{alias.ljust(max_alias_length + 2)}{model_aliases[alias]}')

def main(): init_args, call_args, display_alias = parse_args() if display_alias: model_alises = get_model_aliases(init_args['scope']) display_model_aliases(model_alises) else: inferencer = MMPoseInferencer(**init_args) for _ in inferencer(**call_args): pass

if name == 'main': main()

Reproduces the problem - command or script

python inference_demo.py

Reproduces the problem - error message

E:\anaconda3\envs\pymmpose\python.exe D:\githubProgram\mmpose-main\demo\inferencer_demo.py Loads checkpoint by local backend from path: D:\githubProgram\motionbert_ft_h36m-d80af323_20230531.pth 12/04 21:43:37 - mmengine - WARNING - Failed to search registry with scope "mmpose" in the "function" registry tree. As a workaround, the current "function" registry in "mmengine" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmpose" is a correct scope, or whether the registry is initialized. Loads checkpoint by local backend from path: D:\githubProgram\mmpose-main\hrformer_base_coco_256x192-6f5f1169_20220316.pth 12/04 21:43:37 - mmengine - WARNING - dataset_meta are not saved in the checkpoint's meta data, load via config. E:\anaconda3\envs\pymmpose\lib\site-packages\mmpose\datasets\datasets\utils.py:102: UserWarning: The metainfo config file "configs/base/datasets/coco.py" does not exist. A matched config file "E:\anaconda3\envs\pymmpose\lib\site-packages\mmpose.mim\configs_base_\datasets\coco.py" will be used instead. warnings.warn( Loads checkpoint by http backend from path: https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/rtmdet_m_8xb32-100e_coco-obj365-person-235e8209.pth 12/04 21:43:39 - mmengine - WARNING - Failed to search registry with scope "mmdet" in the "function" registry tree. As a workaround, the current "function" registry in "mmengine" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmdet" is a correct scope, or whether the registry is initialized. E:\anaconda3\envs\pymmpose\lib\site-packages\torch\functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:3191.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] Traceback (most recent call last): File "D:\githubProgram\mmpose-main\demo\inferencer_demo.py", line 224, in main() File "D:\githubProgram\mmpose-main\demo\inferencer_demo.py", line 219, in main for _ in inferencer(**call_args): File "E:\anaconda3\envs\pymmpose\lib\site-packages\mmpose\apis\inferencers\mmpose_inferencer.py", line 210, in call visualization = self.visualize(ori_inputs, preds, File "E:\anaconda3\envs\pymmpose\lib\site-packages\mmpose\apis\inferencers\mmpose_inferencer.py", line 249, in visualize return self.inferencer.visualize( File "E:\anaconda3\envs\pymmpose\lib\site-packages\mmpose\apis\inferencers\pose3d_inferencer.py", line 429, in visualize visualization = self.visualizer.add_datasample( File "E:\anaconda3\envs\pymmpose\lib\site-packages\mmengine\dist\utils.py", line 427, in wrapper return func(*args, **kwargs) File "E:\anaconda3\envs\pymmpose\lib\site-packages\mmpose\visualization\local_visualizer_3d.py", line 598, in add_datasample pred_img_data = self._draw_3d_data_samples( File "E:\anaconda3\envs\pymmpose\lib\site-packages\mmpose\visualization\local_visualizer_3d.py", line 303, in _draw_3d_data_samples pred_img_data = pred_img_data.reshape( ValueError: cannot reshape array of size 17203200 into shape (640,125440,3)

Additional information

No response

QKLXG avatar Dec 04 '24 13:12 QKLXG