Conditional GAN concatenation of real image and label

I am concatenating real images with labels and the output shape is [128, 11,28, 28]. How can I visualize this image?

encoded_labels = F.one_hot(reallabels, num_classes)
encoded_labels = encoded_labels [:, :, None, None]
encoded_labels = encoded_labels .repeat(1, 1, mnist_shape[1], mnist_shape[2]) 

Here the encoded_labels size is torch.Size([128, 10, 28, 28])

Now I want to concatenate it with images
cat_real_labels = torch.cat((realImages.float(), encoded_labels .float()),1)
output: torch.Size([128, 11, 28, 28])

How can I visualize this image?

You cannot visualize it directly, as the tensor doesn’t have a valid image shape.
However, you could visualize the 11 channels separately of all 128 samples (so 1408 grayscale images).

Can you just give me a hint of code? How can I visualize it separately for all 128 samples?

Something like this approach would work. The difference would be that you would have to flatten the first two dimensions in case you want to visualize all 11*128 grayscale images.

1 Like