def test_can_save_and_load_with_landmarks(self): source_dataset = Dataset.from_iterable([ DatasetItem(id='name0/name0_0001', subset='test', image=np.ones((2, 5, 3)), attributes={ 'positive_pairs': ['name0/name0_0002'], 'negative_pairs': [] }, annotations=[ Points([0, 4, 3, 3, 2, 2, 1, 0, 3, 0]), ] ), DatasetItem(id='name0/name0_0002', subset='test', image=np.ones((2, 5, 3)), attributes={ 'positive_pairs': [], 'negative_pairs': [] }, annotations=[ Points([0, 5, 3, 5, 2, 2, 1, 0, 3, 0]), ] ), ]) with TestDir() as test_dir: LfwConverter.convert(source_dataset, test_dir, save_images=True) parsed_dataset = Dataset.import_from(test_dir, 'lfw') compare_datasets(self, source_dataset, parsed_dataset)
def test_can_save_and_load_with_no_save_images(self): source_dataset = Dataset.from_iterable([ DatasetItem( id='name0_0001', subset='test', image=np.ones((2, 5, 3)), annotations=[ Label(0, attributes={'positive_pairs': ['name0/name0_0002']}) ]), DatasetItem(id='name0_0002', subset='test', image=np.ones((2, 5, 3)), annotations=[ Label(0, attributes={ 'positive_pairs': ['name0/name0_0001'], 'negative_pairs': ['name1/name1_0001'] }) ]), DatasetItem(id='name1_0001', subset='test', image=np.ones((2, 5, 3)), annotations=[Label(1, attributes={})]), ], categories=['name0', 'name1']) with TestDir() as test_dir: LfwConverter.convert(source_dataset, test_dir, save_images=False) parsed_dataset = Dataset.import_from(test_dir, 'lfw') compare_datasets(self, source_dataset, parsed_dataset)
def test_can_save_and_load_with_no_format_names(self): source_dataset = Dataset.from_iterable([ DatasetItem( id='a/1', image=np.ones((2, 5, 3)), annotations=[ Label(0, attributes={ 'positive_pairs': ['name0/b/2'], 'negative_pairs': ['d/4'] }) ], ), DatasetItem( id='b/2', image=np.ones((2, 5, 3)), annotations=[Label(0)]), DatasetItem( id='c/3', image=np.ones((2, 5, 3)), annotations=[Label(1)]), DatasetItem( id='d/4', image=np.ones((2, 5, 3)), ), ], categories=['name0', 'name1']) with TestDir() as test_dir: LfwConverter.convert(source_dataset, test_dir, save_images=True) parsed_dataset = Dataset.import_from(test_dir, 'lfw') compare_datasets(self, source_dataset, parsed_dataset)
def test_can_save_and_load_with_meta_file(self): source_dataset = Dataset.from_iterable([ DatasetItem( id='name0_0001', subset='test', image=np.ones((2, 5, 3)), annotations=[ Label(0, attributes={'positive_pairs': ['name0/name0_0002']}) ]), DatasetItem(id='name0_0002', subset='test', image=np.ones((2, 5, 3)), annotations=[ Label(0, attributes={ 'positive_pairs': ['name0/name0_0001'], 'negative_pairs': ['name1/name1_0001'] }) ]), DatasetItem( id='name1_0001', subset='test', image=np.ones((2, 5, 3)), annotations=[ Label(1, attributes={'positive_pairs': ['name1/name1_0002']}) ]), DatasetItem(id='name1_0002', subset='test', image=np.ones((2, 5, 3)), annotations=[ Label(1, attributes={ 'positive_pairs': ['name1/name1_0002'], 'negative_pairs': ['name0/name0_0001'] }) ]), ], categories=['name0', 'name1']) with TestDir() as test_dir: LfwConverter.convert(source_dataset, test_dir, save_images=True, save_dataset_meta=True) parsed_dataset = Dataset.import_from(test_dir, 'lfw') self.assertTrue(osp.isfile(osp.join(test_dir, 'dataset_meta.json'))) compare_datasets(self, source_dataset, parsed_dataset, require_images=True)
def test_can_save_and_load_image_with_arbitrary_extension(self): dataset = Dataset.from_iterable([ DatasetItem(id='a/1', image=Image(path='a/1.JPEG', data=np.zeros((4, 3, 3))), annotations=[Label(0)]), DatasetItem(id='b/c/d/2', image=Image(path='b/c/d/2.bmp', data=np.zeros((3, 4, 3))), annotations=[Label(1)]), ], categories=['name0', 'name1']) with TestDir() as test_dir: LfwConverter.convert(dataset, test_dir, save_images=True) parsed_dataset = Dataset.import_from(test_dir, 'lfw') compare_datasets(self, dataset, parsed_dataset, require_images=True)
def test_can_save_and_load_image_with_arbitrary_extension(self): dataset = Dataset.from_iterable([ DatasetItem(id='name0/name0_0001', image=Image( path='name0/name0_0001.JPEG', data=np.zeros((4, 3, 3))), attributes={ 'positive_pairs': [], 'negative_pairs': [] }, ), DatasetItem(id='name0/name0_0002', image=Image( path='name0/name0_0002.bmp', data=np.zeros((3, 4, 3))), attributes={ 'positive_pairs': ['name0/name0_0001'], 'negative_pairs': [] }, ), ]) with TestDir() as test_dir: LfwConverter.convert(dataset, test_dir, save_images=True) parsed_dataset = Dataset.import_from(test_dir, 'lfw') compare_datasets(self, dataset, parsed_dataset, require_images=True)
def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self): dataset = Dataset.from_iterable([ DatasetItem(id='кириллица с пробелом', image=np.ones((2, 5, 3)), attributes = { 'positive_pairs': [], 'negative_pairs': [] }, ), DatasetItem(id='name0/name0_0002', image=np.ones((2, 5, 3)), attributes = { 'positive_pairs': [], 'negative_pairs': ['кириллица с пробелом'] }, ), ]) with TestDir() as test_dir: LfwConverter.convert(dataset, test_dir, save_images=True) parsed_dataset = Dataset.import_from(test_dir, 'lfw') compare_datasets(self, dataset, parsed_dataset, require_images=True)
def test_can_save_and_load(self): source_dataset = Dataset.from_iterable([ DatasetItem(id='name0/name0_0001', subset='test', image=np.ones((2, 5, 3)), attributes={ 'positive_pairs': ['name0/name0_0002'], 'negative_pairs': [] } ), DatasetItem(id='name0/name0_0002', subset='test', image=np.ones((2, 5, 3)), attributes={ 'positive_pairs': ['name0/name0_0001'], 'negative_pairs': ['name1/name1_0001'] } ), DatasetItem(id='name1/name1_0001', subset='test', image=np.ones((2, 5, 3)), attributes={ 'positive_pairs': ['name1/name1_0002'], 'negative_pairs': [] } ), DatasetItem(id='name1/name1_0002', subset='test', image=np.ones((2, 5, 3)), attributes={ 'positive_pairs': ['name1/name1_0002'], 'negative_pairs': ['name0/name0_0001'] } ), ]) with TestDir() as test_dir: LfwConverter.convert(source_dataset, test_dir, save_images=True) parsed_dataset = Dataset.import_from(test_dir, 'lfw') compare_datasets(self, source_dataset, parsed_dataset)