So I also have a strange issue with BCEWithLogitsLoss , simply with computation of the loss thru
loss = criterion(outputs.squeeze(), labels)
The computation works just fine 99.9% of the time but when I use this on my dataset with 7987 rows AND with a batch size of 256, I have the error
File “/nics/b/home/doursand/anaconda3/envs/limsnet/lib/python3.7/site-packages/torch/nn/functional.py”, line 2580, in binary_cross_entropy_with_logits
raise ValueError(“Target size ({}) must be the same as input size ({})”.format(target.size(), input.size()))
ValueError: Target size (torch.Size([1])) must be the same as input size (torch.Size([]))
However, if I change the batch size value to 255 instead of 256, then everything works like a charm!
Now if you do the calculation,
7937 rows / 256  = 31.0039062
and
7937 rows / 255 = 31.133333
Question : is it a rounding issue which makes the iteration with 256 images/batch fail (as 31.0039062 is seen as 31 ?)