<>BCELoss

BCELoss是 − 1 n ∑ ( y n × ln ⁡ x n + ( 1 − y n ) × ln ⁡ ( 1 − x n ) ) -\frac 1
n\sum(y_n \times \ln x_n+(1-y_n) \times \ln(1-x_n))−n1​∑(yn​×lnxn​+(1−yn​)×ln(1−
xn​))

0.3992+ (1-0) \times \ln (1-0.3992)=-0.50950×ln0.3992+(1−0)×ln(1−0.3992)=−0.5095

0.2232+ (1-1) \times \ln (1-0.2232)=-1.49971×ln0.2232+(1−1)×ln(1−0.2232)=−1.4997

0.6435+ (1-1) \times \ln (1-0.6435)=-0.44081×ln0.6435+(1−1)×ln(1−0.6435)=−0.4408

0.3800+ (1-0) \times \ln (1-0.3800)=-0.47800×ln0.3800+(1−0)×ln(1−0.3800)=−0.4780

0.3044+ (1-0) \times \ln (1-0.3044)=-0.36300×ln0.3044+(1−0)×ln(1−0.3044)=−0.3630

0.3241+ (1-1) \times \ln (1-0.3241)=-1.12671×ln0.3241+(1−1)×ln(1−0.3241)=−1.1267

0.6281+ (1-1) \times \ln (1-0.6281)=-0.46511×ln0.6281+(1−1)×ln(1−0.6281)=−0.4651

0.4689+ (1-0) \times \ln (1-0.4689)=-0.63280×ln0.4689+(1−0)×ln(1−0.4689)=−0.6328

0.3834+ (1-1) \times \ln (1-0.3834)=-0.95871×ln0.3834+(1−1)×ln(1−0.3834)=−0.9587

0.5095 + 1.4997 + 0.4408 3 = 0.8167 \frac {0.5095+1.4997+0.4408} {3} = 0.8167
30.5095+1.4997+0.4408​=0.8167
0.4780 + 0.3630 + 1.1267 3 = 0.6559 \frac {0.4780+0.3630+1.1267} {3} = 0.6559
30.4780+0.3630+1.1267​=0.6559
0.4651 + 0.6328 + 0.9587 3 = 0.6855 \frac {0.4651+0.6328+0.9587} {3} = 0.6855
30.4651+0.6328+0.9587​=0.6855

0.8167 + 0.6559 + 0.6855 3 = 0.7194 \frac {0.8167+0.6559+0.6855} {3} = 0.7194
30.8167+0.6559+0.6855​=0.7194

emmm应该是我上面每次都保留4位小数，算到最后误差越来越大差了0.0001。不过也很厉害啦哈哈哈哈哈！

<>BCEWithLogitsLoss

BCEWithLogitsLoss就是把Sigmoid-BCELoss合成一步。我们直接用刚刚的input验证一下是不是0.7193：

GitHub

Gitee