utils/tf_image_processing.py
def map_ground_truth(ground_truth, palette, one_hot=True, name=None):
  """ Maps a ground truth image tensor to a label tensor.

  Args:
    ground_truth: Rank 3 or 4 tensor: [(batch_size,) height, width, depth].
    palette: Color palette with rank [num_classes, palette_depth].

  Returns:
    If `one_hot` is `True`, it returns a one hot label of shape
        [(batch_size,) height, width, 1], otherwise it will return a label of
        shape [(batch_size,) height, width, num_clases].

  Raises:
    ValueError: If the channels of ground truth and palette or not the same.

  """
  palette = tf.convert_to_tensor(palette)
  with tf.name_scope(name, 'MapGroundTruth', [ground_truth, palette]):
    is_batch = True
    if len(ground_truth.shape) == 3:
      is_batch = False
      ground_truth = tf.expand_dims(ground_truth, axis=0)
    ground_truth = tf.cast(ground_truth, tf.int32)
    n, h, w, c = ground_truth.shape.as_list()
    num_classes, c_p = palette.shape.as_list()
    if c != c_p:
      raise ValueError(
        'Ground truth channels (%ds) do not match palette channels (%ds)' %
        (c, c_p))
    equality = tf.equal(
      tf.reshape(ground_truth, [n, h, w, 1, c]),
      tf.reshape(palette, [num_classes, c]))
    label = tf.cast(tf.reduce_all(equality, axis=-1), tf.int32)
    if one_hot:
      label = tf.argmax(label, axis=3)
      label = tf.expand_dims(label, axis=-1)
    if not is_batch:
      label = tf.squeeze(label, axis=0)
    return label
 Maps a ground truth image tensor to a label tensor.

  Args:
    ground_truth: Rank 3 or 4 tensor: [(batch_size,) height, width, depth].
    palette: Color palette with rank [num_classes, palette_depth].

  Returns:
    If `one_hot` is `True`, it returns a one hot label of shape
        [(batch_size,) height, width, 1], otherwise it will return a label of
        shape [(batch_size,) height, width, num_clases].

  Raises:
    ValueError: If the channels of ground truth and palette or not the same.

  
Maps a ground truth image tensor to a label tensor.
Maps a ground truth image tensor to a label tensor .
def map_ground_truth(ground_truth, palette, one_hot=True, name=None):
  palette = tf.convert_to_tensor(palette)
  with tf.name_scope(name, 'MapGroundTruth', [ground_truth, palette]):
    is_batch = True
    if len(ground_truth.shape) == 3:
      is_batch = False
      ground_truth = tf.expand_dims(ground_truth, axis=0)
    ground_truth = tf.cast(ground_truth, tf.int32)
    n, h, w, c = ground_truth.shape.as_list()
    num_classes, c_p = palette.shape.as_list()
    if c != c_p:
      raise ValueError(
        'Ground truth channels (%ds) do not match palette channels (%ds)' %
        (c, c_p))
    equality = tf.equal(
      tf.reshape(ground_truth, [n, h, w, 1, c]),
      tf.reshape(palette, [num_classes, c]))
    label = tf.cast(tf.reduce_all(equality, axis=-1), tf.int32)
    if one_hot:
      label = tf.argmax(label, axis=3)
      label = tf.expand_dims(label, axis=-1)
    if not is_batch:
      label = tf.squeeze(label, axis=0)
    return label
def map_ground_truth ( ground_truth , palette , one_hot = True , name = None ) : palette = tf . convert_to_tensor ( palette ) with tf . name_scope ( name , 'MapGroundTruth' , [ ground_truth , palette ] ) : is_batch = True if len ( ground_truth . shape ) == 3 : is_batch = False ground_truth = tf . expand_dims ( ground_truth , axis = 0 ) ground_truth = tf . cast ( ground_truth , tf . int32 ) n , h , w , c = ground_truth . shape . as_list ( ) num_classes , c_p = palette . shape . as_list ( ) if c != c_p : raise ValueError ( 'Ground truth channels (%ds) do not match palette channels (%ds)' % ( c , c_p ) ) equality = tf . equal ( tf . reshape ( ground_truth , [ n , h , w , 1 , c ] ) , tf . reshape ( palette , [ num_classes , c ] ) ) label = tf . cast ( tf . reduce_all ( equality , axis = - 1 ) , tf . int32 ) if one_hot : label = tf . argmax ( label , axis = 3 ) label = tf . expand_dims ( label , axis = - 1 ) if not is_batch : label = tf . squeeze ( label , axis = 0 ) return label
Maps a ground truth image tensor to a label tensor.
Maps a ground truth image tensor to a label tensor .
""" Maps a ground truth image tensor to a label tensor.

  Args:
    ground_truth: Rank 3 or 4 tensor: [(batch_size,) height, width, depth].
    palette: Color palette with rank [num_classes, palette_depth].

  Returns:
    If `one_hot` is `True`, it returns a one hot label of shape
        [(batch_size,) height, width, 1], otherwise it will return a label of
        shape [(batch_size,) height, width, num_clases].

  Raises:
    ValueError: If the channels of ground truth and palette or not the same.

  """
If `one_hot` is `True`, it returns a one hot label of shape
[(batch_size,) height, width, 1], otherwise it will return a label of
shape [(batch_size,) height, width, num_clases].
If ` one_hot ` is ` True ` it returns a one hot label of shape [ ( batch_size ) height width 1 ] otherwise it will return a label of shape [ ( batch_size ) height width num_clases ] .
If the channels of ground truth and palette or not the same.
If the channels of ground truth and palette or not the same .
ValueError
ground_truth
Rank 3 or 4 tensor: [(batch_size,) height, width, depth].
Rank 3 or 4 tensor : [ ( batch_size ) height width depth ] .
palette
Color palette with rank [num_classes, palette_depth].
Color palette with rank [ num_classes palette_depth ] .
one_hot
name