def apply_bbox_cutout(image, bboxes, pad_fraction):
    """Applies cutout to a single bounding box within image."""
    # Choose a single bounding box to apply cutout to.
    random_index = tf.random_uniform(
        shape=[], maxval=tf.shape(bboxes)[0], dtype=tf.int32)
    # Select the corresponding bbox and apply cutout.
    chosen_bbox = tf.gather(bboxes, random_index)
    mask, mean = _cutout_inside_bbox(image, chosen_bbox, pad_fraction)

    # When applying cutout we either set the pixel value to 128 or to the mean
    # value inside the bbox.
    replace = mean if replace_with_mean else 128

    # Apply the cutout mask to the image. Where the mask is 0 we fill it with
    # `replace`.
    image = tf.where(
        tf.equal(mask, 0),
        tf.cast(tf.ones_like(image, dtype=image.dtype) * replace,
                dtype=image.dtype),
        image)
    return image
Applies cutout to a single bounding box within image.
inference_api/src/main/object_detection/utils/autoaugment_utils.py