open-mmlab / mmpose

OpenMMLab Pose Estimation Toolbox and Benchmark.
https://mmpose.readthedocs.io/en/latest/
Apache License 2.0
5.81k stars 1.24k forks source link

Image size IndexError on inference run #1977

Closed andpuc23 closed 1 year ago

andpuc23 commented 1 year ago

I am trying to run inference script (demo/top_down_img_demo.py) on CID and then DEKR models with COCO dataset, to check the pipeline is actually working in prediction mode. Used the provided config (here and further for CID): configs/body/2d_kpt_sview_rgb_img/cid/coco/hrnet_w48_coco_512x512.py (didn't change anything)

python demo/top_down_img_demo.py \ configs/body/2d_kpt_sview_rgb_img/cid/coco/hrnet_w48_coco_512x512.py \ https://download.openmmlab.com/mmpose/pretrain_models/hrnet_w48-8ef0771d.pth \ --img-root data/coco/val2017/ \ --json-file data/coco/annotations/person_keypoints_val2017.json \ --out-img-root data/coco/predictions/

The 1-st problem I encounter is that config provides image_size as an int (512 in the case), and TopDownTransform calculates aspect_ratio = image_size[0] / image_size[1]

OK, I change image_size to [512, 512] and heatmap_size to [128, 128] in config, get the next error:

Traceback (most recent call last): File "demo/top_down_img_demo.py", line 130, in main() File "demo/top_down_img_demo.py", line 99, in main pose_results, returned_outputs = inference_top_down_pose_model( File "/home/student/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/utils/misc.py", line 340, in new_func output = old_func(*args, kwargs) File "/home/student/.local/share/Trash/files/mmpose/mmpose/mmpose/apis/inference.py", line 392, in inference_top_down_pose_model poses, heatmap = _inference_single_pose_model( File "/home/student/.local/share/Trash/files/mmpose/mmpose/mmpose/apis/inference.py", line 267, in _inference_single_pose_model result = model( File "/home/student/anaconda3/envs/openmmlab/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, *kwargs) File "/home/student/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/runner/fp16_utils.py", line 119, in new_func return old_func(args, kwargs) File "/home/student/.local/share/Trash/files/mmpose/mmpose/mmpose/models/detectors/cid.py", line 141, in forward return self.forward_test( File "/home/student/.local/share/Trash/files/mmpose/mmpose/mmpose/models/detectors/cid.py", line 228, in forward_test assert img.size(0) == 1 AssertionError

Printing img.shape in cid.py 's forward_test() gives torch.Size([2, 427, 640, 3]), which means that there is a batch of 2 images passed to processing. My next question is how to control batch size in this case, since config doesn't seem to have such an option. OK, I fix that by throwing away 2-nd image in a batch: if img.shape[0] > 1: img = img[0] img = img[None, :,:,:] (I know this can be done neater, for now I just want it to work) and picking list containing 1-st item of img_metas instead of the original list.

Next I get such error: Traceback (most recent call last): File "demo/top_down_img_demo.py", line 130, in main() File "demo/top_down_img_demo.py", line 99, in main pose_results, returned_outputs = inference_top_down_pose_model( File "/home/viacheslav/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/utils/misc.py", line 340, in new_func output = old_func(*args, **kwargs) File "/home/viacheslav/mmpose/mmpose/apis/inference.py", line 392, in inference_top_down_pose_model poses, heatmap = _inference_single_pose_model( File "/home/viacheslav/mmpose/mmpose/apis/inference.py", line 259, in _inference_single_pose_model data = test_pipeline(data) File "/home/viacheslav/mmpose/mmpose/datasets/pipelines/shared_transform.py", line 107, in call data = t(data) File "/home/viacheslav/mmpose/mmpose/datasets/pipelines/shared_transform.py", line 178, in call meta[key_tgt] = results[key_src] KeyError: 'flip_index'

No idea what to do here, pls help

enironment: /home/xxx/anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/init.py:20: UserWarning: On January 1, 2023, MMCV will release v2.0.0, in which it will remove components related to the training process and add a data transformation module. In addition, it will rename the package names mmcv to mmcv-lite and mmcv-full to mmcv. See https://github.com/open-mmlab/mmcv/blob/master/docs/en/compatibility.md for more details. warnings.warn( sys.platform: linux Python: 3.8.16 (default, Jan 17 2023, 23:13:24) [GCC 11.2.0] CUDA available: True GPU 0: NVIDIA GeForce GTX 1080 CUDA_HOME: None GCC: gcc (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 PyTorch: 1.10.2 PyTorch compiling details: PyTorch built with:

TorchVision: 0.11.3 OpenCV: 4.7.0 MMCV: 1.7.1 MMCV Compiler: GCC 9.3 MMCV CUDA Compiler: 11.3 MMPose: 0.29.0+4c397f2

ly015 commented 1 year ago

Hi, thanks for using MMPose. CID and DEKR follow the bottom-up paradigm, so please use the script demo/bottom_up_img_demo.py. Details can be found at https://github.com/open-mmlab/mmpose/blob/master/demo/docs/2d_human_pose_demo.md#2d-human-pose-bottom-up-image-demo.

ly015 commented 1 year ago

There is a lack of demo guides for each model indeed. We will consider adding them to the model README files in the future.

andpuc23 commented 1 year ago

Thank you @ly015! I found an error, and now it works. However, as you noticed, more guides would be much appreciated!