I was trying to the run the benchmark code in google colab, But I was run into problem . could please anyone help me to solve this.
here my error.
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
Tensors on CUDA cannot be converted to numpy directly. You need to manually move it to CPU first.
The solution is exactly what is error description says:
what worked for me was changing true and preds to preds.to(‘cpu’).numpy() and true.to(‘cpu’).numpy()
Thanks for the solution polymath.
@suresh12 were you able to solve it? I am still facing the issue after changing the line
return preds.detach().numpy().squeeze() to return preds.to(‘cpu’).detach().numpy().squeeze()
Do we have to change somewhere else to? can you share the code snippet which you changed
actually you have to use .to(‘cpu’) the first time preds and true are stored as numpy tensors which is in the following line:
intersection = np.logical_and(true, pred)
union = np.logical_or(true, pred)
Thanks for the help, solved.
Just FYI this has been fixed on the blog post in a recent round of edits. Thanks to @polymathAB for flagging.