Unflatten a tensor back to an image
I am working on GANs and I want to visualize the image formed.
For this, I was trying
def show_images(image_tensor, num_images=9, size=(1, 28, 28)):
    image_unflat = image_tensor.detach().cpu.view(-1, *size)
    image_grid = make_grid(image_unflat[:num_images], nrow=3)
    plt.imshow(image_grid.permute(1, 2, 0).squeeze())
    plt.show()

but when I am trying to show_image(some_tensor), I am getting an error as
image_unflat = image_tensor.detach().cpu.view(-1, *size)
AttributeError: 'builtin_function_or_method' object has no attribute 'view'

Here, the size of some_tensor is N x 784.

You need to call cpu() before broadcasting with view.
image_unflat = image_tensor.detach().cpu().view(-1, *size)

