utils/tf_image_processing.py
def preprocess(image, ground_truth, out_size, mean, is_training):
  """ Preprocess image and ground truth annotation.

  Args:
    image: 3-D Tensor of shape (num_rows, num_columns, num_channels) (HWC).
    ground_truth: 3-D Tensor of shape (num_rows, num_columns, num_channels)
        (HWC).
    out_size: Tuple of Int. Output height and width of the preprocessed image.
    mean: Python array or 1-D Tensor with the same length as the number of
        channels of `image`.
    is_training: Bool. If `True` the image and ground truth annotation will be
        augmented using shifting, left/right flipping and rotation.

    Returns:
      Tuple of 3-D Tensors: `image` and `ground_truth` tensors of shape
          (`height`, `width`, -1).
  """
  mean = tf.convert_to_tensor(mean, dtype=tf.float32)

  # TODO: Images and ground_truth should also have the possibility to be a
  #       4-D Tensor
  image = tf.convert_to_tensor(image)
  depth_i = image.shape.as_list()[2]

  if ground_truth is not None:
    ground_truth = tf.convert_to_tensor(ground_truth)
    depth_ground_truth = ground_truth.shape.as_list()[2]
  else:
    ground_truth = None
    depth_ground_truth = 0

  out_height, out_width = out_size

  if is_training:
    # Combine images so that we can randomly crop only one matrix for both
    # Image and ground truth label
    combined = tf.concat([image, ground_truth], axis=2)

    combined = tf.random_crop(
      combined, [out_height, out_width, depth_i + depth_ground_truth])

    # combined = tf.image.random_flip_left_right(combined)

    image = combined[:, :, :depth_i]
    ground_truth = combined[:, :, depth_i:]

    # NOTE: since per_image_standardization zeros the mean and makes
    # the stddev unit, this likely has no effect see tensorflow#1458.
    image = tf.cast(image, dtype=tf.float32)
    image = tf.image.random_brightness(image, max_delta=1.2)
    image = tf.image.random_contrast(image, lower=0.8, upper=1.2)
  else:
    image = tf.image.resize_image_with_crop_or_pad(image, out_height, out_width)
    image = tf.cast(image, dtype=tf.float32)
    if ground_truth is not None:
      ground_truth = tf.image.resize_image_with_crop_or_pad(
        ground_truth, out_height, out_width)

  image = image - mean
  image = rgb_to_bgr(image)

  # Subtract off the mean and divide by the variance of the pixels.
  image = tf.image.per_image_standardization(image)

  if ground_truth is not None:
    ground_truth = tf.cast(ground_truth, dtype=tf.int32)
  return image, ground_truth
 Preprocess image and ground truth annotation.

  Args:
    image: 3-D Tensor of shape (num_rows, num_columns, num_channels) (HWC).
    ground_truth: 3-D Tensor of shape (num_rows, num_columns, num_channels)
        (HWC).
    out_size: Tuple of Int. Output height and width of the preprocessed image.
    mean: Python array or 1-D Tensor with the same length as the number of
        channels of `image`.
    is_training: Bool. If `True` the image and ground truth annotation will be
        augmented using shifting, left/right flipping and rotation.

    Returns:
      Tuple of 3-D Tensors: `image` and `ground_truth` tensors of shape
          (`height`, `width`, -1).
  
Preprocess image and ground truth annotation.
Preprocess image and ground truth annotation .
def preprocess(image, ground_truth, out_size, mean, is_training):
  mean = tf.convert_to_tensor(mean, dtype=tf.float32)
  image = tf.convert_to_tensor(image)
  depth_i = image.shape.as_list()[2]
  if ground_truth is not None:
    ground_truth = tf.convert_to_tensor(ground_truth)
    depth_ground_truth = ground_truth.shape.as_list()[2]
  else:
    ground_truth = None
    depth_ground_truth = 0
  out_height, out_width = out_size
  if is_training:
    combined = tf.concat([image, ground_truth], axis=2)
    combined = tf.random_crop(
      combined, [out_height, out_width, depth_i + depth_ground_truth])
    image = combined[:, :, :depth_i]
    ground_truth = combined[:, :, depth_i:]
    image = tf.cast(image, dtype=tf.float32)
    image = tf.image.random_brightness(image, max_delta=1.2)
    image = tf.image.random_contrast(image, lower=0.8, upper=1.2)
  else:
    image = tf.image.resize_image_with_crop_or_pad(image, out_height, out_width)
    image = tf.cast(image, dtype=tf.float32)
    if ground_truth is not None:
      ground_truth = tf.image.resize_image_with_crop_or_pad(
        ground_truth, out_height, out_width)
  image = image - mean
  image = rgb_to_bgr(image)
  image = tf.image.per_image_standardization(image)
  if ground_truth is not None:
    ground_truth = tf.cast(ground_truth, dtype=tf.int32)
  return image, ground_truth
def preprocess ( image , ground_truth , out_size , mean , is_training ) : mean = tf . convert_to_tensor ( mean , dtype = tf . float32 ) image = tf . convert_to_tensor ( image ) depth_i = image . shape . as_list ( ) [ 2 ] if ground_truth is not None : ground_truth = tf . convert_to_tensor ( ground_truth ) depth_ground_truth = ground_truth . shape . as_list ( ) [ 2 ] else : ground_truth = None depth_ground_truth = 0 out_height , out_width = out_size if is_training : combined = tf . concat ( [ image , ground_truth ] , axis = 2 ) combined = tf . random_crop ( combined , [ out_height , out_width , depth_i + depth_ground_truth ] ) image = combined [ : , : , : depth_i ] ground_truth = combined [ : , : , depth_i : ] image = tf . cast ( image , dtype = tf . float32 ) image = tf . image . random_brightness ( image , max_delta = 1.2 ) image = tf . image . random_contrast ( image , lower = 0.8 , upper = 1.2 ) else : image = tf . image . resize_image_with_crop_or_pad ( image , out_height , out_width ) image = tf . cast ( image , dtype = tf . float32 ) if ground_truth is not None : ground_truth = tf . image . resize_image_with_crop_or_pad ( ground_truth , out_height , out_width ) image = image - mean image = rgb_to_bgr ( image ) image = tf . image . per_image_standardization ( image ) if ground_truth is not None : ground_truth = tf . cast ( ground_truth , dtype = tf . int32 ) return image , ground_truth
Preprocess image and ground truth annotation.
Preprocess image and ground truth annotation .
""" Preprocess image and ground truth annotation.

  Args:
    image: 3-D Tensor of shape (num_rows, num_columns, num_channels) (HWC).
    ground_truth: 3-D Tensor of shape (num_rows, num_columns, num_channels)
        (HWC).
    out_size: Tuple of Int. Output height and width of the preprocessed image.
    mean: Python array or 1-D Tensor with the same length as the number of
        channels of `image`.
    is_training: Bool. If `True` the image and ground truth annotation will be
        augmented using shifting, left/right flipping and rotation.

    Returns:
      Tuple of 3-D Tensors: `image` and `ground_truth` tensors of shape
          (`height`, `width`, -1).
  """ # TODO: Images and ground_truth should also have the possibility to be a #       4-D Tensor # Combine images so that we can randomly crop only one matrix for both # Image and ground truth label # combined = tf.image.random_flip_left_right(combined) # NOTE: since per_image_standardization zeros the mean and makes # the stddev unit, this likely has no effect see tensorflow#1458. # Subtract off the mean and divide by the variance of the pixels.
image
3-D Tensor of shape (num_rows, num_columns, num_channels) (HWC).
3 - D Tensor of shape ( num_rows num_columns num_channels ) ( HWC ) .
ground_truth
3-D Tensor of shape (num_rows, num_columns, num_channels)
(HWC).
3 - D Tensor of shape ( num_rows num_columns num_channels ) ( HWC ) .
out_size
Tuple of Int. Output height and width of the preprocessed image.
Tuple of Int . Output height and width of the preprocessed image .
mean
Python array or 1-D Tensor with the same length as the number of
channels of `image`.
Python array or 1 - D Tensor with the same length as the number of channels of ` image ` .
is_training
Bool. If `True` the image and ground truth annotation will be
augmented using shifting, left/right flipping and rotation.
Bool . If ` True ` the image and ground truth annotation will be augmented using shifting left / right flipping and rotation .
Returns
Tuple of 3-D Tensors: `image` and `ground_truth` tensors of shape
(`height`, `width`, -1).
Tuple of 3 - D Tensors : ` image ` and ` ground_truth ` tensors of shape ( ` height ` ` width ` - 1 ) .