(encoded_image,
                  is_training,
                  height,
                  width,
                  resize_height=346,
                  resize_width=346,
                  thread_id=0,
                  image_format="jpeg")
return image
Decode an image, resize and apply random distortions.

  In training, images are distorted slightly differently depending on thread_id.

  Args:
    encoded_image: String Tensor containing the image.
    is_training: Boolean; whether preprocessing for training or eval.
    height: Height of the output image.
    width: Width of the output image.
    resize_height: If > 0, resize height before crop to final dimensions.
    resize_width: If > 0, resize width before crop to final dimensions.
    thread_id: Preprocessing thread id used to select the ordering of color
      distortions. There should be a multiple of 2 preprocessing threads.
    image_format: "jpeg" or "png".

  Returns:
    A float32 Tensor of shape [height, width, 3] with values in [-1, 1].

  Raises:
    ValueError: If image_format is invalid.
Decode an image, resize and apply random distortions.
Decode an image resize and apply random distortions .
def process_image(encoded_image,
                  is_training,
                  height,
                  width,
                  resize_height=346,
                  resize_width=346,
                  thread_id=0,
                  image_format="jpeg"):
  """Decode an image, resize and apply random distortions.

  In training, images are distorted slightly differently depending on thread_id.

  Args:
    encoded_image: String Tensor containing the image.
    is_training: Boolean; whether preprocessing for training or eval.
    height: Height of the output image.
    width: Width of the output image.
    resize_height: If > 0, resize height before crop to final dimensions.
    resize_width: If > 0, resize width before crop to final dimensions.
    thread_id: Preprocessing thread id used to select the ordering of color
      distortions. There should be a multiple of 2 preprocessing threads.
    image_format: "jpeg" or "png".

  Returns:
    A float32 Tensor of shape [height, width, 3] with values in [-1, 1].

  Raises:
    ValueError: If image_format is invalid.
  """
  # Helper function to log an image summary to the visualizer. Summaries are
  # only logged in thread 0.
  def image_summary(name, image):
    if not thread_id:
      tf.summary.image(name, tf.expand_dims(image, 0))

  # Decode image into a float32 Tensor of shape [?, ?, 3] with values in [0, 1).
  with tf.name_scope("decode", values=[encoded_image]):
    if image_format == "jpeg":
      image = tf.image.decode_jpeg(encoded_image, channels=3)
    elif image_format == "png":
      image = tf.image.decode_png(encoded_image, channels=3)
    else:
      raise ValueError("Invalid image format: %s" % image_format)
  image = tf.image.convert_image_dtype(image, dtype=tf.float32)
  image_summary("original_image", image)

  # Resize image.
  assert (resize_height > 0) == (resize_width > 0)
  if resize_height:
    image = tf.image.resize_images(image,
                                   size=[resize_height, resize_width],
                                   method=tf.image.ResizeMethod.BILINEAR)

  # Crop to final dimensions.
  if is_training:
    image = tf.random_crop(image, [height, width, 3])
  else:
    # Central crop, assuming resize_height > height, resize_width > width.
    image = tf.image.resize_image_with_crop_or_pad(image, height, width)

  image_summary("resized_image", image)

  # Randomly distort the image.
  if is_training:
    image = distort_image(image, thread_id)

  image_summary("final_image", image)

  # Rescale to [-1,1] instead of [0, 1]
  image = tf.subtract(image, 0.5)
  image = tf.multiply(image, 2.0)
  return image
def process_image ( encoded_image , is_training , height , width , resize_height = 346 , resize_width = 346 , thread_id = 0 , image_format = "jpeg" ) : # Helper function to log an image summary to the visualizer. Summaries are # only logged in thread 0. def image_summary ( name , image ) : if not thread_id : tf . summary . image ( name , tf . expand_dims ( image , 0 ) ) # Decode image into a float32 Tensor of shape [?, ?, 3] with values in [0, 1). with tf . name_scope ( "decode" , values = [ encoded_image ] ) : if image_format == "jpeg" : image = tf . image . decode_jpeg ( encoded_image , channels = 3 ) elif image_format == "png" : image = tf . image . decode_png ( encoded_image , channels = 3 ) else : raise ValueError ( "Invalid image format: %s" % image_format ) image = tf . image . convert_image_dtype ( image , dtype = tf . float32 ) image_summary ( "original_image" , image ) # Resize image. assert ( resize_height > 0 ) == ( resize_width > 0 ) if resize_height : image = tf . image . resize_images ( image , size = [ resize_height , resize_width ] , method = tf . image . ResizeMethod . BILINEAR ) # Crop to final dimensions. if is_training : image = tf . random_crop ( image , [ height , width , 3 ] ) else : # Central crop, assuming resize_height > height, resize_width > width. image = tf . image . resize_image_with_crop_or_pad ( image , height , width ) image_summary ( "resized_image" , image ) # Randomly distort the image. if is_training : image = distort_image ( image , thread_id ) image_summary ( "final_image" , image ) # Rescale to [-1,1] instead of [0, 1] image = tf . subtract ( image , 0.5 ) image = tf . multiply ( image , 2.0 ) return image