コード例 #1
0
def box_classification_loss(inputs,
                            outputs,
                            is_intermediate=False,
                            is_balanced=False,
                            mine_hard_negatives=False,
                            hard_negative_score_threshold=0.5):
    """Calculates the voxel level classification loss.

  Args:
    inputs: A dictionary of tf.Tensors with our input label data.
    outputs: A dictionary of tf.Tensors with the network output.
    is_intermediate: If True, loss will be computed on intermediate tensors.
    is_balanced: If True, the per-voxel losses are re-weighted to have equal
      total weight for foreground vs. background voxels.
    mine_hard_negatives: If True, mines hard negatives and applies loss on them
      too.
    hard_negative_score_threshold: A prediction is a hard negative if its label
      is 0 and the score for the 0 class is less than this threshold.

  Returns:
    loss: A tf.float32 scalar corresponding to softmax classification loss.

  Raises:
    ValueError: If the size of the third dimension of the predicted logits is
      unknown at graph construction.
  """
    return loss_utils.apply_unbatched_loss_on_voxel_tensors(
        inputs=inputs,
        outputs=outputs,
        unbatched_loss_fn=functools.partial(
            _box_classification_loss_unbatched,
            is_intermediate=is_intermediate,
            is_balanced=is_balanced,
            mine_hard_negatives=mine_hard_negatives,
            hard_negative_score_threshold=hard_negative_score_threshold))
コード例 #2
0
def box_classification_using_center_distance_loss(
        inputs,
        outputs,
        is_intermediate=False,
        is_balanced=False,
        max_positive_normalized_distance=0.3):
    """Calculates the loss based on predicted center distance from gt center.

  Computes the loss using the object properties of the voxel tensors.

  Args:
    inputs: A dictionary of tf.Tensors with our input label data.
    outputs: A dictionary of tf.Tensors with the network output.
    is_intermediate: If True, loss will be computed on intermediate tensors.
    is_balanced: If True, the per-voxel losses are re-weighted to have equal
      total weight for foreground vs. background voxels.
    max_positive_normalized_distance: Maximum distance of a predicted box from
      the ground-truth box that we use to classify the predicted box as
      positive.

  Returns:
    loss: A tf.float32 scalar corresponding to distance confidence loss.
  """
    return loss_utils.apply_unbatched_loss_on_voxel_tensors(
        inputs=inputs,
        outputs=outputs,
        unbatched_loss_fn=functools.partial(
            _box_classification_using_center_distance_loss_unbatched,
            is_intermediate=is_intermediate,
            is_balanced=is_balanced,
            max_positive_normalized_distance=max_positive_normalized_distance))
コード例 #3
0
def box_corner_distance_loss_on_voxel_tensors(
    inputs,
    outputs,
    loss_type,
    delta=1.0,
    is_balanced=False,
    is_intermediate=False):
  """Computes regression loss on object corner locations using object tensors.

  Args:
    inputs: A dictionary of tf.Tensors with our input data.
    outputs: A dictionary of tf.Tensors with the network output.
    loss_type: Loss type.
    delta: float, the voxel where the huber loss function changes from a
      quadratic to linear.
    is_balanced: If True, the per-voxel losses are re-weighted to have equal
      total weight for each object instance.
    is_intermediate: If True, intermediate tensors are used for computing
      the loss.

  Returns:
    localization_loss: A tf.float32 scalar corresponding to localization loss.
  """
  standard_fields.check_input_voxel_fields(inputs=inputs)
  standard_fields.check_output_voxel_fields(outputs=outputs)

  def fn(inputs_1, outputs_1):
    return _box_corner_distance_loss_on_voxel_tensors_unbatched(
        inputs_1=inputs_1,
        outputs_1=outputs_1,
        loss_type=loss_type,
        delta=delta,
        is_balanced=is_balanced,
        is_intermediate=is_intermediate)

  return loss_utils.apply_unbatched_loss_on_voxel_tensors(
      inputs=inputs, outputs=outputs, unbatched_loss_fn=fn)
コード例 #4
0
def hard_negative_classification_loss(inputs,
                                      outputs,
                                      is_intermediate=False,
                                      gamma=1.0):
    """Calculates the loss based on predicted center distance from gt center.

  Computes the loss using the object properties of the voxel tensors.

  Args:
    inputs: A dictionary of tf.Tensors with our input label data.
    outputs: A dictionary of tf.Tensors with the network output.
    is_intermediate: If True, loss will be computed on intermediate tensors.
    gamma: Gamma similar to how it is used in focal loss.

  Returns:
    loss: A tf.float32 scalar corresponding to distance confidence loss.
  """
    return loss_utils.apply_unbatched_loss_on_voxel_tensors(
        inputs=inputs,
        outputs=outputs,
        unbatched_loss_fn=functools.partial(
            _voxel_hard_negative_classification_loss_unbatched,
            is_intermediate=is_intermediate,
            gamma=gamma))