(image, target_image_shape, crop_method, seed, random_flip)
return image
Preprocesses ImageNet images to have a target image shape.

  Args:
    image: 3-D tensor with a single image.
    target_image_shape: List/Tuple with target image shape.
    crop_method: Method for cropping the image:
      One of: distorted, random, middle, none
    seed: Random seed, only used for `crop_method=distorted`.

  Returns:
    Image tensor with shape `target_image_shape`.
Preprocesses ImageNet images to have a target image shape.
Preprocesses ImageNet images to have a target image shape .
def _transform_imagnet_image(image, target_image_shape, crop_method, seed, random_flip):
  """Preprocesses ImageNet images to have a target image shape.

  Args:
    image: 3-D tensor with a single image.
    target_image_shape: List/Tuple with target image shape.
    crop_method: Method for cropping the image:
      One of: distorted, random, middle, none
    seed: Random seed, only used for `crop_method=distorted`.

  Returns:
    Image tensor with shape `target_image_shape`.
  """
  if crop_method == "distorted":
    begin, size, _ = tf.image.sample_distorted_bounding_box(
        tf.shape(image),
        tf.zeros([0, 0, 4], tf.float32),
        aspect_ratio_range=[1.0, 1.0],
        area_range=[0.5, 1.0],
        use_image_if_no_bounding_boxes=True,
        seed=seed)
    image = tf.slice(image, begin, size)
    # Unfortunately, the above operation loses the depth-dimension. So we need
    # to restore it the manual way.
    image.set_shape([None, None, target_image_shape[-1]])
  elif crop_method == "random":
    tf.set_random_seed(seed)
    shape = tf.shape(image)
    h, w = shape[0], shape[1]
    size = tf.minimum(h, w)
    begin = [h - size, w - size] * tf.random.uniform([2], 0, 1)
    begin = tf.cast(begin, tf.int32)
    begin = tf.concat([begin, [0]], axis=0)  # Add channel dimension.
    image = tf.slice(image, begin, [size, size, 3])
  elif crop_method == "middle":
    shape = tf.shape(image)
    h, w = shape[0], shape[1]
    size = tf.minimum(h, w)
    begin = tf.cast([h - size, w - size], tf.float32) / 2.0
    begin = tf.cast(begin, tf.int32)
    begin = tf.concat([begin, [0]], axis=0)  # Add channel dimension.
    image = tf.slice(image, begin, [size, size, 3])
  elif crop_method == "zoomed":
    shape = tf.shape(image)
    h, w = shape[0], shape[1]
    size = tf.minimum(h, w)
    begin, size, _ = tf.image.sample_distorted_bounding_box(
        [size, size, shape[2]],
        tf.zeros([0, 0, 4], tf.float32),
        aspect_ratio_range=[1.0, 1.0],
        area_range=[0.5, 1.0],
        use_image_if_no_bounding_boxes=True,
        seed=seed)
    begin = tf.cast([h - size[0], w - size[1], 0], tf.int32) // 2
    image = tf.slice(image, begin, size)
    # Unfortunately, the above operation loses the depth-dimension. So we need
    # to restore it the manual way.
    image.set_shape([None, None, target_image_shape[-1]])
  elif crop_method != "none":
    raise ValueError("Unsupported crop method: {}".format(crop_method))
  image = tf.image.resize_images(
      image, [target_image_shape[0], target_image_shape[1]])
  if random_flip:
    image = tf.image.random_flip_left_right(image, seed=seed)
  image.set_shape(target_image_shape)
  return image
def _transform_imagnet_image ( image , target_image_shape , crop_method , seed , random_flip ) : if crop_method == "distorted" : begin , size , _ = tf . image . sample_distorted_bounding_box ( tf . shape ( image ) , tf . zeros ( [ 0 , 0 , 4 ] , tf . float32 ) , aspect_ratio_range = [ 1.0 , 1.0 ] , area_range = [ 0.5 , 1.0 ] , use_image_if_no_bounding_boxes = True , seed = seed ) image = tf . slice ( image , begin , size ) # Unfortunately, the above operation loses the depth-dimension. So we need # to restore it the manual way. image . set_shape ( [ None , None , target_image_shape [ - 1 ] ] ) elif crop_method == "random" : tf . set_random_seed ( seed ) shape = tf . shape ( image ) h , w = shape [ 0 ] , shape [ 1 ] size = tf . minimum ( h , w ) begin = [ h - size , w - size ] * tf . random . uniform ( [ 2 ] , 0 , 1 ) begin = tf . cast ( begin , tf . int32 ) begin = tf . concat ( [ begin , [ 0 ] ] , axis = 0 ) # Add channel dimension. image = tf . slice ( image , begin , [ size , size , 3 ] ) elif crop_method == "middle" : shape = tf . shape ( image ) h , w = shape [ 0 ] , shape [ 1 ] size = tf . minimum ( h , w ) begin = tf . cast ( [ h - size , w - size ] , tf . float32 ) / 2.0 begin = tf . cast ( begin , tf . int32 ) begin = tf . concat ( [ begin , [ 0 ] ] , axis = 0 ) # Add channel dimension. image = tf . slice ( image , begin , [ size , size , 3 ] ) elif crop_method == "zoomed" : shape = tf . shape ( image ) h , w = shape [ 0 ] , shape [ 1 ] size = tf . minimum ( h , w ) begin , size , _ = tf . image . sample_distorted_bounding_box ( [ size , size , shape [ 2 ] ] , tf . zeros ( [ 0 , 0 , 4 ] , tf . float32 ) , aspect_ratio_range = [ 1.0 , 1.0 ] , area_range = [ 0.5 , 1.0 ] , use_image_if_no_bounding_boxes = True , seed = seed ) begin = tf . cast ( [ h - size [ 0 ] , w - size [ 1 ] , 0 ] , tf . int32 ) // 2 image = tf . slice ( image , begin , size ) # Unfortunately, the above operation loses the depth-dimension. So we need # to restore it the manual way. image . set_shape ( [ None , None , target_image_shape [ - 1 ] ] ) elif crop_method != "none" : raise ValueError ( "Unsupported crop method: {}" . format ( crop_method ) ) image = tf . image . resize_images ( image , [ target_image_shape [ 0 ] , target_image_shape [ 1 ] ] ) if random_flip : image = tf . image . random_flip_left_right ( image , seed = seed ) image . set_shape ( target_image_shape ) return image