RizwanMunawar / yolov7-pose-estimation

YOLOv7 Pose estimation using OpenCV, PyTorch
GNU General Public License v3.0
335 stars 77 forks source link

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 19 but got size 20 for tensor number 1 in the list. #14

Closed Jille closed 1 year ago

Jille commented 1 year ago

Hi. I'm trying to get your repo to work, but all videos I pass in (except football1.mp4) fail with the following error:

$ cd yolov7-pose-estimation && python pose-estimate.py --source ../1411739551.mp4 --device cpu
Optimizer stripped from yolov7-w6-pose.pt, 321.8MB
Fusing layers... 
/usr/local/lib/python3.8/dist-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3190.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Frame 1 Processing
Traceback (most recent call last):
  File "pose-estimate.py", line 160, in <module>
    main(opt)
  File "pose-estimate.py", line 155, in main
    run(**vars(opt))
  File "/usr/local/lib/python3.8/dist-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "pose-estimate.py", line 70, in run
    output_data, _ = model(image)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/content/yolov7-pose-estimation/models/yolo.py", line 514, in forward
    return self.forward_once(x, profile)  # single-scale inference, train
  File "/content/yolov7-pose-estimation/models/yolo.py", line 540, in forward_once
    x = m(x)  # run
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/content/yolov7-pose-estimation/models/common.py", line 62, in forward
    return torch.cat(x, self.d)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 19 but got size 20 for tensor number 1 in the list.

I'm running this on a Colab instance. The setup seems correct, because it does work for mp4.

I've tried reencoding a video to .png files and back to .mp4, but to no avail.

Any ideas?

RizwanMunawar commented 1 year ago

@Jille! I have tested pose estimation on other videos too and it's working fine. Can you share your video file for testing? A tested sample is attached below.

vlcsnap-2022-12-21-21h14m36s258

Jille commented 1 year ago

Hey @RizwanMunawar, thanks for the quick response :)

It seems to be a problem with the resolution of the video. If I convert football1.mp4 to an awkward size it breaks:

ffmpeg -i football1.mp4 -s 426x240 footsmall.mp4

You can find the resulting mp4 at http://skynet.quis.cx/footsmall.mp4

RizwanMunawar commented 1 year ago

@Jille! Your Image Size (width or height) must need to be greater than 640 or follow the aspect ratio concept, otherwise, the code will show an error.

i.e. I have tried on your provided video, which has size (426 240), but the model is throwing the same error as you mentioned above. But when I tried on video size (640360), the model is working fine.

Jille commented 1 year ago

Thanks @RizwanMunawar :)

It'd be nice if you could add a check to give a clearer error message for future users :)

RizwanMunawar commented 1 year ago

Sure, I will add it soon

Thanks @RizwanMunawar :)

It'd be nice if you could add a check to give a clearer error message for future users :)