def bbox_cutout(image, bboxes, pad_fraction, replace_with_mean):
    'Applies cutout to the image according to bbox information.\n\n  This is a cutout variant that using bbox information to make more informed\n  decisions on where to place the cutout mask.\n\n  Args:\n    image: 3D uint8 Tensor.\n    bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox\n      has 4 elements (min_y, min_x, max_y, max_x) of type float with values\n      between [0, 1].\n    pad_fraction: Float that specifies how large the cutout mask should be in\n      in reference to the size of the original bbox. If pad_fraction is 0.25,\n      then the cutout mask will be of shape\n      (0.25 * bbox height, 0.25 * bbox width).\n    replace_with_mean: Boolean that specified what value should be filled in\n      where the cutout mask is applied. Since the incoming image will be of\n      uint8 and will not have had any mean normalization applied, by default\n      we set the value to be 128. If replace_with_mean is True then we find\n      the mean pixel values across the channel dimension and use those to fill\n      in where the cutout mask is applied.\n\n  Returns:\n    A tuple. First element is a tensor of the same shape as image that has\n    cutout applied to it. Second element is the bboxes that were passed in\n    that will be unchanged.\n  '

    def apply_bbox_cutout(image, bboxes, pad_fraction):
        'Applies cutout to a single bounding box within image.'
        random_index = tf.random_uniform(shape=[], maxval=tf.shape(bboxes)[0], dtype=tf.int32)
        chosen_bbox = tf.gather(bboxes, random_index)
        (mask, mean) = _cutout_inside_bbox(image, chosen_bbox, pad_fraction)
        replace = (mean if replace_with_mean else 128)
        image = tf.where(tf.equal(mask, 0), tf.cast((tf.ones_like(image, dtype=image.dtype) * replace), dtype=image.dtype), image)
        return image
    image = tf.cond(tf.equal(tf.shape(bboxes)[0], 0), (lambda : image), (lambda : apply_bbox_cutout(image, bboxes, pad_fraction)))
    return (image, bboxes)
Applies cutout to the image according to bbox information.

This is a cutout variant that using bbox information to make more informed
decisions on where to place the cutout mask.

Args:
  image: 3D uint8 Tensor.
  bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox
    has 4 elements (min_y, min_x, max_y, max_x) of type float with values
    between [0, 1].
  pad_fraction: Float that specifies how large the cutout mask should be in
    in reference to the size of the original bbox. If pad_fraction is 0.25,
    then the cutout mask will be of shape
    (0.25 * bbox height, 0.25 * bbox width).
  replace_with_mean: Boolean that specified what value should be filled in
    where the cutout mask is applied. Since the incoming image will be of
    uint8 and will not have had any mean normalization applied, by default
    we set the value to be 128. If replace_with_mean is True then we find
    the mean pixel values across the channel dimension and use those to fill
    in where the cutout mask is applied.

Returns:
  A tuple. First element is a tensor of the same shape as image that has
  cutout applied to it. Second element is the bboxes that were passed in
  that will be unchanged.
def bbox_cutout(image, bboxes, pad_fraction, replace_with_mean):
    'Applies cutout to the image according to bbox information.\n\n  This is a cutout variant that using bbox information to make more informed\n  decisions on where to place the cutout mask.\n\n  Args:\n    image: 3D uint8 Tensor.\n    bboxes: 2D Tensor that is a list of the bboxes in the image. Each bbox\n      has 4 elements (min_y, min_x, max_y, max_x) of type float with values\n      between [0, 1].\n    pad_fraction: Float that specifies how large the cutout mask should be in\n      in reference to the size of the original bbox. If pad_fraction is 0.25,\n      then the cutout mask will be of shape\n      (0.25 * bbox height, 0.25 * bbox width).\n    replace_with_mean: Boolean that specified what value should be filled in\n      where the cutout mask is applied. Since the incoming image will be of\n      uint8 and will not have had any mean normalization applied, by default\n      we set the value to be 128. If replace_with_mean is True then we find\n      the mean pixel values across the channel dimension and use those to fill\n      in where the cutout mask is applied.\n\n  Returns:\n    A tuple. First element is a tensor of the same shape as image that has\n    cutout applied to it. Second element is the bboxes that were passed in\n    that will be unchanged.\n  '

    def apply_bbox_cutout(image, bboxes, pad_fraction):
        'Applies cutout to a single bounding box within image.'
        random_index = tf.random_uniform(shape=[], maxval=tf.shape(bboxes)[0], dtype=tf.int32)
        chosen_bbox = tf.gather(bboxes, random_index)
        (mask, mean) = _cutout_inside_bbox(image, chosen_bbox, pad_fraction)
        replace = (mean if replace_with_mean else 128)
        image = tf.where(tf.equal(mask, 0), tf.cast((tf.ones_like(image, dtype=image.dtype) * replace), dtype=image.dtype), image)
        return image
    image = tf.cond(tf.equal(tf.shape(bboxes)[0], 0), (lambda : image), (lambda : apply_bbox_cutout(image, bboxes, pad_fraction)))
    return (image, bboxes)