Hzzone / pytorch-openpose

pytorch implementation of openpose including Hand and Body Pose Estimation.
2.03k stars 390 forks source link

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. #8

Open JeremyKeusters opened 4 years ago

JeremyKeusters commented 4 years ago

First of all: thanks for your amazing work! I would like to use OpenPose, but can't run Caffe in my current setup/environment. This repo is a life-saver.

Now to the point: I got the following error when running the demo.py: TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

I fixed this by changing the line in python/hand.py: output = self.model(data).numpy()

to: output = self.model(data).cpu().numpy()

As numpy can't work on stuff that is still on the GPU.. I'm not sure if this needs to be changed in the repo and if this is the best solution for this error? Thanks.

My environment specs are the following: OS: CentOS Linux release 7.5.1804 CUDA version: 8.0 cuDNN version: 7.0.5 Torch version: 0.4.1 Python version: Python 3.6.6 GPU's: 4x GeForce RTX 2070

The full error stack:

Traceback (most recent call last):
  File "demo.py", line 31, in <module>
    peaks = hand_estimation(oriImg[y:y+w, x:x+w, :])
  File "python/hand.py", line 46, in __call__
    output = self.model(data).numpy()
TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
Hzzone commented 4 years ago
output = self.model(data).cpu().numpy()
JeremyKeusters commented 4 years ago

Yup, that’s the same solution as I posted above. So you agree that this is the right solution?

12345k commented 4 years ago

@JeremyKeusters your solution has helped me. Thanks

swithmn1 commented 4 years ago

output = self.model(data).cpu().numpy();this is right!