TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
rraminen opened this issue · 0 comments
rraminen commented
In cyclegan.ipynb and cyclegan_ws.ipynb, show_best(fnames, losses, gen, n):
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')