(image, offset_height, offset_width, crop_height, crop_width)
return tf.reshape(image, cropped_shape)
Crops the given image using the provided offsets and sizes.

  Note that the method doesn't assume we know the input image size but it does
  assume we know the input image rank.

  Args:
    image: an image of shape [height, width, channels].
    offset_height: a scalar tensor indicating the height offset.
    offset_width: a scalar tensor indicating the width offset.
    crop_height: the height of the cropped image.
    crop_width: the width of the cropped image.

  Returns:
    the cropped (and resized) image.

  Raises:
    InvalidArgumentError: if the rank is not 3 or if the image dimensions are
      less than the crop size.
Crops the given image using the provided offsets and sizes.
Crops the given image using the provided offsets and sizes .
def _crop(image, offset_height, offset_width, crop_height, crop_width):
  """Crops the given image using the provided offsets and sizes.

  Note that the method doesn't assume we know the input image size but it does
  assume we know the input image rank.

  Args:
    image: an image of shape [height, width, channels].
    offset_height: a scalar tensor indicating the height offset.
    offset_width: a scalar tensor indicating the width offset.
    crop_height: the height of the cropped image.
    crop_width: the width of the cropped image.

  Returns:
    the cropped (and resized) image.

  Raises:
    InvalidArgumentError: if the rank is not 3 or if the image dimensions are
      less than the crop size.
  """
  original_shape = tf.shape(image)

  rank_assertion = tf.Assert(
      tf.equal(tf.rank(image), 3),
      ['Rank of image must be equal to 3.'])
  with tf.control_dependencies([rank_assertion]):
    cropped_shape = tf.stack([crop_height, crop_width, original_shape[2]])

  size_assertion = tf.Assert(
      tf.logical_and(
          tf.greater_equal(original_shape[0], crop_height),
          tf.greater_equal(original_shape[1], crop_width)),
      ['Crop size greater than the image size.'])

  offsets = tf.to_int32(tf.stack([offset_height, offset_width, 0]))

  # Use tf.strided_slice instead of crop_to_bounding box as it accepts tensors
  # to define the crop size.
  with tf.control_dependencies([size_assertion]):
    image = tf.strided_slice(image, offsets, offsets + cropped_shape,
                             strides=tf.ones_like(offsets))
  return tf.reshape(image, cropped_shape)
def _crop ( image , offset_height , offset_width , crop_height , crop_width ) : original_shape = tf . shape ( image ) rank_assertion = tf . Assert ( tf . equal ( tf . rank ( image ) , 3 ) , [ 'Rank of image must be equal to 3.' ] ) with tf . control_dependencies ( [ rank_assertion ] ) : cropped_shape = tf . stack ( [ crop_height , crop_width , original_shape [ 2 ] ] ) size_assertion = tf . Assert ( tf . logical_and ( tf . greater_equal ( original_shape [ 0 ] , crop_height ) , tf . greater_equal ( original_shape [ 1 ] , crop_width ) ) , [ 'Crop size greater than the image size.' ] ) offsets = tf . to_int32 ( tf . stack ( [ offset_height , offset_width , 0 ] ) ) # Use tf.strided_slice instead of crop_to_bounding box as it accepts tensors # to define the crop size. with tf . control_dependencies ( [ size_assertion ] ) : image = tf . strided_slice ( image , offsets , offsets + cropped_shape , strides = tf . ones_like ( offsets ) ) return tf . reshape ( image , cropped_shape )