loop through the batch image loader pytorch
Let say I have batch with  


  imgs = torch.Size([128, 1, 28, 28])


if I want to loop through the each image 

for img in imgs:
   print(img.shpae) -&gt; torch.Size([1, 28, 28])


if I want to get a  torch.Size([1,1, 28, 28]) for each image what should I do?

unsqueeze Just pass dim, In which position you want to add one extra singleton dimension.

imgs = torch.zeros([128, 1, 28, 28])

# dim (int) – the index at which to insert the singleton dimension
imgs.unsqueeze_(dim = 1)

imgs.shape
&gt;&gt;&gt; torch.Size([128, 1, 1, 28, 28])

