Exemple #1
0
def preprocess(example, output_size=(HEIGHT, WIDTH), max_objects=50, training=True):
    image, objects, image_id = decode(example)

    if training:
        image = random_resize(image, output_size, ratio_range=(0.5, 2.0))
        image, objects = random_crop(image, objects, output_size)
        image, objects = random_hflip(image, objects, 0.5)
    else:
        image = resize(image, output_size)

    image = normalize(image, [123.68, 116.779, 103.939], [58.393, 57.12, 57.375])
    image, objects = pad_to(image, objects, output_size)

    gt_bboxes, gt_labels = get(['gt_bbox', 'gt_label'], objects)
    gt_bboxes = coords_to_absolute(gt_bboxes, tf.shape(image)[:2])
    objects = {**objects, 'gt_bbox': gt_bboxes}

    bbox_targets, labels, centerness = atss_match(
        gt_bboxes, gt_labels, anchors, num_level_bboxes, topk=9, centerness=True)

    objects = pad_objects(objects, max_objects)

    image = tf.cast(image, tf.bfloat16)
    return image, {'bbox_target': bbox_targets, 'label': labels, 'centerness': centerness,
                   **objects, 'image_id': image_id}
Exemple #2
0
def transform(example, output_size=(HEIGHT, WIDTH), training=True):
    image, objects, image_id = decode(example)

    # if training:
    #     image = random_resize(image, output_size, ratio_range=(0.8, 1.2))
    #     image, objects = random_crop(image, objects, output_size)
    #     image, objects = random_hflip(image, objects, 0.5)
    # else:
    image = resize(image, output_size)

    image = normalize(image, [123.68, 116.779, 103.939],
                      [58.393, 57.12, 57.375])
    image, objects = pad_to(image, objects, output_size)

    gt_bboxes, gt_labels = get(['gt_bbox', 'gt_label'], objects)
    gt_bboxes = coords_to_absolute(gt_bboxes, tf.shape(image)[:2])

    bbox_targets, labels = atss_match(gt_bboxes,
                                      gt_labels,
                                      anchors,
                                      num_level_bboxes,
                                      topk=9,
                                      centerness=False)

    return image, {
        'bbox_target': bbox_targets,
        'label': labels,
        'image_id': image_id
    }
Exemple #3
0
def preprocess(example,
               output_size=(HEIGHT, WIDTH),
               max_objects=50,
               training=True):
    image, objects, image_id = decode(example)

    # if training:
    #     image = random_resize(image, output_size, ratio_range=(0.8, 1.2))
    #     image, objects = random_crop(image, objects, output_size)
    #     image, objects = random_hflip(image, objects, 0.5)
    # else:
    image = resize(image, output_size)

    image = normalize(image, [123.68, 116.779, 103.939],
                      [58.393, 57.12, 57.375])
    image, objects = pad_to(image, objects, output_size)

    gt_bboxes, gt_labels = get(['gt_bbox', 'gt_label'], objects)
    gt_bboxes = coords_to_absolute(gt_bboxes, tf.shape(image)[:2])
    objects = {**objects, 'gt_bbox': gt_bboxes}

    bbox_targets, labels, ignore = max_iou_match(gt_bboxes,
                                                 gt_labels,
                                                 bbox_coder,
                                                 pos_iou_thr=0.5,
                                                 neg_iou_thr=0.4)

    objects = pad_objects(objects, max_objects)

    return image, {
        'bbox_target': bbox_targets,
        'label': labels,
        'ignore': ignore,
        **objects, 'image_id': image_id
    }
Exemple #4
0
def preprocess(example,
               output_size=(HEIGHT, WIDTH),
               max_objects=50,
               training=True):
    image, objects, image_id = decode(example)

    # if training:
    # image = random_resize(image, output_size, ratio_range=(0.8, 1.2))
    # image, objects = random_crop(image, objects, output_size)
    # image, objects = random_hflip(image, objects, 0.5)
    # else:
    image = resize(image, output_size)

    image = normalize(image, [123.68, 116.779, 103.939],
                      [58.393, 57.12, 57.375])
    image, objects = pad_to(image, objects, output_size)

    gt_bboxes, gt_labels, is_difficults = get(
        ['bbox', 'label', 'is_difficult'], objects)
    gt_bboxes = coords_to_absolute(gt_bboxes, tf.shape(image)[:2])

    assigned_gt_inds = atss_assign(anchors,
                                   num_level_bboxes,
                                   gt_bboxes,
                                   topk=9)
    bbox_targets, labels, centerness, ignore = encode_target(gt_bboxes,
                                                             gt_labels,
                                                             assigned_gt_inds,
                                                             bbox_coder,
                                                             encode_bbox=False,
                                                             centerness=True)

    gt_bboxes = pad_to_fixed_size(gt_bboxes, max_objects)
    gt_labels = pad_to_fixed_size(gt_labels, max_objects)
    is_difficults = pad_to_fixed_size(is_difficults, max_objects)

    # image = tf.cast(image, tf.bfloat16)
    return image, {
        'bbox_target': bbox_targets,
        'label': labels,
        'ignore': ignore,
        'centerness': centerness,
        'gt_bbox': gt_bboxes,
        'gt_label': gt_labels,
        'is_difficult': is_difficults,
        'image_id': image_id
    }
Exemple #5
0
def preprocess(example,
               output_size=(HEIGHT, WIDTH),
               max_objects=50,
               training=True):
    image, objects, image_id = decode(example)

    # if training:
    #     image = random_resize(image, output_size, ratio_range=(0.8, 1.2))
    #     image, objects = random_crop(image, objects, output_size)
    #     image, objects = random_hflip(image, objects, 0.5)
    # else:
    image = resize(image, output_size)

    image = normalize(image, [123.68, 116.779, 103.939],
                      [58.393, 57.12, 57.375])
    image, objects = pad_to(image, objects, output_size)

    gt_bboxes, gt_labels = get(['gt_bbox', 'gt_label'], objects)
    gt_bboxes = coords_to_absolute(gt_bboxes, tf.shape(image)[:2])
    objects = {**objects, 'gt_bbox': gt_bboxes}

    bbox_targets, labels, centerness = fcos_match(gt_bboxes,
                                                  gt_labels,
                                                  points,
                                                  num_level_points,
                                                  strides=strides,
                                                  radius=0.5)

    objects = pad_objects(objects, max_objects)

    return image, {
        'bbox_target': bbox_targets,
        'label': labels,
        'centerness': centerness,
        **objects, 'image_id': image_id
    }
Exemple #6
0
                                                 skip_prefetch=True))

it = iter(ds_train)

example = next(it)

image, objects, image_id = decode(example)

# if training:
#     image = random_resize(image, output_size, ratio_range=(0.8, 1.2))
#     image, objects = random_crop(image, objects, output_size)
#     image, objects = random_hflip(image, objects, 0.5)
# else:
image = resize(image, output_size)

image = normalize(image, [123.68, 116.779, 103.939], [58.393, 57.12, 57.375])
image, objects = pad_to(image, objects, output_size)

gt_bboxes, gt_labels = get(['gt_bbox', 'gt_label'], objects)
gt_bboxes = coords_to_absolute(gt_bboxes, tf.shape(image)[:2])
objects = {**objects, 'gt_bbox': gt_bboxes}

bbox_targets, labels, centerness = atss_match(gt_bboxes,
                                              gt_labels,
                                              anchors,
                                              num_level_bboxes,
                                              topk=9,
                                              centerness=True)

objects = pad_objects(objects, max_objects)