AI-Challenger-Retinal-Edema-Segmentation
AI-Challenger-Retinal-Edema-Segmentation copied to clipboard
关于loss
您好,请问在训练的时候背景的Loss是不参与计算吗?因为我看您EL` Dice是从类别1开始计算的,如下:
class EL_DiceLoss(nn.Module): def init(self, class_num=4,smooth=1,gamma=0.5): super(EL_DiceLoss, self).init() self.smooth = smooth self.class_num = class_num self.gamma = gamma
def forward(self,input, target):
input = torch.exp(input)
self.smooth = 0.
Dice = Variable(torch.Tensor([0]).float()).cuda()
for i in range(1,self.class_num):
input_i = input[:,i,:,:]
target_i = (target == i).float()
intersect = (input_i*target_i).sum()
union = torch.sum(input_i) + torch.sum(target_i)
if target_i.sum() == 0:
dice = Variable(torch.Tensor([1]).float()).cuda()
else:
dice = (2 * intersect + self.smooth) / (union + self.smooth)
Dice += (-torch.log(dice))**self.gamma
dice_loss = Dice/(self.class_num - 1)
return dice_loss
为什么WCE Loss设置的 ignore_index=255呢?背景像素不应当是0吗? weight_1 = torch.Tensor([1,5,10,20]) criterion_1 = nn.NLLLoss(weight=weight_1,ignore_index=255)
请您讲解一下,谢谢~