import tensorflow as tf

  upper_pad = tf.maximum(0, image_height - cutout_center_height - length // 2)
  left_pad = tf.maximum(0, cutout_center_width - length // 2)
  right_pad = tf.maximum(0, image_width - cutout_center_width - length // 2)

  cutout_shape = [image_height - (lower_pad + upper_pad),
                  image_width - (left_pad + right_pad)]

  padding_dims = [[lower_pad, upper_pad], [left_pad, right_pad]]

  mask = tf.pad(
      tf.zeros(cutout_shape, dtype=images.dtype),
      padding_dims, constant_values=1)

  patch = tf.ones_like(images, dtype=images.dtype) * replace,

  mask = tf.expand_dims(mask, -1)
  mask = tf.tile(mask, [1, 1, num_channels])

  images = tf.where(
      tf.equal(mask, 0),
