(image, crop_size)
Returns a central crop for the specified size of an image.

  Args:
    image: A tensor with shape [height, width, channels]
    crop_size: A tuple (crop_width, crop_height)

  Returns:
    A tensor of shape [crop_height, crop_width, channels].
Returns a central crop for the specified size of an image.
Returns a central crop for the specified size of an image .
def central_crop(image, crop_size):
  """Returns a central crop for the specified size of an image.

  Args:
    image: A tensor with shape [height, width, channels]
    crop_size: A tuple (crop_width, crop_height)

  Returns:
    A tensor of shape [crop_height, crop_width, channels].
  """
  with tf.variable_scope('CentralCrop'):
    target_width, target_height = crop_size
    image_height, image_width = tf.shape(image)[0], tf.shape(image)[1]
    assert_op1 = tf.Assert(
        tf.greater_equal(image_height, target_height),
        ['image_height < target_height', image_height, target_height])
    assert_op2 = tf.Assert(
        tf.greater_equal(image_width, target_width),
        ['image_width < target_width', image_width, target_width])
    with tf.control_dependencies([assert_op1, assert_op2]):
      offset_width = (image_width - target_width) / 2
      offset_height = (image_height - target_height) / 2
      return tf.image.crop_to_bounding_box(image, offset_height, offset_width,
                                           target_height, target_width)
def central_crop ( image , crop_size ) : with tf . variable_scope ( 'CentralCrop' ) : target_width , target_height = crop_size image_height , image_width = tf . shape ( image ) [ 0 ] , tf . shape ( image ) [ 1 ] assert_op1 = tf . Assert ( tf . greater_equal ( image_height , target_height ) , [ 'image_height < target_height' , image_height , target_height ] ) assert_op2 = tf . Assert ( tf . greater_equal ( image_width , target_width ) , [ 'image_width < target_width' , image_width , target_width ] ) with tf . control_dependencies ( [ assert_op1 , assert_op2 ] ) : offset_width = ( image_width - target_width ) / 2 offset_height = ( image_height - target_height ) / 2 return tf . image . crop_to_bounding_box ( image , offset_height , offset_width , target_height , target_width )