It seems your model returns just 1 channel using the sigmoid function.
You shouldn’t apply torch.max() on this, but just a threshold.
torch.max is useful, when your model returns predictions in multiple channels, each channel giving the “probability” of the class. In your case you just have a binary problem, i.e. 1 channel, where the prediction > threshold indicates class 1 and prediction < threshold class 0.
Could you check again, that your DataLoader returns the same number of images as set by batch_size?
I.e.: for batch_size=2 your data or x_train should have the shape [2, ...].