def build_faster_rcnn_classification_loss(loss_config): """Builds a classification loss for Faster RCNN based on the loss config. Args: loss_config: A losses_pb2.ClassificationLoss object. Returns: Loss based on the config. Raises: ValueError: On invalid loss_config. """ loss_type = loss_config.TYPE config = loss_config.VALUE # By default, Faster RCNN second stage classifier uses Softmax loss # with anchor-wise outputs. return losses.WeightedSoftmaxClassificationLoss(logit_scale=config.logit_scale)
def _build_classification_loss(loss_config): """Builds a classification loss based on the loss config. Args: loss_config: A losses_pb2.ClassificationLoss object. Returns: Loss based on the config. Raises: ValueError: On invalid loss_config. """ loss_type = loss_config.TYPE config = loss_config.VALUE if loss_type == "weighted_sigmoid": return losses.WeightedSigmoidClassificationLoss() elif loss_type == "weighted_sigmoid_focal": if config.alpha > 0: alpha = config.alpha else: alpha = None return losses.SigmoidFocalClassificationLoss(gamma=config.gamma, alpha=alpha) elif loss_type == "weighted_softmax_focal": if config.alpha > 0: alpha = config.alpha else: alpha = None return losses.SoftmaxFocalClassificationLoss(gamma=config.gamma, alpha=alpha) elif loss_type == "weighted_ghm": return GHMCLoss(bins=config.bins, momentum=config.momentum) elif loss_type == "weighted_softmax": return losses.WeightedSoftmaxClassificationLoss( logit_scale=config.logit_scale) elif loss_type == "bootstrapped_sigmoid": return losses.BootstrappedSigmoidClassificationLoss( alpha=config.alpha, bootstrap_type=("hard" if config.hard_bootstrap else "soft"), ) raise ValueError("Empty loss config.")