简体   繁体   中英

TypeError: can’t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

learned_pred = euclidean_distances(answer.cpu().data.numpy(), predicates_emb).argmin(axis=1)

The type error is raised in the above line of code I used.cpu() so I cannot understand why..

How can I solve this problem?

The conversion from variable answer is true. Therefore, I think the problem may stay in the variable predicates_emb .

Can you check if var predicates_emb is tensor or not. If it is, you should convert it to numpy array.

I had the same issue, a answer.cpu() did not work for me but answer.to('cpu')... did work for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM