zh-plus / video-to-pose3D

Convert video to 3D pose in one-key.
MIT License
643 stars 130 forks source link

"Argument 'alpha' can not be treated as a double" #35

Closed thekryz closed 4 years ago

thekryz commented 4 years ago

When I try to run python videopose.py with the demo video, I get the message "Argument 'alpha' can not be treated as a double:

(base) xxx@yyy:~/miniconda3/lib/python3.7/site-packages/video-to-pose3D$ python videopose.py 
the video is 25.051 f/s
Loading YOLO model..
/opt/conda/conda-bld/pytorch_1591914880026/work/torch/csrc/utils/python_arg_parser.cpp:756: UserWarning: This overload of nonzero is deprecated:
    nonzero(Tensor input, *, Tensor out)
Consider using one of the following signatures instead:
    nonzero(Tensor input, *, bool as_tuple)
Loading pose model from joints_detectors/Alphapose/models/sppe/duc_se.pth
Start pose estimation...
  0%|▎                                                                                                    | 1/338 [00:00<00:46,  7.18it/s]Exception in thread Thread-4:
Traceback (most recent call last):
  File "/home/xxx/miniconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/home/xxx/miniconda3/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/xxx/miniconda3/lib/python3.7/site-packages/video-to-pose3D/joints_detectors/Alphapose/dataloader.py", line 678, in update
    img = vis_frame(orig_img, result)
  File "/home/xxx/miniconda3/lib/python3.7/site-packages/video-to-pose3D/joints_detectors/Alphapose/fn.py", line 198, in vis_frame
    img = cv2.addWeighted(bg, transparency, img, 1 - transparency, 0)
TypeError: Argument 'alpha' can not be treated as a double

The script seems to continue, though I'm not sure if it eventually finishes, since I had to interrupt.

MikeXuQ commented 4 years ago

Hi, I have met the same question. Have you solved it?

smq20181217 commented 4 years ago

I have met the same problem, when i try to reduce the version of opencv-python to 3 and reinstall ffmpeg, this probem did not recur

zh-plus commented 4 years ago

The "alpha" argument is the second argument in https://github.com/zh-plus/video-to-pose3D/blob/b09374082557a6228d14e7d11ef09fa12b25cae8/joints_detectors/Alphapose/fn.py#L198

Since I cannot reproduce this issue, you can set a breakpoint there and see if the value of transparency cannot be converted to double. From my point of view, replacing transparency by float(transparency) may help.

Also, it may be caused by the incompatibility of opencv-python package. In my environment, the version is 4.1.0.25, which may help addressing this issue.

sysu17363044 commented 3 years ago

have you solved the problem yet? plz help

wordball commented 3 years ago

Might be a bit late but did you make sure that alpha was the correct data type? For example, if alpha was supposed to be an integer, did you use the int() method or ensure that the value that would replace alpha is an integer?

wangzexi commented 3 years ago

Same problem. I found the type of transparency is a torch.Tensor, so using torch.tensor(3.14).item() to get real value.

transparency = max(0, min(1, kp_scores[n])).item()
# ...
transparency = max(0, min(1, 0.5 * (kp_scores[start_p] + kp_scores[end_p]))).item()
gyg123456 commented 2 years ago

I have met the same problem, when i try to reduce the version of opencv-python to 3 and reinstall ffmpeg, this probem did not recur

It works,really thanks

javadasoodeh commented 1 year ago

I encountered a similar issue with the function 'AddWeighted'. However, I was able to address the problem by developing a custom function, which works well. The problem arose when I attempted to pass an array as an alpha parameter, resulting in the error 'Argument alpha cannot be treated as a double'. Consequently, I sought to investigate the underlying issue and, as a solution, introduced a new function named 'customAddWeighted'.

To see the full code: https://github.com/javadasoodeh/CV/blob/main/opencv_basic/alpha_blending.py

_Please note that the provided link may be subject to change. To access the relevant information, kindly navigate to the 'https://github.com/javadasoodeh/CV' section and search for the file name 'alphablending.py'.

def customAddWeighted(src1, alpha, src2, beta, gamma=0):
    # Check if the images have the same size
    if src1.shape != src2.shape:
        raise ValueError("Input images must have the same size.")

    # Perform alpha blending
    blended_image = np.clip(src1 * alpha[:, :, np.newaxis] + src2 * beta[:, :, np.newaxis] + gamma, 0, 255).astype(
        np.uint8)

    return blended_image