Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. #509

Open
rraminen opened this issue Apr 28, 2020 · 0 comments

Comments

@rraminen
Copy link
Contributor

In cyclegan.ipynb and cyclegan_ws.ipynb, show_best(fnames, losses, gen, n):
image

Would this be the right fix:

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant