Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JeremyKeusters opened this issue Jul 12, 2019 · 4 comments

Comments

@JeremyKeusters
Copy link

JeremyKeusters commented Jul 12, 2019

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
Copy link
Owner

Hzzone commented Jul 12, 2019

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

@JeremyKeusters
Copy link
Author

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

@12345k
Copy link

12345k commented Oct 13, 2019

@JeremyKeusters your solution has helped me. Thanks

@swithmn1
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants