简体   繁体   English

2.3 Pytorch BCEloss 与我自己的“log”计算之比

[英]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.我正在编写一个玩具 model 脚本来练习 PyTorch 和 GAN 模型,并且我确保我尽可能理解每个步骤。 That leaded me to checking my understanding of the BCEloss function, and apparently I understand it... with a ratio of 2.3.这使我检查了我对 BCEloss function 的理解,显然我理解它......比率为 2.3。

To check the results, I write the intermediate values for Excel:为了检查结果,我写了 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 .然后我在 Excel 上复制tmp1并计算: -log(x)每个值,这是y_target = y_real = 1的 BCEloss 公式。

Then I compare the resulting values with the values of tmp2 : these values are 2.3x higher than "mine".然后我将结果值与tmp2的值进行比较:这些值比“我的”高 2.3 倍。

在此处输入图像描述 (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:-)我觉得 PEBCAK 来了:-)

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 .这是因为在 Excel 中,日志function 计算以 10 为底的对数。二进制交叉熵的标准定义使用日志 ZC1C425268E68385D1AB5074C17A94F1 以e为底The ratio you're seeing is just log(10)=2.302585您看到的比率只是log(10)=2.302585

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PyTorch - BCELoss:ValueError:目标和输入必须具有相同数量的元素 - PyTorch - BCELoss: ValueError: Target and input must have the same number of elements 如何在 Pytorch 中创建我自己的损失函数? - How to create my own loss function in Pytorch? 如何在 Pytorch 中使用 torch.nn.Sequential 实现我自己的 ResNet? - How to implement my own ResNet with torch.nn.Sequential in Pytorch? 如何使用我自己的输入使用Pytorch的“使用seq2seq进行翻译”? - How do I use Pytorch's “tanslation with a seq2seq” using my own inputs? 使用 Pytorch model 参数进行计算时出现结果类型转换错误 - Result type cast error when doing calculations with Pytorch model parameters 每次下降之间的困惑度计算都会上升 - Perplexity calculations rise between each significantly drop 如何在训练集和测试集之间划分数据集,同时保持两组中目标变量的比率? - How do I split my data set between training and testing sets while keeping the ratio of the target variable in both sets? LGBM 中的二进制对数损失与在线发现的导数计算不同 - Binary log loss in LGBM not as per derivative calculations found online 是否可以在pytorch的transform.compose中添加自己的功能 - Is it possible to add own function in transform.compose in pytorch 在pytorch中的相关类之间共享渐变 - Sharing gradients between the related classes in pytorch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM