slim/preprocessing/vgg_preprocessing.py
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(input=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(input=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]
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.
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)
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 )
def _random_crop(image_list, crop_height, crop_width):
  if not image_list:
    raise ValueError('Empty image_list.')
  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(input=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(input=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])
   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.' ) 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 ( input = 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 ( input = 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 ] ) 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 ]
Crops the given list of images.
Crops the given list of images .
"""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.
  """ # Compute the rank assertions. # 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.
the image_list with cropped images.
the image_list with cropped images .
if there are multiple image inputs provided with different size
or the images are smaller than the crop dimensions.
if there are multiple image inputs provided with different size or the images are smaller than the crop dimensions .
ValueError
image_list
a list of image tensors of the same dimension but possibly
varying channel.
a list of image tensors of the same dimension but possibly varying channel .
crop_height
the new height.
the new height .
crop_width
the new width.
the new width .