首页 > 编程知识 正文

分类交叉熵,交叉熵损失值

时间:2023-05-05 06:23:23 阅读:194598 作者:2072

B C E L o s s ( 二 分 类 交 叉 熵 损 失 ) BCELoss(二分类交叉熵损失) BCELoss(二分类交叉熵损失) 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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。