I am following the Pytorch tutorial on the DCgan, and was trying to view the output images from the model individually, instead as grid. This is the code used:
generating new images
sets a random seed
manualSeed = random.randint(1, 10000) # use if you want new results
print("Random Seed: ", manualSeed)
random.seed(manualSeed)
torch.manual_seed(manualSeed)
I am able to view the output as a grid using the following function, but that doesn’t serve my purpose since I would like to save each image later using a loop function.
make_grid will create a grid using all samples in the current batch and transform it into an image format.
Based on your code I guess you are seeing an error claiming that the input shape is invalid.
If so, this error is expected since matplotlib expects input arrays in an image formar as [height, width, channels] where the channels dimension might be missing in case of a grayscale image.
Your model output should have the shape [batch_size, channels, height, width] so you would have to index the sample you would like to visualize in the batch dimension and permute the image to the aforementioned channels-last format.
Thanks alot! I can now see the image but it is in black and no information is available. Also, I am unable to find a way to remove the X and Y numbers plotted as I want to generate art using pytorch and the grids are not going away
Code:
# sets a random seed
manualSeed = random.randint(1, 10000) # use if you want new results
You are receiving a warning that your data will be clipped, which could create the black image.
Check the values in the tensor you would like to visualize and make sure they are either floating point values in [0, 1] or uint8 values in [0, 255].
To remove the axes you could use plt.axis('off') and refer to the matplotlib docs for more information.