code: def random_crop_and_flip(x, pad_rows=4, pad_cols=4):
    
    rows = tf.shape(x)[1]
    cols = tf.shape(x)[2]
    channels = x.get_shape()[3]
  
    def _rand_crop_img(img):
      """Randomly crop an individual image"""
      return tf.random_crop(img, [rows, cols, channels])
  
    # Some of these ops are only on CPU.
    # This function will often be called with the device set to GPU.
    # We need to set it to CPU temporarily to avoid an exception.
    with tf.device('/CPU:0'):
      x = tf.image.resize_image_with_crop_or_pad(x, rows + pad_rows,
                                                 cols + pad_cols)
      x = tf.map_fn(_rand_crop_img, x)
      x = tf.image.random_flip_left_right(x)
    return x
docs: Augment a batch by randomly cropping and horizontally flipping it.