Display tensor of <B,16,W,H>

Hi,

How would I display a tensor of dimension <B,C=16,W,H> , where the channel is not 3?
The tensor represents a batch of feature maps.
I would like to use utils.make_grid to display the batch…

Thanks! :slight_smile:

Hey! This isn’t a Lightning question, but you could visualize your tensor one channel at a time like so:

from torchvision.utils import make_grid
import torch
import matplotlib.pyplot as plt

b, c, w, h = 32, 16, 8, 8

x = torch.rand(b, c, w, h)

for channel in range(x.shape[1]):
    grid = make_grid(x[:, channel, :, :].unsqueeze(1))
    plt.imshow(grid.permute(1, 2, 0).numpy()) # imshow uses w, h, c order
    plt.show()

Hope this helps!

1 Like

@teddy thank you very much for the reply.
Where should I ask questions like these then? Pytorch forum? Quite new to this.

I would say the PyTorch forum, but if you are unsure we are happy to answer any other questions you may have here :slight_smile:

1 Like