def get_valid_anchor_weights_in_flattened_image(true_image_shapes, height, width):
    'Computes valid anchor weights for an image assuming pixels will be flattened.\n\n  This function is useful when we only want to penalize valid areas in the\n  image in the case when padding is used. The function assumes that the loss\n  function will be applied after flattening the spatial dimensions and returns\n  anchor weights accordingly.\n\n  Args:\n    true_image_shapes: An integer tensor of shape [batch_size, 3] representing\n      the true image shape (without padding) for each sample in the batch.\n    height: height of the prediction from the network.\n    width: width of the prediction from the network.\n\n  Returns:\n    valid_anchor_weights: a float tensor of shape [batch_size, height * width]\n    with 1s in locations where the spatial coordinates fall within the height\n    and width in true_image_shapes.\n  '
    indices = tf.reshape(tf.range((height * width)), [1, (- 1)])
    batch_size = tf.shape(true_image_shapes)[0]
    batch_indices = (tf.ones((batch_size, 1), dtype=tf.int32) * indices)
    (y_coords, x_coords, _) = row_col_channel_indices_from_flattened_indices(batch_indices, width, 1)
    (max_y, max_x) = (true_image_shapes[:, 0], true_image_shapes[:, 1])
    max_x = _to_float32(tf.expand_dims(max_x, 1))
    max_y = _to_float32(tf.expand_dims(max_y, 1))
    x_coords = _to_float32(x_coords)
    y_coords = _to_float32(y_coords)
    valid_mask = tf.math.logical_and((x_coords < max_x), (y_coords < max_y))
    return _to_float32(valid_mask)
Computes valid anchor weights for an image assuming pixels will be flattened.

This function is useful when we only want to penalize valid areas in the
image in the case when padding is used. The function assumes that the loss
function will be applied after flattening the spatial dimensions and returns
anchor weights accordingly.

Args:
  true_image_shapes: An integer tensor of shape [batch_size, 3] representing
    the true image shape (without padding) for each sample in the batch.
  height: height of the prediction from the network.
  width: width of the prediction from the network.

Returns:
  valid_anchor_weights: a float tensor of shape [batch_size, height * width]
  with 1s in locations where the spatial coordinates fall within the height
  and width in true_image_shapes.
def get_valid_anchor_weights_in_flattened_image(true_image_shapes, height, width):
    'Computes valid anchor weights for an image assuming pixels will be flattened.\n\n  This function is useful when we only want to penalize valid areas in the\n  image in the case when padding is used. The function assumes that the loss\n  function will be applied after flattening the spatial dimensions and returns\n  anchor weights accordingly.\n\n  Args:\n    true_image_shapes: An integer tensor of shape [batch_size, 3] representing\n      the true image shape (without padding) for each sample in the batch.\n    height: height of the prediction from the network.\n    width: width of the prediction from the network.\n\n  Returns:\n    valid_anchor_weights: a float tensor of shape [batch_size, height * width]\n    with 1s in locations where the spatial coordinates fall within the height\n    and width in true_image_shapes.\n  '
    indices = tf.reshape(tf.range((height * width)), [1, (- 1)])
    batch_size = tf.shape(true_image_shapes)[0]
    batch_indices = (tf.ones((batch_size, 1), dtype=tf.int32) * indices)
    (y_coords, x_coords, _) = row_col_channel_indices_from_flattened_indices(batch_indices, width, 1)
    (max_y, max_x) = (true_image_shapes[:, 0], true_image_shapes[:, 1])
    max_x = _to_float32(tf.expand_dims(max_x, 1))
    max_y = _to_float32(tf.expand_dims(max_y, 1))
    x_coords = _to_float32(x_coords)
    y_coords = _to_float32(y_coords)
    valid_mask = tf.math.logical_and((x_coords < max_x), (y_coords < max_y))
    return _to_float32(valid_mask)