def get_num_instances_from_weights(groundtruth_weights_list):
    'Computes the number of instances/boxes from the weights in a batch.\n\n  Args:\n    groundtruth_weights_list: A list of float tensors with shape\n      [max_num_instances] representing whether there is an actual instance in\n      the image (with non-zero value) or is padded to match the\n      max_num_instances (with value 0.0). The list represents the batch\n      dimension.\n\n  Returns:\n    A scalar integer tensor incidating how many instances/boxes are in the\n    images in the batch. Note that this function is usually used to normalize\n    the loss so the minimum return value is 1 to avoid weird behavior.\n  '
    num_instances = tf.reduce_sum([tf.math.count_nonzero(w) for w in groundtruth_weights_list])
    num_instances = tf.maximum(num_instances, 1)
    return num_instances
Computes the number of instances/boxes from the weights in a batch.

Args:
  groundtruth_weights_list: A list of float tensors with shape
    [max_num_instances] representing whether there is an actual instance in
    the image (with non-zero value) or is padded to match the
    max_num_instances (with value 0.0). The list represents the batch
    dimension.

Returns:
  A scalar integer tensor incidating how many instances/boxes are in the
  images in the batch. Note that this function is usually used to normalize
  the loss so the minimum return value is 1 to avoid weird behavior.
def get_num_instances_from_weights(groundtruth_weights_list):
    'Computes the number of instances/boxes from the weights in a batch.\n\n  Args:\n    groundtruth_weights_list: A list of float tensors with shape\n      [max_num_instances] representing whether there is an actual instance in\n      the image (with non-zero value) or is padded to match the\n      max_num_instances (with value 0.0). The list represents the batch\n      dimension.\n\n  Returns:\n    A scalar integer tensor incidating how many instances/boxes are in the\n    images in the batch. Note that this function is usually used to normalize\n    the loss so the minimum return value is 1 to avoid weird behavior.\n  '
    num_instances = tf.reduce_sum([tf.math.count_nonzero(w) for w in groundtruth_weights_list])
    num_instances = tf.maximum(num_instances, 1)
    return num_instances