#假设strong_out_ul和weak_out_ul都是logits(未经过softmax,且同样尺寸)
weak_prob_ul = F.softmax(weak_out_ul.detach_(), dim=1)
max_probs, target_ul = torch.max(weak_prob_ul, dim=1)
mask = max_probs.ge(0.95).float()#0.95可更换为其他阈值
loss_unsup = (F.cross_entropy(strong_out_ul, target_ul, reduction='none') * mask).mean()
CE损失函数融入置信度掩码(极简代码)
最新推荐文章于 2024-05-21 17:26:41 发布