Thank You.
Below are the shapes of data, output, pred, target
data shape: torch.Size([12, 3, 600, 600])
target shape: torch.Size([12])
output1:  torch.Size([12, 4]) # Before and after squeezing
output2:  torch.Size([1, 12, 4])
Prediction:  torch.Size([1, 1, 4])

I think, I have removed the batch dimension somewhere, I am now running with using the batch size 1 but how to make it work for any batch size