- F.concat([score_shp[0], score_shp[1], score_shp[2] + 1], axis=0),
- dtype=np.float32,
- )
- one_mat = mge.ones(
- F.concat([score_shp[0], score_shp[1], tensor(1)], axis=0), dtype=np.float32,
- )
-
- one_hot = basic.indexing_set_one_hot(
- zero_mat, 2, valid_label.astype(np.int32), one_mat
- )[:, :, 1:]
- pos_part = F.power(1 - score, gamma) * one_hot * F.log(score)
- neg_part = F.power(score, gamma) * (1 - one_hot) * F.log(1 - score)
- loss = -(alpha * pos_part + (1 - alpha) * neg_part).sum(axis=2) * mask
-
- if norm_type == "fg":
- positive_mask = label > background
- return loss.sum() / F.maximum(positive_mask.sum(), 1)
- elif norm_type == "none":
- return loss.sum()
- else:
- raise NotImplementedError