RizwanMunawar / yolov7-pose-estimation

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

VideoCapture resize error #6

Closed Ishihara-Masabumi closed 1 year ago

Ishihara-Masabumi commented 2 years ago

I resized the frame size in pose-estimate.py as below.

orig_image = cv2.resize(frame, dsize=(480, 480))

But, the following error occured.

$ python3 pose-estimate.py --device 0
Optimizer stripped from yolov7-w6-pose.pt, 161.1MB
Fusing layers... 
Frame 0 Processing
Traceback (most recent call last):
  File "pose-estimate.py", line 172, in <module>
    main(opt)
  File "pose-estimate.py", line 167, in main
    run(**vars(opt))
  File "/home/ishihara/.local/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "pose-estimate.py", line 96, in run
    output = model(image)
  File "/home/ishihara/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/ishihara/yolov7-pose-estimation/models/yolo.py", line 514, in forward
    return self.forward_once(x, profile)  # single-scale inference, train
  File "/home/ishihara/yolov7-pose-estimation/models/yolo.py", line 540, in forward_once
    x = m(x)  # run
  File "/home/ishihara/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/ishihara/yolov7-pose-estimation/models/common.py", line 111, in fuseforward
    return self.act(self.conv(x))
  File "/home/ishihara/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/ishihara/.local/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 443, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "/home/ishihara/.local/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 439, in _conv_forward
    return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same
RizwanMunawar commented 2 years ago

@Ishihara-Masabumi it seems that model weights are on the GPU, but resize image array is on the CPU. So, you need to send your input tensors to the GPU. add this line after resizing.

orig_image.to("cuda")

I hope it will resolve your issue.

Ishihara-Masabumi commented 2 years ago

Thank you for your support. BTW, the message from the run using 'orig_image.to("cuda")' is as follows:

Optimizer stripped from yolov7-w6-pose.pt, 161.1MB
Fusing layers... 
Frame 0 Processing
Traceback (most recent call last):
  File "pose-estimate.py", line 173, in <module>
    main(opt)
  File "pose-estimate.py", line 168, in main
    run(**vars(opt))
  File "/home/********/.local/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "pose-estimate.py", line 77, in run
    orig_image.to("cuda")
AttributeError: 'numpy.ndarray' object has no attribute 'to'
RizwanMunawar commented 2 years ago

@Ishihara-Masabumi Well! I have tested with resize on both GPU and CPU (Windows and Linux machines), its works fine. Even I not transferred the data to "cuda". Seems like you are using CPU and GPU both in parallel mode, or GPU memory was not cleared yet. For more details, you can take a look at mentioned link below. https://discuss.pytorch.org/t/converting-numpy-array-to-tensor-on-gpu/19423

RizwanMunawar commented 1 year ago

@Ishihara-Masabumi I am closing this issue, due to inactivity for a long time. Also, I have tested the code, and there is no issue coming that you mentioned. Feel free to open a new issue, if you will face an issue, but try to provide complete Information for testing.

Ishihara-Masabumi commented 1 year ago

I tried to run on many resize sizes. Then, I found that some resizees are accessible but others are not accessible and give errors. Please let me know the rule to resize. Thanks.

RizwanMunawar commented 1 year ago

@Ishihara-Masabumi! You will need to resize the image by keeping in mind the aspect ratio concept, otherwise, the code will throw an error. i.e acceptable resize start from 640 360, 1280 720 etc.

Ishihara-Masabumi commented 1 year ago

Thanks.