2021
07-09
07-09
pytorch 实现二分类交叉熵逆样本频率权重
通常,由于类别不均衡,需要使用weightedcrossentropyloss平衡。definverse_freq(label):"""输入label[N,1,H,W],1是channel数目"""den=label.sum()#0_,_,h,w=label.shapenum=h*walpha=den/num#0returntorch.tensor([alpha,1-alpha]).cuda()#train...loss1=F.cross_entropy(out1,label.squeeze(1).long(),weight=inverse_freq(label))补充:Pytorch踩坑记之交叉熵(nn.CrossEntropy...
继续阅读 >