def gather_with_padding_values(input_tensor, indices, padding_value):
  """Gathers elements from tensor and pads `padding_value` for ignore indices.

  Gathers elements from `input_tensor` based on `indices`. If there are ignore
  indices (which are "-1"s) in `indices`, `padding_value` will be gathered for
  those positions.

  Args:
    input_tensor: A N-D tensor of shape [M, d_1, d_2 .. d_(N-1)] to gather
      values from.
    indices: A 1-D tensor in which each element is either an index in the
      first dimension of input_tensor or -1.
    padding_value: A (N-1)-D tensor of shape [d_1, d_2 .. d_(N-1)] which will be
      used as gathered value for each ignore index in `indices`.

  Returns:
    gathered_tensor: A tensor of shape [L, d_1, d_2 .. d_(N-1)] containing
      values gathered from input_tensor. The first dimension L is equal to the
      length of `indices`.
  """
  padding_value = tf.expand_dims(padding_value, axis=0)
  input_tensor = tf.concat([padding_value, input_tensor], axis=0)
  gather_indices = indices + 1
  gathered_tensor = tf.gather(input_tensor, gather_indices)
  return gathered_tensor
Gathers elements from tensor and pads `padding_value` for ignore indices.

  Gathers elements from `input_tensor` based on `indices`. If there are ignore
  indices (which are "-1"s) in `indices`, `padding_value` will be gathered for
  those positions.

  Args:
    input_tensor: A N-D tensor of shape [M, d_1, d_2 .. d_(N-1)] to gather
      values from.
    indices: A 1-D tensor in which each element is either an index in the
      first dimension of input_tensor or -1.
    padding_value: A (N-1)-D tensor of shape [d_1, d_2 .. d_(N-1)] which will be
      used as gathered value for each ignore index in `indices`.

  Returns:
    gathered_tensor: A tensor of shape [L, d_1, d_2 .. d_(N-1)] containing
      values gathered from input_tensor. The first dimension L is equal to the
      length of `indices`.
  
inference_api/src/main/object_detection/utils/ops.py