Hello, I am using squeeze() before calculating loss. My code is given below and giving an error
ValueError: Target size (torch.Size([1, 256, 383])) must be the same as input size (torch.Size([1, 1, 256, 383]))
    def training_step(self, batch, batch_nb):
        x, y = batch
        y_hat = self.forward(x)
        y_label = y.squeeze(axis = 1)
        loss = F.cross_entropy(y_hat, y_label) if self.n_classes > 1 else \
            F.binary_cross_entropy_with_logits(y_hat, y_label)
        tensorboard_logs = {'train_loss': loss}
        return {'loss': loss, 'log': tensorboard_logs}

But, when I am changing the y_label to y only for logist binary_cross_entropy_with_logitsy_hat, y)
Working fine!
Why y_label is showing the error for logits but working fine for cross_entropy.
However, if I do not use squeeze() it gives the same error for both loss functions.
For your kind information
x torch size torch.Size([1, 3, 256, 383])
y torch size torch.Size([1, 3, 256, 383])
y_label torch size torch.Size([1, 256, 383])
Thanks in advance.