def crop_image_from_xy(image, crop_location, crop_size, scale=1.0):
    '\n    Crops an image. When factor is not given does an central crop.\n\n    Inputs:\n        image: 4D tensor, [batch, height, width, channels] which will be cropped in height and width dimension\n        crop_location: tensor, [batch, 2] which represent the height and width location of the crop\n        crop_size: int, describes the extension of the crop\n    Outputs:\n        image_crop: 4D tensor, [batch, crop_size, crop_size, channels]\n    '
    with tf.name_scope('crop_image_from_xy'):
        s = image.get_shape().as_list()
        assert (len(s) == 4), 'Image needs to be of shape [batch, width, height, channel]'
        scale = tf.reshape(scale, [(- 1)])
        crop_location = tf.cast(crop_location, tf.float32)
        crop_location = tf.reshape(crop_location, [s[0], 2])
        crop_size = tf.cast(crop_size, tf.float32)
        crop_size_scaled = (crop_size / scale)
        y1 = (crop_location[:, 0] - (crop_size_scaled // 2))
        y2 = (y1 + crop_size_scaled)
        x1 = (crop_location[:, 1] - (crop_size_scaled // 2))
        x2 = (x1 + crop_size_scaled)
        y1 /= s[1]
        y2 /= s[1]
        x1 /= s[2]
        x2 /= s[2]
        boxes = tf.stack([y1, x1, y2, x2], (- 1))
        crop_size = tf.cast(tf.stack([crop_size, crop_size]), tf.int32)
        box_ind = tf.range(s[0])
        image_c = tf.image.crop_and_resize(tf.cast(image, tf.float32), boxes, box_ind, crop_size, name='crop')
        return image_c
Crops an image. When factor is not given does an central crop.

Inputs:
    image: 4D tensor, [batch, height, width, channels] which will be cropped in height and width dimension
    crop_location: tensor, [batch, 2] which represent the height and width location of the crop
    crop_size: int, describes the extension of the crop
Outputs:
    image_crop: 4D tensor, [batch, crop_size, crop_size, channels]
def crop_image_from_xy(image, crop_location, crop_size, scale=1.0):
    '\n    Crops an image. When factor is not given does an central crop.\n\n    Inputs:\n        image: 4D tensor, [batch, height, width, channels] which will be cropped in height and width dimension\n        crop_location: tensor, [batch, 2] which represent the height and width location of the crop\n        crop_size: int, describes the extension of the crop\n    Outputs:\n        image_crop: 4D tensor, [batch, crop_size, crop_size, channels]\n    '
    with tf.name_scope('crop_image_from_xy'):
        s = image.get_shape().as_list()
        assert (len(s) == 4), 'Image needs to be of shape [batch, width, height, channel]'
        scale = tf.reshape(scale, [(- 1)])
        crop_location = tf.cast(crop_location, tf.float32)
        crop_location = tf.reshape(crop_location, [s[0], 2])
        crop_size = tf.cast(crop_size, tf.float32)
        crop_size_scaled = (crop_size / scale)
        y1 = (crop_location[:, 0] - (crop_size_scaled // 2))
        y2 = (y1 + crop_size_scaled)
        x1 = (crop_location[:, 1] - (crop_size_scaled // 2))
        x2 = (x1 + crop_size_scaled)
        y1 /= s[1]
        y2 /= s[1]
        x1 /= s[2]
        x2 /= s[2]
        boxes = tf.stack([y1, x1, y2, x2], (- 1))
        crop_size = tf.cast(tf.stack([crop_size, crop_size]), tf.int32)
        box_ind = tf.range(s[0])
        image_c = tf.image.crop_and_resize(tf.cast(image, tf.float32), boxes, box_ind, crop_size, name='crop')
        return image_c