(image, labels, bboxes,
                             out_shape, data_format='NHWC',
                             scope='light_head_preprocess_train')
Preprocesses the given image for training.

    Note that the actual resizing scale is sampled from
        [`resize_size_min`, `resize_size_max`].

    Args:
        image: A `Tensor` representing an image of arbitrary size.
        output_height: The height of the image after preprocessing.
        output_width: The width of the image after preprocessing.
        resize_side_min: The lower bound for the smallest side of the image for
            aspect-preserving resizing.
        resize_side_max: The upper bound for the smallest side of the image for
            aspect-preserving resizing.

    Returns:
        A preprocessed image.
Preprocesses the given image for training.
Preprocesses the given image for training .
def light_head_preprocess_for_train(image, labels, bboxes,
                             out_shape, data_format='NHWC',
                             scope='light_head_preprocess_train'):
    """Preprocesses the given image for training.

    Note that the actual resizing scale is sampled from
        [`resize_size_min`, `resize_size_max`].

    Args:
        image: A `Tensor` representing an image of arbitrary size.
        output_height: The height of the image after preprocessing.
        output_width: The width of the image after preprocessing.
        resize_side_min: The lower bound for the smallest side of the image for
            aspect-preserving resizing.
        resize_side_max: The upper bound for the smallest side of the image for
            aspect-preserving resizing.

    Returns:
        A preprocessed image.
    """
    fast_mode = False
    with tf.name_scope(scope, 'light_head_preprocess_train', [image, labels, bboxes]):
        if image.get_shape().ndims != 3:
            raise ValueError('Input must be of size [height, width, C>0]')
        # Convert to float scaled [0, 1].
        if image.dtype != tf.float32:
            image = tf.image.convert_image_dtype(image, dtype=tf.float32)
        tf_summary_image(image, bboxes, 'image_with_bboxes_0')

        # Randomly distort the colors. There are 4 ways to do it.
        distort_color_image = apply_with_random_selector(image,
                                                lambda x, ordering: distort_color(x, ordering, fast_mode),
                                                num_cases=4)
        tf_summary_image(distort_color_image, bboxes, 'image_color_distorted_1')

        random_sample_image, labels, bboxes = tf_image.ssd_random_sample_patch_wrapper(distort_color_image, labels, bboxes, [_R_MEAN/255., _G_MEAN/255., _B_MEAN/255.])
        tf_summary_image(random_sample_image, bboxes, 'image_shape_distorted_2')

        # Randomly flip the image horizontally.
        random_sample_flip_image, bboxes = tf_image.random_flip_left_right(random_sample_image, bboxes)

        random_sample_flip_resized_image = tf_image.resize_image(random_sample_flip_image, out_shape,
                                          method=tf.image.ResizeMethod.BILINEAR,
                                          align_corners=False)
        tf_summary_image(random_sample_flip_resized_image, bboxes, 'image_fliped_and_resized_3')

        # Rescale to VGG input scale.
        image = random_sample_flip_resized_image * 2.
        image.set_shape([None, None, 3])
        image = tf_image_whitened(image, [_R_MEAN/127.5, _G_MEAN/127.5, _B_MEAN/127.5])
        # Image data format.
        if data_format == 'NCHW':
            image = tf.transpose(image, perm=(2, 0, 1))
        return image, labels, bboxes
def light_head_preprocess_for_train ( image , labels , bboxes , out_shape , data_format = 'NHWC' , scope = 'light_head_preprocess_train' ) : fast_mode = False with tf . name_scope ( scope , 'light_head_preprocess_train' , [ image , labels , bboxes ] ) : if image . get_shape ( ) . ndims != 3 : raise ValueError ( 'Input must be of size [height, width, C>0]' ) # Convert to float scaled [0, 1]. if image . dtype != tf . float32 : image = tf . image . convert_image_dtype ( image , dtype = tf . float32 ) tf_summary_image ( image , bboxes , 'image_with_bboxes_0' ) # Randomly distort the colors. There are 4 ways to do it. distort_color_image = apply_with_random_selector ( image , lambda x , ordering : distort_color ( x , ordering , fast_mode ) , num_cases = 4 ) tf_summary_image ( distort_color_image , bboxes , 'image_color_distorted_1' ) random_sample_image , labels , bboxes = tf_image . ssd_random_sample_patch_wrapper ( distort_color_image , labels , bboxes , [ _R_MEAN / 255. , _G_MEAN / 255. , _B_MEAN / 255. ] ) tf_summary_image ( random_sample_image , bboxes , 'image_shape_distorted_2' ) # Randomly flip the image horizontally. random_sample_flip_image , bboxes = tf_image . random_flip_left_right ( random_sample_image , bboxes ) random_sample_flip_resized_image = tf_image . resize_image ( random_sample_flip_image , out_shape , method = tf . image . ResizeMethod . BILINEAR , align_corners = False ) tf_summary_image ( random_sample_flip_resized_image , bboxes , 'image_fliped_and_resized_3' ) # Rescale to VGG input scale. image = random_sample_flip_resized_image * 2. image . set_shape ( [ None , None , 3 ] ) image = tf_image_whitened ( image , [ _R_MEAN / 127.5 , _G_MEAN / 127.5 , _B_MEAN / 127.5 ] ) # Image data format. if data_format == 'NCHW' : image = tf . transpose ( image , perm = ( 2 , 0 , 1 ) ) return image , labels , bboxes