Hi Krish!



 krish13:

In such case how is l1 computed? Will it be computed pixel by pixel (10*10) and mean is taken to get l1?


As an aside, you should use BCEWithLogitsLoss rather than BCELoss
for reasons of numerical stability.
To answer your question, the documentation is a little imperfect on this
point.  BCELoss simply computes the loss for each pair of matching
elements of the output and target tensors, and then computes the
mean (if that is what you have chosen for the reduction).  It doesn’t
care how the dimensions are divvied up into B, C, H, W.
This example shows what is going on:
>>> import torch
>>> torch.__version__
'1.7.1'
>>> _ = torch.manual_seed (2021)
>>> output = torch.rand (1, 1, 10, 10)
>>> target = torch.rand (1, 1, 10, 10)
>>> torch.nn.BCELoss() (output, target)
tensor(1.0348)
>>> torch.nn.BCELoss() (output.flatten(), target.flatten())
tensor(1.0348)
>>> torch.nn.BCELoss (reduction = 'none') (output, target).shape
torch.Size([1, 1, 10, 10])
>>> torch.nn.BCELoss (reduction = 'none') (output.flatten(), target.flatten()).shape
torch.Size([100])

Best.
K. Frank