def test_can_save_dataset_with_no_subsets(self): class TestExtractor(Extractor): def __iter__(self): return iter([ DatasetItem(id=1, annotations=[ Label(2, id=1, group=1), ]), DatasetItem(id=2, annotations=[ Label(3, id=2, group=2), ]), ]) def categories(self): label_cat = LabelCategories() point_cat = PointsCategories() for label in range(10): label_cat.add('label_' + str(label)) point_cat.add(label) return { AnnotationType.label: label_cat, AnnotationType.points: point_cat, } with TestDir() as test_dir: self._test_save_and_load(TestExtractor(), CocoConverter(), test_dir)
def test_annotation_attributes(self): class TestExtractor(Extractor): def __iter__(self): return iter([ DatasetItem(id=1, image=np.ones((4, 2, 3)), annotations=[ Polygon([0, 0, 4, 0, 4, 4], label=5, group=1, id=1, attributes={ 'is_crowd': False, 'x': 5, 'y': 'abc' }), ], attributes={'id': 1}) ]) def categories(self): label_categories = LabelCategories() for i in range(10): label_categories.add(str(i)) return { AnnotationType.label: label_categories, } with TestDir() as test_dir: self._test_save_and_load(TestExtractor(), CocoConverter(), test_dir)
def test_can_save_dataset_with_image_info(self): class TestExtractor(Extractor): def __iter__(self): return iter([ DatasetItem(id=1, image=Image(path='1.jpg', size=(10, 15))), ]) with TestDir() as test_dir: self._test_save_and_load(TestExtractor(), CocoConverter(), test_dir)
def test_preserve_coco_ids(self): class TestExtractor(Extractor): def __iter__(self): return iter([ DatasetItem(id='some/name1', image=np.ones((4, 2, 3)), attributes={'id': 40}), ]) with TestDir() as test_dir: self._test_save_and_load( TestExtractor(), CocoConverter(tasks='image_info', save_images=True), test_dir)
def test_can_save_dataset_with_no_subsets(self): class TestExtractor(Extractor): def __iter__(self): return iter([ DatasetItem(id=1), DatasetItem(id=2), ]) def categories(self): return {AnnotationType.label: LabelCategories()} with TestDir() as test_dir: self._test_save_and_load(TestExtractor(), CocoConverter(), test_dir)
def test_relative_paths(self): class TestExtractor(Extractor): def __iter__(self): return iter([ DatasetItem(id='1', image=np.ones((4, 2, 3)), attributes={'id': 1}), DatasetItem(id='subdir1/1', image=np.ones((2, 6, 3)), attributes={'id': 2}), DatasetItem(id='subdir2/1', image=np.ones((5, 4, 3)), attributes={'id': 3}), ]) with TestDir() as test_dir: self._test_save_and_load( TestExtractor(), CocoConverter(tasks='image_info', save_images=True), test_dir)