(image, height, width, labels, bboxes,
                         fast_mode=True,
                         scope=None)
Distort one image for training a network.

  Distorting images provides a useful technique for augmenting the data
  set during training in order to make the network invariant to aspects
  of the image that do not effect the label.

  Additionally it would create image_summaries to display the different
  transformations applied to the image.

  Args:
    image: 3-D Tensor of image. If dtype is tf.float32 then the range should be
      [0, 1], otherwise it would converted to tf.float32 assuming that the range
      is [0, MAX], where MAX is largest positive representable number for
      int(8/16/32) data type (see `tf.image.convert_image_dtype` for details).
    height: integer
    width: integer
    bbox: 3-D float Tensor of bounding boxes arranged [1, num_boxes, coords]
      where each coordinate is [0, 1) and the coordinates are arranged
      as [ymin, xmin, ymax, xmax].
    fast_mode: Optional boolean, if True avoids slower transformations (i.e.
      bi-cubic resizing, random_hue or random_contrast).
    scope: Optional scope for name_scope.
  Returns:
    3-D float Tensor of distorted image used for training with range [-1, 1].
Distort one image for training a network.
Distort one image for training a network .
def preprocess_for_train(image, height, width, labels, bboxes,
                         fast_mode=True,
                         scope=None):
  """Distort one image for training a network.

  Distorting images provides a useful technique for augmenting the data
  set during training in order to make the network invariant to aspects
  of the image that do not effect the label.

  Additionally it would create image_summaries to display the different
  transformations applied to the image.

  Args:
    image: 3-D Tensor of image. If dtype is tf.float32 then the range should be
      [0, 1], otherwise it would converted to tf.float32 assuming that the range
      is [0, MAX], where MAX is largest positive representable number for
      int(8/16/32) data type (see `tf.image.convert_image_dtype` for details).
    height: integer
    width: integer
    bbox: 3-D float Tensor of bounding boxes arranged [1, num_boxes, coords]
      where each coordinate is [0, 1) and the coordinates are arranged
      as [ymin, xmin, ymax, xmax].
    fast_mode: Optional boolean, if True avoids slower transformations (i.e.
      bi-cubic resizing, random_hue or random_contrast).
    scope: Optional scope for name_scope.
  Returns:
    3-D float Tensor of distorted image used for training with range [-1, 1].
  """
  with tf.name_scope(scope, 'distort_image', [image, height, width, bboxes]):
    if image.dtype != tf.float32:
      image = tf.image.convert_image_dtype(image, dtype=tf.float32)

    tf.summary.image('ori_image',
                     tf.expand_dims(image, 0))
    # Randomly distort the colors. There are 4 ways to do it.
    image = apply_with_random_selector(
      image,
        lambda x, ordering: distort_color(x, ordering, fast_mode),
        num_cases=4)

    # Randomly flip the image horizontally.
    image, bboxes = flip_with_bboxes(image, bboxes)

    print(image.get_shape())

    # TODO(shizehao): bistort bbox
    image = tf.squeeze(tf.image.resize_nearest_neighbor(tf.expand_dims(image,axis=0),size=[height, width]))

    tf.summary.image('final_distorted_image',
                     tf.expand_dims(image, 0))

    image = tf.subtract(image, 0.5)
    image = tf.multiply(image, 2.0)

    return image, labels, bboxes
def preprocess_for_train ( image , height , width , labels , bboxes , fast_mode = True , scope = None ) : with tf . name_scope ( scope , 'distort_image' , [ image , height , width , bboxes ] ) : if image . dtype != tf . float32 : image = tf . image . convert_image_dtype ( image , dtype = tf . float32 ) tf . summary . image ( 'ori_image' , tf . expand_dims ( image , 0 ) ) # Randomly distort the colors. There are 4 ways to do it. image = apply_with_random_selector ( image , lambda x , ordering : distort_color ( x , ordering , fast_mode ) , num_cases = 4 ) # Randomly flip the image horizontally. image , bboxes = flip_with_bboxes ( image , bboxes ) print ( image . get_shape ( ) ) # TODO(shizehao): bistort bbox image = tf . squeeze ( tf . image . resize_nearest_neighbor ( tf . expand_dims ( image , axis = 0 ) , size = [ height , width ] ) ) tf . summary . image ( 'final_distorted_image' , tf . expand_dims ( image , 0 ) ) image = tf . subtract ( image , 0.5 ) image = tf . multiply ( image , 2.0 ) return image , labels , bboxes