def test_dataset():
    data_path = 'test_data'
    data = Data(data_path, mode='train')
    from auto_driving.config import Config
    config = Config()
    config.size = (400, 512)
    sizes = [(2710, 3384), config.size]
    scale = FrameTransform(config)
    transforms = [None, scale.transform]
    for transform, expected_size in zip(transforms, sizes):
        dataset = FrameDataset(data, config, transform=transform)
        sample = dataset[0]
        assert len(dataset) == 8
        assert 'image' in sample
        assert 'mask' in sample
        assert 'bboxes' in sample
        assert 'classes' in sample
        assert sample['image'].type() == torch.FloatTensor(0).type()
        assert sample['mask'].type() == torch.FloatTensor(0).type()
        assert sample['bboxes'].type() == torch.FloatTensor(0).type()
        assert sample['classes'].type() == torch.LongTensor(0).type()
        assert sample['image'].shape[0] == 3
        assert sample['image'].shape[1:] == expected_size
        assert sample['mask'].shape[1] == 1
        assert sample['mask'].shape[2:] == expected_size
Exemple #2
0
def dataset_t():
    data_path = 'test_data'
    data = Data(data_path, mode='train')
    config = Config()
    config.size = (400, 512)
    scale = FrameTransform(config)
    dataset = FrameDataset(data, config, transform=scale.transform)
    return dataset
Exemple #3
0
def test_evaluate_img_cat(masks1, masks2):
    config = Config()
    dt_masks, dt_cats = masks1
    gt_masks, gt_cats = masks2
    scores = np.array([0.8, 0.7, 0.6, 0.5, 0.4] + [0.0] * (len(dt_cats) - 5))
    evaluator = Eval(config)
    evaluator.params.catIds = [0, 1, 2, 3]
    dtm_1, scores_1, G_1 = evaluator.evaluate_img_cat(dt_masks[dt_cats == 1],
                                                      gt_masks[gt_cats == 1],
                                                      scores[dt_cats == 1])
    assert dtm_1.shape[1] == 1
    assert dtm_1[0, 0] == 1
    for i in range(1, dtm_1.shape[0]):
        assert dtm_1[i, 0] == 0
    assert G_1 == 1

    dtm_2, scores_2, G_2 = evaluator.evaluate_img_cat(dt_masks[dt_cats == 2],
                                                      gt_masks[gt_cats == 2],
                                                      scores[dt_cats == 2])
    assert G_2 == 3
    assert dtm_2[3, 0] == 1
    assert dtm_2[4, 0] == 0
    assert dtm_2[6, 1] == 1
    assert dtm_2[7, 1] == 0
    assert dtm_2[0, 2] == 0

    dtm_3, scores_3, G_3 = evaluator.evaluate_img_cat(dt_masks[dt_cats == 3],
                                                      gt_masks[gt_cats == 3],
                                                      scores[dt_cats == 3])
    assert G_3 == 0
Exemple #4
0
def test_accumulate():
    config = Config()
    scores = np.array([0.9, 0.8, 0.7, 0.6, 0.5, 0.4])
    evaluator = Eval(config)
    evaluator.params.catIds = [0, 1, 2]
    evaluator.params.iouThrs = [0.5, 0.75, 0.95]
    matches = []
    dtm = np.array([
        [1, 1, 0, 1, 0, 0],
        [0, 1, 0, 1, 0, 0],
        [0, 1, 0, 0, 0, 0],
    ],
                   dtype=np.float64)
    gtN = 4
    matches.append({'dtMatches': dtm, 'dtScores': scores, 'gtN': gtN})
    matches.append(None)
    evaluator.eval_res.append(matches)
    evaluator.accumulate()
    pr = np.array([
        [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.0, 0.0, 0.0],
        [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    ])
    pr = np.stack([pr, -np.ones_like(pr)], axis=2)
    assert np.allclose(pr, evaluator.precision)
def test_transform():
    from auto_driving.config import Config
    config = Config()
    config.size = (400, 512)
    transform = FrameTransform(config)
    dtypes = [np.int8, np.int32, np.float32, np.float64]
    for dtype in dtypes:
        sample = {}
        sample['image'] = np.ones((2710, 3384, 3), dtype=dtype)
        sample['mask'] = np.ones((10, 2710, 3384), dtype=dtype)
        newsample = transform.transform(sample)
        assert sample != newsample
        assert sample['image'] != newsample['image']
        assert sample['mask'] != newsample['mask']
        assert newsample['image'].shape == (config.size[0], config.size[1], 3)
        assert newsample['mask'].shape == (sample['mask'].shape[0],
                                           config.size[0], config.size[1])
        assert newsample['image'].dtype == dtype
        assert newsample['mask'].dtype == dtype
        assert newsample['image'].max() == 1.0
        assert newsample['mask'].max() == 1.0
Exemple #6
0
def test_evaluate_img(masks1, masks2):
    config = Config()
    dt_masks, dt_cats = masks1
    gt_masks, gt_cats = masks2
    scores = np.array([0.8, 0.7, 0.6, 0.5, 0.4] + [0.0] * (len(dt_cats) - 5))
    evaluator = Eval(config)
    evaluator.params.catIds = [0, 1, 2, 3]

    evaluator.evaluate_img(dt_masks, gt_masks, dt_cats, gt_cats, scores)
    assert len(evaluator.eval_res) == 1
    assert len(evaluator.eval_res[0]) == len(evaluator.params.catIds) - 1
    assert evaluator.eval_res[0][-1] is None
Exemple #7
0
def test_overlap_det():
    gt_masks = np.array([[[0, 0, 0], [0, 1, 1], [0, 1, 1]]], dtype=np.bool)
    dt_masks = np.array(
        [[[0, 0, 0], [0, 1, 1], [0, 1, 1]], [[0, 0, 0], [0, 0, 1], [0, 1, 1]],
         [[0, 0, 0], [0, 1, 0], [0, 0, 1]]],
        dtype=np.bool)
    scores = np.array([0.6, 0.7, 0.8])
    config = Config()
    evaluator = Eval(config)
    dtm, scores, G = evaluator.evaluate_img_cat(dt_masks=dt_masks,
                                                gt_masks=gt_masks,
                                                scores=scores)
    thrs = evaluator.params.iouThrs
    assert np.allclose(dtm[:, 0][thrs <= 0.5], 1)
    assert np.allclose(dtm[:, 1:][thrs <= 0.5], 0)
    assert np.allclose(dtm[:, 0][thrs > 0.5], 0)
    assert np.allclose(dtm[:, 1][np.logical_and(thrs > 0.5, thrs <= 3 / 4)], 1)
    assert np.allclose(dtm[:, 2][np.logical_and(thrs > 0.5, thrs <= 3 / 4)], 0)
    assert np.allclose(dtm[:, 2][thrs > 3 / 4], 1)