2.3 ratio between Pytorch BCEloss and my own "log" calculations
I'm scripting a toy model to both practice PyTorch and GAN models, and I'm making sure I understand each step as much as possible.
That leaded me to checking my understanding of the BCEloss function, and apparently I understand it... with a ratio of 2.3.

To check the results, I write the intermediate values for Excel:

tmp1 = y_pred.tolist()  # predicted values in list (to copy/paste on Excel)
tmploss = nn.BCELoss(reduction='none')  # redefining a loss giving the whole BCEloss tensor
tmp2 = tmploss(y_pred, y_real).tolist()  # BCEloss values in list (to copy/paste Exel)


Then I copy tmp1 on Excel and calculate: -log(x) for each values, which is the BCEloss formula for y_target = y_real = 1.

Then I compare the resulting values with the values of tmp2: these values are 2.3x higher than "mine".


(Sorry, I couldn't figure out how to format tables on this site...)

Can you please tell me what is happening? I feel a PEBCAK coming :-)

This is because in Excel the Log function calculates the logarithm to the base 10.
The standard definition of binary cross entropy uses a log function to the base e.
The ratio you're seeing is just log(10)=2.302585
