Пример #1
0
 def __init__(self, cfg):
     self.cls_loss_func = SigmoidFocalLoss(cfg.MODEL.FCOS.LOSS_GAMMA,
                                           cfg.MODEL.FCOS.LOSS_ALPHA)
     # we make use of IOU Loss for bounding boxes regression,
     # but we found that L1 in log scale can yield a similar performance
     self.box_reg_loss_func = IOULoss()
     self.centerness_loss_func = nn.BCEWithLogitsLoss()
Пример #2
0
 def __init__(self, cfg, box_coder):
     self.cfg = cfg
     self.cls_loss_func = SigmoidFocalLoss(cfg.MODEL.ATSS.LOSS_GAMMA,
                                           cfg.MODEL.ATSS.LOSS_ALPHA)
     self.centerness_loss_func = nn.BCEWithLogitsLoss(reduction="sum")
     self.matcher = Matcher(cfg.MODEL.ATSS.FG_IOU_THRESHOLD,
                            cfg.MODEL.ATSS.BG_IOU_THRESHOLD, True)
     self.box_coder = box_coder
Пример #3
0
    def __init__(self, cfg):
        self.cls_loss_func = SigmoidFocalLoss(cfg.MODEL.FCOS.LOSS_GAMMA,
                                              cfg.MODEL.FCOS.LOSS_ALPHA)
        self.fpn_strides = cfg.MODEL.FCOS.FPN_STRIDES
        self.center_sampling_radius = cfg.MODEL.FCOS.CENTER_SAMPLING_RADIUS
        self.iou_loss_type = cfg.MODEL.FCOS.IOU_LOSS_TYPE
        self.norm_reg_targets = cfg.MODEL.FCOS.NORM_REG_TARGETS

        # we make use of IOU Loss for bounding boxes regression,
        # but we found that L1 in log scale can yield a similar performance
        self.box_reg_loss_func = IOULoss(self.iou_loss_type)
        self.centerness_loss_func = nn.BCEWithLogitsLoss(reduction="sum")
Пример #4
0
    def __init__(self, cfg):
        self.cls_loss_func = SigmoidFocalLoss(
            cfg.MODEL.FCOS.LOSS_GAMMA,
            cfg.MODEL.FCOS.LOSS_ALPHA
        )
        # class_weights = torch.ones(cfg.MODEL.FCOS.NUM_CLASSES).cuda()
        # class_weights[1] = 0.4
        # self.cls_loss_func_ce = nn.CrossEntropyLoss(reduction="sum")
        self.fpn_strides = cfg.MODEL.FCOS.FPN_STRIDES
        self.center_sampling_radius = cfg.MODEL.FCOS.CENTER_SAMPLING_RADIUS
        self.iou_loss_type = cfg.MODEL.FCOS.IOU_LOSS_TYPE
        self.norm_reg_targets = cfg.MODEL.FCOS.NORM_REG_TARGETS

        # we make use of IOU Loss for bounding boxes regression,
        # but we found that L1 in log scale can yield a similar performance
        self.box_reg_loss_func = IOULoss(self.iou_loss_type)
        self.f1_loss = F1_Loss(num_classes=cfg.MODEL.FCOS.NUM_CLASSES)
Пример #5
0
def make_retinanet_loss_evaluator(cfg, box_coder):
    matcher = Matcher(
        cfg.MODEL.RETINANET.FG_IOU_THRESHOLD,
        cfg.MODEL.RETINANET.BG_IOU_THRESHOLD,
        allow_low_quality_matches=True,
    )
    sigmoid_focal_loss = SigmoidFocalLoss(cfg.MODEL.RETINANET.LOSS_GAMMA,
                                          cfg.MODEL.RETINANET.LOSS_ALPHA)

    loss_evaluator = RetinaNetLossComputation(
        matcher,
        box_coder,
        generate_retinanet_labels,
        sigmoid_focal_loss,
        bbox_reg_beta=cfg.MODEL.RETINANET.BBOX_REG_BETA,
        regress_norm=cfg.MODEL.RETINANET.BBOX_REG_WEIGHT,
    )
    return loss_evaluator
Пример #6
0
    def __init__(self, cfg):
        self.cls_loss_func = SigmoidFocalLoss(cfg.MODEL.EMBED_MASK.LOSS_GAMMA,
                                              cfg.MODEL.EMBED_MASK.LOSS_ALPHA)
        self.fpn_strides = cfg.MODEL.EMBED_MASK.FPN_STRIDES
        self.center_on = cfg.MODEL.EMBED_MASK.CENTER_ON
        self.center_sampling_radius = cfg.MODEL.EMBED_MASK.CENTER_POS_RADIOS
        self.iou_loss_type = cfg.MODEL.EMBED_MASK.IOU_LOSS_TYPE
        self.norm_reg_targets = cfg.MODEL.EMBED_MASK.NORM_REG_TARGETS

        self.box_reg_loss_func = IOULoss(self.iou_loss_type)
        self.centerness_loss_func = nn.BCEWithLogitsLoss(reduction="sum")

        ########## mask prediction ############
        self.mask_loss_func = LovaszHinge(reduction='none')

        self.mask_scale_factor = cfg.MODEL.EMBED_MASK.MASK_SCALE_FACTOR
        self.object_sizes_of_interest = [
            [-1, cfg.MODEL.EMBED_MASK.FPN_INTEREST_SPLIT[0]],
            [
                cfg.MODEL.EMBED_MASK.FPN_INTEREST_SPLIT[0],
                cfg.MODEL.EMBED_MASK.FPN_INTEREST_SPLIT[1]
            ],
            [
                cfg.MODEL.EMBED_MASK.FPN_INTEREST_SPLIT[1],
                cfg.MODEL.EMBED_MASK.FPN_INTEREST_SPLIT[2]
            ],
            [
                cfg.MODEL.EMBED_MASK.FPN_INTEREST_SPLIT[2],
                cfg.MODEL.EMBED_MASK.FPN_INTEREST_SPLIT[3]
            ], [cfg.MODEL.EMBED_MASK.FPN_INTEREST_SPLIT[3], INF]
        ]
        self.sample_in_mask = cfg.MODEL.EMBED_MASK.SAMPLE_IN_MASK
        self.sample_pos_iou_th = cfg.MODEL.EMBED_MASK.SAMPLE_POS_IOU_TH

        self.box_padding = cfg.MODEL.EMBED_MASK.BOX_PADDING

        self.fix_margin = cfg.MODEL.EMBED_MASK.FIX_MARGIN
        prior_margin = cfg.MODEL.EMBED_MASK.PRIOR_MARGIN
        self.init_margin = -math.log(0.5) / (prior_margin**2)

        self.loss_mask_alpha = cfg.MODEL.EMBED_MASK.LOSS_MASK_ALPHA
        self.loss_smooth_alpha = cfg.MODEL.EMBED_MASK.LOSS_SMOOTH_ALPHA