当前位置: 首页>>代码示例>>Python>>正文


Python layers.SigmoidFocalLoss方法代码示例

本文整理汇总了Python中maskrcnn_benchmark.layers.SigmoidFocalLoss方法的典型用法代码示例。如果您正苦于以下问题:Python layers.SigmoidFocalLoss方法的具体用法?Python layers.SigmoidFocalLoss怎么用?Python layers.SigmoidFocalLoss使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在maskrcnn_benchmark.layers的用法示例。


在下文中一共展示了layers.SigmoidFocalLoss方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_retinanet_loss_evaluator

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
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 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:22,代码来源:loss.py

示例2: make_retinanet_loss_evaluator

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
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
    )

    scheme = "free" if cfg.MODEL.SAMPLING_FREE_ON else "focalloss"
    loss_evaluator = eval("RetinaNetLossComputation" + scheme.capitalize())(
        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 
开发者ID:ChenJoya,项目名称:sampling-free,代码行数:23,代码来源:loss.py

示例3: __init__

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
def __init__(self, cfg, proposal_matcher, box_coder):
        """
        Arguments:
            proposal_matcher (Matcher)
            box_coder (BoxCoder)
        """
        # self.target_preparator = target_preparator
        self.proposal_matcher = proposal_matcher
        self.box_coder = box_coder
        self.num_classes = cfg.RETINANET.NUM_CLASSES -1
        self.box_cls_loss_func = SigmoidFocalLoss(
            self.num_classes,
            cfg.RETINANET.LOSS_GAMMA,
            cfg.RETINANET.LOSS_ALPHA
        )
        self.regression_loss = SmoothL1Loss(
            beta=cfg.RETINANET.BBOX_REG_BETA
        ) 
开发者ID:zhangxiaosong18,项目名称:FreeAnchor,代码行数:20,代码来源:retinanet_loss.py

示例4: __init__

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
def __init__(self, cfg, proposal_matcher, box_coder):
        """
        Arguments:
            proposal_matcher (Matcher)
            box_coder (BoxCoder)
        """
        # self.target_preparator = target_preparator
        self.proposal_matcher = proposal_matcher
        self.box_coder = box_coder
        self.num_classes = cfg.RETINANET.NUM_CLASSES -1
        self.box_cls_loss_func = SigmoidFocalLoss(
            self.num_classes,
            cfg.RETINANET.LOSS_GAMMA,
            cfg.RETINANET.LOSS_ALPHA
        )
        if cfg.RETINANET.SELFADJUST_SMOOTH_L1:
            self.regression_loss = AdjustSmoothL1Loss(
                4,
                beta=cfg.RETINANET.BBOX_REG_BETA
            )
        else:
            self.regression_loss = SmoothL1Loss(
                beta=cfg.RETINANET.BBOX_REG_BETA
            ) 
开发者ID:chengyangfu,项目名称:retinamask,代码行数:26,代码来源:retinanet_loss.py

示例5: __init__

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
def __init__(self, cfg, proposal_matcher, box_coder):
        """
        Arguments:
            proposal_matcher (Matcher) 
                a tensor of size N containing the index of the gt element m the 
                matches to prediction n. If there is no match, a negative value is returned
            box_coder (BoxCoder)
        """
        self.proposal_matcher = proposal_matcher
        self.box_coder = box_coder
        self.num_classes = cfg.MODEL.RETINANET.NUM_CLASSES -1
        self.box_cls_loss_func = SigmoidFocalLoss(
            cfg.MODEL.RETINANET.LOSS_GAMMA,
            cfg.MODEL.RETINANET.LOSS_ALPHA
        )
        self.bbox_reg_weight = cfg.MODEL.RETINANET.BBOX_REG_WEIGHT
        self.bbox_reg_beta = cfg.MODEL.RETINANET.BBOX_REG_BETA
        self.weight = cfg.MODEL.PANOPTIC.DET_WEIGHT 
开发者ID:Lausannen,项目名称:NAS-FCOS,代码行数:20,代码来源:loss.py

示例6: make_retinanet_loss_evaluator

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
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 
开发者ID:ucas-vg,项目名称:TinyBenchmark,代码行数:22,代码来源:loss.py

示例7: prepare_targets

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
def prepare_targets(self, anchors, targets):
        labels = []
        regression_targets = []
        for anchors_per_image, targets_per_image in zip(anchors, targets):
            matched_targets = self.match_targets_to_anchors(
                anchors_per_image, targets_per_image
            )

            matched_idxs = matched_targets.get_field("matched_idxs")
            labels_per_image = matched_targets.get_field("labels").clone()

            # Background (negative examples)
            bg_indices = matched_idxs == Matcher.BELOW_LOW_THRESHOLD
            labels_per_image[bg_indices] = 0

            # discard indices that are between thresholds 
            # -1 will be ignored in SigmoidFocalLoss
            inds_to_discard = matched_idxs == Matcher.BETWEEN_THRESHOLDS
            labels_per_image[inds_to_discard] = -1

            labels_per_image = labels_per_image.to(dtype=torch.float32)
            # compute regression targets
            regression_targets_per_image = self.box_coder.encode(
                matched_targets.bbox, anchors_per_image.bbox
            )

            labels.append(labels_per_image)
            regression_targets.append(regression_targets_per_image)

        return labels, regression_targets 
开发者ID:zhangxiaosong18,项目名称:FreeAnchor,代码行数:32,代码来源:retinanet_loss.py

示例8: prepare_targets

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
def prepare_targets(self, anchors, targets):
        labels = []
        regression_targets = []
        for anchors_per_image, targets_per_image in zip(anchors, targets):
            if len(targets_per_image) <= 0:
                device = anchors_per_image.bbox.device
                dummy_labels = torch.zeros(len(anchors_per_image),
                                           dtype=torch.float32,
                                           device=device)
                dummy_regression = torch.zeros((len(anchors_per_image), 4),
                                               dtype=torch.float32,
                                               device=device)
                labels.append(dummy_labels)
                regression_targets.append(dummy_regression)
                continue
            matched_targets = self.match_targets_to_anchors(
                anchors_per_image, targets_per_image
            )

            matched_idxs = matched_targets.get_field("matched_idxs")
            labels_per_image = matched_targets.get_field("labels").clone()

            # Background (negative examples)
            bg_indices = matched_idxs == Matcher.BELOW_LOW_THRESHOLD
            labels_per_image[bg_indices] = 0

            # discard indices that are between thresholds 
            # -1 will be ignored in SigmoidFocalLoss
            inds_to_discard = matched_idxs == Matcher.BETWEEN_THRESHOLDS
            labels_per_image[inds_to_discard] = -1

            labels_per_image = labels_per_image.to(dtype=torch.float32)
            # compute regression targets
            regression_targets_per_image = self.box_coder.encode(
                matched_targets.bbox, anchors_per_image.bbox
            )

            labels.append(labels_per_image)
            regression_targets.append(regression_targets_per_image)
            
        return labels, regression_targets 
开发者ID:Lausannen,项目名称:NAS-FCOS,代码行数:43,代码来源:loss.py

示例9: __init__

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
def __init__(self, cfg):
        self.cls_loss_func = SigmoidFocalLoss(
            cfg.MODEL.RETINANET.LOSS_GAMMA,
            cfg.MODEL.RETINANET.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.bbox_reg_loss_func = IOULoss()
        self.reg_weights_loss_func = nn.BCEWithLogitsLoss() 
开发者ID:Lausannen,项目名称:NAS-FCOS,代码行数:11,代码来源:loss.py

示例10: __init__

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
def __init__(self, cfg):
        # self.cls_loss_func = SigmoidFocalLoss(
        #     cfg.MODEL.LOC.LOSS_GAMMA,
        #     cfg.MODEL.LOC.LOSS_ALPHA
        # )
        cls_loss_name = cfg.MODEL.LOC.CLS_LOSS
        self.cls_divide_pos_num = True
        if cls_loss_name == 'fixed_focal_loss':
            self.cls_loss_func = FixSigmoidFocalLoss(
                cfg.MODEL.LOC.LOSS_GAMMA,
                cfg.MODEL.LOC.LOSS_ALPHA
            )
        elif cls_loss_name == 'L2':
            self.cls_loss_func = L2LossWithLogit()
        elif cls_loss_name == 'GHMC':
            self.cls_loss_func = GHMC(bins=cfg.MODEL.LOC.LOSS_GHMC_BINS,
                              alpha=cfg.MODEL.LOC.LOSS_GHMC_ALPHA,
                              momentum=cfg.MODEL.LOC.LOSS_GHMC_MOMENTUM)
            self.cls_divide_pos_num = False

        # 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()
        if cfg.MODEL.LOC.TARGET_GENERATOR == 'fcos' and cfg.MODEL.LOC.FCOS_CENTERNESS:
            self.centerness_loss_func = nn.BCEWithLogitsLoss()

        self.prepare_targets = build_target_generator(cfg)
        self.cls_loss_weight = cfg.MODEL.LOC.CLS_WEIGHT
        self.centerness_weight_reg = cfg.MODEL.LOC.TARGET_GENERATOR == 'fcos' and cfg.MODEL.LOC.FCOS_CENTERNESS_WEIGHT_REG
        self.debug_vis_labels = cfg.MODEL.LOC.DEBUG.VIS_LABELS

        self.cls_divide_pos_sum = cfg.MODEL.LOC.DIVIDE_POS_SUM
        if self.cls_divide_pos_sum:
            self.cls_divide_pos_num = False 
开发者ID:ucas-vg,项目名称:TinyBenchmark,代码行数:36,代码来源:loss.py

示例11: __init__

# 需要导入模块: from maskrcnn_benchmark import layers [as 别名]
# 或者: from maskrcnn_benchmark.layers import SigmoidFocalLoss [as 别名]
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()
        self.cascade_area_th = cfg.MODEL.FCOS.CASCADE_AREA_TH
        self.vis_labels = cfg.MODEL.FCOS.DEBUG.VIS_LABELS
        self.no_match_gt_count = {pos_area: 0 for pos_area in self.cascade_area_th} 
开发者ID:ucas-vg,项目名称:TinyBenchmark,代码行数:14,代码来源:loss.py


注:本文中的maskrcnn_benchmark.layers.SigmoidFocalLoss方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。