(image_list, crop_height, crop_width)
return [_crop(image, offset_height, offset_width,
                crop_height, crop_width) for image in image_list]
Crops the given list of images.

  The function applies the same crop to each image in the list. This can be
  effectively applied when there are multiple image inputs of the same
  dimension such as:

    image, depths, normals = _random_crop([image, depths, normals], 120, 150)

  Args:
    image_list: a list of image tensors of the same dimension but possibly
      varying channel.
    crop_height: the new height.
    crop_width: the new width.

  Returns:
    the image_list with cropped images.

  Raises:
    ValueError: if there are multiple image inputs provided with different size
      or the images are smaller than the crop dimensions.
Crops the given list of images.
Crops the given list of images .
def _random_crop(image_list, crop_height, crop_width):
  """Crops the given list of images.

  The function applies the same crop to each image in the list. This can be
  effectively applied when there are multiple image inputs of the same
  dimension such as:

    image, depths, normals = _random_crop([image, depths, normals], 120, 150)

  Args:
    image_list: a list of image tensors of the same dimension but possibly
      varying channel.
    crop_height: the new height.
    crop_width: the new width.

  Returns:
    the image_list with cropped images.

  Raises:
    ValueError: if there are multiple image inputs provided with different size
      or the images are smaller than the crop dimensions.
  """
  if not image_list:
    raise ValueError('Empty image_list.')

  # Compute the rank assertions.
  rank_assertions = []
  for i in range(len(image_list)):
    image_rank = tf.rank(image_list[i])
    rank_assert = tf.Assert(
        tf.equal(image_rank, 3),
        ['Wrong rank for tensor  %s [expected] [actual]',
         image_list[i].name, 3, image_rank])
    rank_assertions.append(rank_assert)

  with tf.control_dependencies([rank_assertions[0]]):
    image_shape = tf.shape(image_list[0])
  image_height = image_shape[0]
  image_width = image_shape[1]
  crop_size_assert = tf.Assert(
      tf.logical_and(
          tf.greater_equal(image_height, crop_height),
          tf.greater_equal(image_width, crop_width)),
      ['Crop size greater than the image size.'])

  asserts = [rank_assertions[0], crop_size_assert]

  for i in range(1, len(image_list)):
    image = image_list[i]
    asserts.append(rank_assertions[i])
    with tf.control_dependencies([rank_assertions[i]]):
      shape = tf.shape(image)
    height = shape[0]
    width = shape[1]

    height_assert = tf.Assert(
        tf.equal(height, image_height),
        ['Wrong height for tensor %s [expected][actual]',
         image.name, height, image_height])
    width_assert = tf.Assert(
        tf.equal(width, image_width),
        ['Wrong width for tensor %s [expected][actual]',
         image.name, width, image_width])
    asserts.extend([height_assert, width_assert])

  # Create a random bounding box.
  #
  # Use tf.random_uniform and not numpy.random.rand as doing the former would
  # generate random numbers at graph eval time, unlike the latter which
  # generates random numbers at graph definition time.
  with tf.control_dependencies(asserts):
    max_offset_height = tf.reshape(image_height - crop_height + 1, [])
  with tf.control_dependencies(asserts):
    max_offset_width = tf.reshape(image_width - crop_width + 1, [])
  offset_height = tf.random_uniform(
      [], maxval=max_offset_height, dtype=tf.int32)
  offset_width = tf.random_uniform(
      [], maxval=max_offset_width, dtype=tf.int32)

  return [_crop(image, offset_height, offset_width,
                crop_height, crop_width) for image in image_list]
def _random_crop ( image_list , crop_height , crop_width ) : if not image_list : raise ValueError ( 'Empty image_list.' ) # Compute the rank assertions. rank_assertions = [ ] for i in range ( len ( image_list ) ) : image_rank = tf . rank ( image_list [ i ] ) rank_assert = tf . Assert ( tf . equal ( image_rank , 3 ) , [ 'Wrong rank for tensor  %s [expected] [actual]' , image_list [ i ] . name , 3 , image_rank ] ) rank_assertions . append ( rank_assert ) with tf . control_dependencies ( [ rank_assertions [ 0 ] ] ) : image_shape = tf . shape ( image_list [ 0 ] ) image_height = image_shape [ 0 ] image_width = image_shape [ 1 ] crop_size_assert = tf . Assert ( tf . logical_and ( tf . greater_equal ( image_height , crop_height ) , tf . greater_equal ( image_width , crop_width ) ) , [ 'Crop size greater than the image size.' ] ) asserts = [ rank_assertions [ 0 ] , crop_size_assert ] for i in range ( 1 , len ( image_list ) ) : image = image_list [ i ] asserts . append ( rank_assertions [ i ] ) with tf . control_dependencies ( [ rank_assertions [ i ] ] ) : shape = tf . shape ( image ) height = shape [ 0 ] width = shape [ 1 ] height_assert = tf . Assert ( tf . equal ( height , image_height ) , [ 'Wrong height for tensor %s [expected][actual]' , image . name , height , image_height ] ) width_assert = tf . Assert ( tf . equal ( width , image_width ) , [ 'Wrong width for tensor %s [expected][actual]' , image . name , width , image_width ] ) asserts . extend ( [ height_assert , width_assert ] ) # Create a random bounding box. # # Use tf.random_uniform and not numpy.random.rand as doing the former would # generate random numbers at graph eval time, unlike the latter which # generates random numbers at graph definition time. with tf . control_dependencies ( asserts ) : max_offset_height = tf . reshape ( image_height - crop_height + 1 , [ ] ) with tf . control_dependencies ( asserts ) : max_offset_width = tf . reshape ( image_width - crop_width + 1 , [ ] ) offset_height = tf . random_uniform ( [ ] , maxval = max_offset_height , dtype = tf . int32 ) offset_width = tf . random_uniform ( [ ] , maxval = max_offset_width , dtype = tf . int32 ) return [ _crop ( image , offset_height , offset_width , crop_height , crop_width ) for image in image_list ]