示例#1
0
def test_label():
    stride = 16
    feat_h, feat_w = (7, 7)
    img_info = keras.backend.variable([[112, 112, 3]])

    gt_boxes = keras.backend.variable(100 * numpy.random.random((91, 4)))
    gt_boxes = tensorflow.convert_to_tensor(gt_boxes, dtype=tensorflow.float32)

    all_anchors = keras_rcnn.backend.shift((feat_h, feat_w), stride)

    inds_inside, all_inside_anchors = anchor_target.inside_image(
        all_anchors, img_info[0], allowed_border=1)

    all_inside_anchors = keras_rcnn.backend.clip(all_inside_anchors,
                                                 img_info[0][:2])

    argmax_overlaps_inds, anchor_labels = anchor_target.label(
        gt_boxes, all_inside_anchors, inds_inside)

    result1 = keras.backend.eval(argmax_overlaps_inds)
    result2 = keras.backend.eval(anchor_labels)

    assert result1.shape == (32, ), keras.backend.eval(inds_inside).shape

    assert result2.shape == (32, )

    assert numpy.max(result2) <= 1

    assert numpy.min(result2) >= -1

    argmax_overlaps_inds, anchor_labels = anchor_target.label(
        gt_boxes, all_inside_anchors, inds_inside, clobber_positives=False)

    result1 = keras.backend.eval(argmax_overlaps_inds)
    result2 = keras.backend.eval(anchor_labels)

    assert result1.shape == (32, )

    assert result2.shape == (32, )

    assert numpy.max(result2) <= 1

    assert numpy.min(result2) >= -1

    gt_boxes = keras.backend.variable(224 * numpy.random.random((55, 4)))
    gt_boxes = tensorflow.convert_to_tensor(gt_boxes, dtype=tensorflow.float32)
    argmax_overlaps_inds, anchor_labels = anchor_target.label(
        gt_boxes, all_inside_anchors, inds_inside, clobber_positives=False)

    result1 = keras.backend.eval(argmax_overlaps_inds)
    result2 = keras.backend.eval(anchor_labels)

    assert result1.shape == (32, )

    assert result2.shape == (32, )

    assert numpy.max(result2) <= 1

    assert numpy.min(result2) >= -1
def test_label():
    stride = 16
    feat_h, feat_w = (14, 14)
    img_info = keras.backend.variable([[224, 224, 3]])

    gt_boxes = keras.backend.variable(100 * numpy.random.random((91, 4)))
    gt_boxes = tensorflow.convert_to_tensor(gt_boxes, dtype=tensorflow.float32)

    all_bbox = keras_rcnn.backend.shift((feat_h, feat_w), stride)

    inds_inside, all_inside_bbox = anchor_target.inside_image(
        all_bbox, img_info[0])

    argmax_overlaps_inds, bbox_labels = anchor_target.label(
        gt_boxes, all_inside_bbox, inds_inside)

    result1 = keras.backend.eval(argmax_overlaps_inds)
    result2 = keras.backend.eval(bbox_labels)

    assert result1.shape == (376,)

    assert result2.shape == (376,)

    assert numpy.max(result2) <= 1

    assert numpy.min(result2) >= -1

    argmax_overlaps_inds, bbox_labels = anchor_target.label(
        gt_boxes, all_inside_bbox, inds_inside, clobber_positives=False)

    result1 = keras.backend.eval(argmax_overlaps_inds)
    result2 = keras.backend.eval(bbox_labels)

    assert result1.shape == (376,)

    assert result2.shape == (376,)

    assert numpy.max(result2) <= 1

    assert numpy.min(result2) >= -1

    gt_boxes = keras.backend.variable(224 * numpy.random.random((55, 4)))
    gt_boxes = tensorflow.convert_to_tensor(gt_boxes, dtype=tensorflow.float32)
    argmax_overlaps_inds, bbox_labels = anchor_target.label(
        gt_boxes, all_inside_bbox, inds_inside, clobber_positives=False)
    result1 = keras.backend.eval(argmax_overlaps_inds)
    result2 = keras.backend.eval(bbox_labels)

    assert result1.shape == (376,)

    assert result2.shape == (376,)

    assert numpy.max(result2) <= 1

    assert numpy.min(result2) >= -1
def test_unmap():
    stride = 16
    features = (14, 14)
    anchors = 9
    total_anchors = features[0] * features[1] * anchors
    img_info = keras.backend.variable([[224, 224, 3]])
    gt_boxes = numpy.zeros((91, 4))
    gt_boxes = keras.backend.variable(gt_boxes)

    all_anchors = keras_rcnn.backend.shift(features, stride)

    inds_inside, all_inside_anchors = anchor_target.inside_image(
        all_anchors, img_info[0])

    argmax_overlaps_indices, labels = anchor_target.label(
        gt_boxes, all_inside_anchors, inds_inside)
    bbox_reg_targets = keras_rcnn.backend.bbox_transform(
        all_inside_anchors,
        keras.backend.gather(gt_boxes, argmax_overlaps_indices)
    )

    labels = anchor_target.unmap(labels,
                                 total_anchors,
                                 inds_inside,
                                 fill=-1)
    bbox_reg_targets = anchor_target.unmap(
        bbox_reg_targets, total_anchors, inds_inside, fill=0)

    assert keras.backend.eval(labels).shape == (total_anchors,)
    assert keras.backend.eval(bbox_reg_targets).shape == (total_anchors, 4)