Skip to content

Commit

Permalink
Explicitly move to cpu before plotting (d2l-ai#1966)
Browse files Browse the repository at this point in the history
Fix TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first
  • Loading branch information
AnirudhDagar committed Mar 2, 2022
1 parent f6b1dd0 commit e2be14b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion chapter_computer-vision/kaggle-dog.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def train(net, train_iter, valid_iter, num_epochs, lr, wd, devices, lr_period,
measures = f'train loss {metric[0] / metric[1]:.3f}'
if valid_iter is not None:
valid_loss = evaluate_loss(valid_iter, net, devices)
animator.add(epoch + 1, (None, valid_loss.detach()))
animator.add(epoch + 1, (None, valid_loss.detach().cpu()))
scheduler.step()
if valid_iter is not None:
measures += f', valid loss {valid_loss:.3f}'
Expand Down

0 comments on commit e2be14b

Please sign in to comment.