Esempio n. 1
0
 def distort_fn_1(image=image):
   """Variant 1 of distort function."""
   image = tf.image.random_brightness(image, max_delta=32. / 255.)
   image = tf.image.random_contrast(image, lower=0.5, upper=1.5)
   if distort_color_in_yiq:
     image = distort_image_ops.random_hsv_in_yiq(
         image, lower_saturation=0.5, upper_saturation=1.5,
         max_delta_hue=0.2 * math.pi)
   else:
     image = tf.image.random_saturation(image, lower=0.5, upper=1.5)
     image = tf.image.random_hue(image, max_delta=0.2)
   return image
Esempio n. 2
0
 def distort_fn_0(image=image):
     """Variant 0 of distort function."""
     image = tf.image.random_brightness(image, max_delta=32. / 255.)
     if distort_color_in_yiq:
         image = distort_image_ops.random_hsv_in_yiq(
             image, lower_saturation=0.5, upper_saturation=1.5,
             max_delta_hue=0.2 * math.pi)
     else:
         image = tf.image.random_saturation(image, lower=0.5, upper=1.5)
         image = tf.image.random_hue(image, max_delta=0.2)
     image = tf.image.random_contrast(image, lower=0.5, upper=1.5)
     return image
Esempio n. 3
0
 def distort_fn_1(image=image):
     """Variant 1 of distort function."""
     image = tf.image.random_brightness(image, max_delta=R_BRIGHTNESS_MAX_DELTA)
     image = tf.image.random_contrast(image, lower=R_CONSTRAST_LOWER, upper=R_CONSTRAST_UPPER)
     if distort_color_in_yiq:
         image = distort_image_ops.random_hsv_in_yiq(
             image, lower_saturation=R_SATURATION_LOWER, upper_saturation=R_SATURATION_UPPER,
             max_delta_hue=R_HUE_MAX_DELTA * math.pi)
     else:
         image = tf.image.random_saturation(image, lower=R_SATURATION_LOWER, upper=R_SATURATION_UPPER)
         image = tf.image.random_hue(image, max_delta=R_HUE_MAX_DELTA)
     return image
def parse_and_preprocess_image_record(config, record, height, width,
                                      brightness, contrast, saturation, hue,
                                      distort, nsummary=10, increased_aug=False, random_search_aug=False):
    #imgdata, label, bbox, text = deserialize_image_record(record)
    #label -= 1  # Change to 0-based (don't use background class)
    with tf.name_scope('preprocess_train'):
            image = crop_and_resize_image(config, record, height, width, distort)
            if distort:
                image = tf.image.random_flip_left_right(image)
                if increased_aug:
                    image = tf.image.random_brightness(image, max_delta=brightness)  
                    image = distort_image_ops.random_hsv_in_yiq(image, 
                                                                lower_saturation=saturation, 
                                                                upper_saturation=2.0 - saturation, 
                                                                max_delta_hue=hue * math.pi)
                    image = tf.image.random_contrast(image, lower=contrast, upper=2.0 - contrast)
                    tf.summary.image('distorted_color_image', tf.expand_dims(image, 0))
                    
    image = tf.clip_by_value(image, 0., 255.)
    image = normalize(image)
    image = tf.cast(image, tf.float16)

    return image