01_pytorch_workflow_exercises question #260
Replies: 2 comments 2 replies
-
Hi, y_preds.cpu().detach().numpy() should we replaces by y_preds.detach().numpy().cpu() should do the trick. best wishes |
Beta Was this translation helpful? Give feedback.
-
Hi @sharkweekshane, I've faced that error plenty of times too. And it can be a bit hard to troubleshoot. I just went through the solutions notebook and it seems to work fine end-to-end: https://github.com/mrdbourke/pytorch-deep-learning/blob/main/extras/solutions/01_pytorch_workflow_exercise_solutions.ipynb I'd say a potential issue you may be facing:
You can check what device your PyTorch tensor is on with y_preds.device Out:
y_preds.cpu().device Out:
However, As for this line: tensor.cpu().detach().numpy() This is saying "send Hopefully this clears things up! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi folks,
Been loving the course so far (Cue fire animation)
I'm working through the second set of exercises (01) and I keep getting an error when I try to plot the predictions
Plot the predictions (these may need to be on a specific device)
plot_predictions(predictions = y_preds.cpu())
I get error:
RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.
I see a similar question was asked about this, but I can't wrap my mind around it. Can someone help?
Edit: I also tried
plot_predictions(predictions = y_preds.cpu().detach().numpy())
as suggested by the error, and I got another error that I also don't understandBeta Was this translation helpful? Give feedback.
All reactions