title: Can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first
body: <p>I am trying to show results of GAN network on some specified epochs. The function for printing the current result was used previously with TF. I need to change in to pytorch.</p>
  <pre><code>def show_result(G_net, z_, num_epoch, show=False, save=False, path='result.png'):
  
  
    #test_images = sess.run(G_z, {z: z_, drop_out: 0.0})
    test_images = G_net(z_)
  
    size_figure_grid = 5
    fig, ax = plt.subplots(size_figure_grid, size_figure_grid, figsize=(5, 5))
  
    for i, j in itertools.product(range(size_figure_grid), range(size_figure_grid)):
       ax[i, j].get_xaxis().set_visible(False)
       ax[i, j].get_yaxis().set_visible(False)
  
    for k in range(5*5):
       i = k // 5
       j = k % 5
       ax[i, j].cla()
       ax[i, j].imshow(np.reshape(test_images[k], (28, 28)), cmap='gray')
  
    label = 'Epoch {0}'.format(num_epoch)
    fig.text(0.5, 0.04, label, ha='center')
  
    plt.savefig(name)
    file = drive.CreateFile({'title': label, &quot;parents&quot;: [{&quot;kind&quot;: &quot;https://drive.google.com/drive/u/0/folders/&quot;, &quot;id&quot;: folder_id}]})
    file.SetContentFile(name)
    file.Upload()
  
    if num_epoch == 10 or num_epoch == 20 or num_epoch == 50 or num_epoch == 100:
       plt.show()
      
    plt.close()
  </code></pre>
  <p>The results I need to obtain looks like that:
  <a href="https://i.stack.imgur.com/rIiA1.png" rel="nofollow noreferrer">result img</a></p>
  <p>I am getting this error, however I am not sure what I did incorrectly</p>
  <blockquote>
  <p>Can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first</p>
  </blockquote>