Ejemplo n.º 1
0
def test_map_semantic_img_fast_uint16_stress_test():
    """
	Test fast method on large example. Map 60,000 classes to a 
	different 60,000 classes with a fast array conversion.

	Should take less than 1 millisecond.
	"""
    semantic_img = np.array(range(60000)).reshape(3000, 20).astype(np.uint16)
    # will expect uint16 back since 60000 < 65535, which is uint16 max
    gt_mapped_img1 = np.array(range(60000)).reshape(3000, 20).astype(
        np.uint16) + 1

    label_mapping = {i: i + 1 for i in range(60000)}

    label_mapping_copy = copy.deepcopy(label_mapping)
    label_mapping_arr = form_label_mapping_array(label_mapping)
    dict_is_equal(label_mapping, label_mapping_copy)
    assert label_mapping == label_mapping_copy
    start = time.time()
    mapped_img = map_semantic_img_fast(semantic_img, label_mapping_arr)
    end = time.time()
    print(f'Took {end-start} sec.')

    gt_mapped_img2 = map_semantic_img_slow(semantic_img, label_mapping)

    assert np.allclose(gt_mapped_img1, mapped_img)
    assert np.allclose(gt_mapped_img2, mapped_img)
    assert gt_mapped_img1.dtype == mapped_img.dtype
    assert gt_mapped_img2.dtype == mapped_img.dtype
Ejemplo n.º 2
0
def test_categoryid_to_classname_map():
    """
	Make sure that mapping on disk is correct.
	"""
    taxonomy_data_fpath = _ROOT / 'test_data/coco_panoptic_categories.json'
    coco_category_info = read_json_file(taxonomy_data_fpath)

    gt_categoryid_to_classname_map = {}
    for category in coco_category_info:
        categoryid = category['id']
        classname = category['name']
        gt_categoryid_to_classname_map[categoryid] = classname

    # pad the rest of keys to map to 'unlabeled'
    for id in range(201):
        if id not in gt_categoryid_to_classname_map:
            gt_categoryid_to_classname_map[id] = 'unlabeled'

    categoryid_to_classname_map = get_dataloader_id_to_classname_map(
        dataset_name='coco-panoptic-201', include_ignore_idx_cls=False)
    dict_is_equal(categoryid_to_classname_map, gt_categoryid_to_classname_map)

    for key in categoryid_to_classname_map.keys():
        assert isinstance(key, int)
    for value in categoryid_to_classname_map.values():
        assert isinstance(value, str)
Ejemplo n.º 3
0
def test_load_names():
    """
	"""
    tax_data = read_mapillary_config_helper()
    id_to_classname_map = get_dataloader_id_to_classname_map(
        dataset_name='mapillary-public66', include_ignore_idx_cls=False)
    gt_id_to_classname = {
        i: entry['readable']
        for i, entry in enumerate(tax_data['labels'])
    }
    dict_is_equal(gt_id_to_classname, id_to_classname_map)
    assert len(id_to_classname_map.keys()) == 66
def test_constructor():
    """
		Use a simplfied version of the full dataset (2 images only) to 
		test for functionality.
	"""
    amd = Ade20kMaskDataset(TEST_ADE20K_SPC_IMGDIR,
                            TEST_ADE20K_NON_SPC_DATAROOT)
    gt_fname_to_rgbfpath_dict = {
        'ADE_train_00000001':
        f'{_TEST_DIR}/test_data/ADE20K_test_data/ADEChallengeData2016/images/training/ADE_train_00000001.jpg',
        'ADE_val_00000001':
        f'{_TEST_DIR}/test_data/ADE20K_test_data/ADEChallengeData2016/images/validation/ADE_val_00000001.jpg'
    }
    gt_fname_to_segrgbfpath_dict = {
        'ADE_train_00000001':
        f'{_TEST_DIR}/test_data/ADE20K_test_data/ADE20K_2016_07_26/images/training/a/aiport_terminal/ADE_train_00000001_seg.png',
        'ADE_val_00000001':
        f'{_TEST_DIR}/test_data/ADE20K_test_data/ADE20K_2016_07_26/images/validation/a/abbey/ADE_val_00000001_seg.png'
    }
    dict_is_equal(amd.fname_to_rgbfpath_dict, gt_fname_to_rgbfpath_dict)
    dict_is_equal(amd.fname_to_segrgbfpath_dict, gt_fname_to_segrgbfpath_dict)