예제 #1
0
def read_and_prepocess_single_img(filename_queue, shortside_len, is_training):

    img_name, img, gtboxes_and_label, num_objects = read_single_example_and_decode(
        filename_queue)

    img = tf.cast(img, tf.float32)

    if is_training:

        # img, gtboxes_and_label = image_preprocess.aspect_ratio_jittering(img, gtboxes_and_label)

        img, gtboxes_and_label, img_h, img_w = image_preprocess.short_side_resize(
            img_tensor=img,
            gtboxes_and_label=gtboxes_and_label,
            target_shortside_len=shortside_len,
            length_limitation=cfgs.IMG_MAX_LENGTH)
        img, gtboxes_and_label = image_preprocess.random_flip_left_right(
            img_tensor=img, gtboxes_and_label=gtboxes_and_label)

    else:
        img, gtboxes_and_label, img_h, img_w = image_preprocess.short_side_resize(
            img_tensor=img,
            gtboxes_and_label=gtboxes_and_label,
            target_shortside_len=shortside_len,
            length_limitation=cfgs.IMG_MAX_LENGTH)
    if cfgs.NET_NAME in ['resnet152_v1d', 'resnet101_v1d', 'resnet50_v1d']:
        img = img / 255 - tf.constant([[cfgs.PIXEL_MEAN_]])
    else:
        img = img - tf.constant([[cfgs.PIXEL_MEAN]])  # sub pixel mean at last
    return img_name, img, gtboxes_and_label, num_objects, img_h, img_w
예제 #2
0
def read_and_prepocess_single_img(filename_queue, shortside_len, is_training):

    img_name, img, gtboxes_and_label, num_objects = read_single_example_and_decode(
        filename_queue)

    img = tf.cast(img, tf.float32)

    if is_training:

        if cfgs.RGB2GRAY:
            # img, gtboxes_and_label = image_preprocess.aspect_ratio_jittering(img, gtboxes_and_label)
            img = image_preprocess.random_rgb2gray(
                img_tensor=img, gtboxes_and_label=gtboxes_and_label)

        if cfgs.IMG_ROTATE:
            # rotate with 0.5 prob. and if rotate, if will random choose a theta from : tf.range(-90, 90+16, delta=15)
            img, gtboxes_and_label = image_preprocess.random_rotate_img(
                img_tensor=img, gtboxes_and_label=gtboxes_and_label)

        img, gtboxes_and_label, img_h, img_w = image_preprocess.short_side_resize(
            img_tensor=img,
            gtboxes_and_label=gtboxes_and_label,
            target_shortside_len=shortside_len,
            length_limitation=cfgs.IMG_MAX_LENGTH)

        if cfgs.HORIZONTAL_FLIP:
            img, gtboxes_and_label = image_preprocess.random_flip_left_right(
                img_tensor=img, gtboxes_and_label=gtboxes_and_label)
        if cfgs.VERTICAL_FLIP:
            img, gtboxes_and_label = image_preprocess.random_flip_up_down(
                img_tensor=img, gtboxes_and_label=gtboxes_and_label)

    else:
        img, gtboxes_and_label, img_h, img_w = image_preprocess.short_side_resize(
            img_tensor=img,
            gtboxes_and_label=gtboxes_and_label,
            target_shortside_len=shortside_len,
            length_limitation=cfgs.IMG_MAX_LENGTH)
    # gtboxes_and_label = tf.reshape(tf.py_func(filter_small_gt, inp=[gtboxes_and_label], Tout=[tf.float32]), [-1, 9])
    if cfgs.NET_NAME in ['resnet152_v1d', 'resnet101_v1d', 'resnet50_v1d']:
        img = img / 255 - tf.constant([[cfgs.PIXEL_MEAN_]])
    else:
        img = img - tf.constant([[cfgs.PIXEL_MEAN]])  # sub pixel mean at last
    return img_name, img, gtboxes_and_label, num_objects, img_h, img_w
def read_and_prepocess_single_img(filename_queue, shortside_len, is_training):

    img_name, img, gtboxes_and_label, num_objects = read_single_example_and_decode(
        filename_queue)

    img = tf.cast(img, tf.float32)
    img = img - tf.constant(cfgs.PIXEL_MEAN)

    if is_training:
        img, gtboxes_and_label, img_h, img_w = image_preprocess.short_side_resize(
            img_tensor=img,
            gtboxes_and_label=gtboxes_and_label,
            target_shortside_len=shortside_len)
        img, gtboxes_and_label = image_preprocess.random_flip_left_right(
            img_tensor=img, gtboxes_and_label=gtboxes_and_label)

    else:
        img, gtboxes_and_label, img_h, img_w = image_preprocess.short_side_resize(
            img_tensor=img,
            gtboxes_and_label=gtboxes_and_label,
            target_shortside_len=shortside_len)

    return img_name, img, gtboxes_and_label, num_objects, img_h, img_w