BCELoss(2クラスのクロスエントロピー損失)

BCEL oss(2クラスのクロスエントロピー損失)BCELoss(2クラスのクロスエントロピー損失) B C E L O S S 2つのサブクラスがクロスエントロピー損失損失

def clip_by_tensor(t,t_min,t_max):
    t=t.float()
    result = (t >= t_min).float() * t + (t < t_min).float() * t_min
    result = (result <= t_max).float() * result + (result > t_max).float() * t_max
    return result
def BCELoss(pred,target):
    epsilon = 1e-7
    pred = clip_by_tensor(pred, epsilon, 1.0 - epsilon) # 不要 0和1,要么是接近0的数,要么是接近1的数
    output = -target * torch.log(pred) - (1.0 - target) * torch.log(1.0 - pred)
    return output

おすすめ

転載: blog.csdn.net/qq_41375318/article/details/114625746