INNER CODE UNIT · Python
neg_num
nv-tlabs/GSCNN · loss.py:82
neg_num = neg_index.sum()
sum_num = pos_num + neg_num
weight[pos_index] = neg_num*1.0 / sum_num
weight[neg_index] = pos_num*1.0 / sum_num
weight[ignore_index] = 0
weight = torch.from_numpy(weight)
weight = weight.cuda()
loss = F.binary_cross_entropy_with_logits(log_p, target_t, weight, size_average=True)
return loss
def edge_attention(self, input, target, edge):
n, c, h, w = input.size()
filler = torch.ones_like(target) * 255
return self.seg_loss(input,
torch.where(edge.max(1)[0] > 0.8, target, filler))