fastai / course-v3

The 3rd edition of course.fast.ai
https://course.fast.ai/
Apache License 2.0
4.91k stars 3.57k forks source link

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

Closed rraminen closed 4 years ago

rraminen commented 4 years ago

Copied the tensors on cpu as in the below function in fastai dl2 applications cyclegan.ipynb and cyclegan_ws.ipynb :

def show_best(fnames, losses, gen, n=8):
    sort_idx = losses.argsort().cpu()
    _,axs = plt.subplots(n//2, 4, figsize=(12,2*n))
    xb = get_batch(fnames[sort_idx][:n], tfms, size=128)
    with torch.no_grad():
        fakes = gen(xb)
    xb,fakes = (1+xb.cpu())/2,(1+fakes.cpu())/2
    for i in range(n):
        axs.flatten()[2*i].imshow(xb[i].permute(1,2,0))
        axs.flatten()[2*i].axis('off')
        axs.flatten()[2*i+1].imshow(fakes[i].permute(1,2,0))
        axs.flatten()[2*i+1].set_title(losses[sort_idx][i].item())
        axs.flatten()[2*i+1].axis('off')
review-notebook-app[bot] commented 4 years ago

Check out this pull request on  ReviewNB

Review Jupyter notebook visual diffs & provide feedback on notebooks.


Powered by ReviewNB