def test_directory_parsing_classification_dataset(self): dataset = DirectoryParsingClassificationDataset(self.tmp_dir, color=self.color) if self.depth == 1: expected_legnth = self.n_img_per_class * self.n_class elif self.depth == 2: expected_legnth =\ self.n_img_per_class * self.n_sub_directory * self.n_class self.assertEqual(len(dataset), expected_legnth) assert_is_classification_dataset(dataset, self.n_class, color=self.color) label_names = directory_parsing_label_names(self.tmp_dir) self.assertEqual(label_names, ['class_{}'.format(i) for i in range(self.n_class)]) if self.depth == 1: self.assertEqual(dataset.img_paths, [ '{}/class_{}/img{}.{}'.format(self.tmp_dir, i, j, self.suffix) for i in range(self.n_class) for j in range(self.n_img_per_class) ]) elif self.depth == 2: self.assertEqual(dataset.img_paths, [ '{}/class_{}/nested_{}/img{}.{}'.format( self.tmp_dir, i, j, k, self.suffix) for i in range(self.n_class) for j in range(self.n_sub_directory) for k in range(self.n_img_per_class) ])
def test_numerical_sort(self): dataset = DirectoryParsingClassificationDataset(self.tmp_dir, numerical_sort=True) assert_is_classification_dataset(dataset, self.n_class) label_names = directory_parsing_label_names(self.tmp_dir, numerical_sort=True) self.assertEqual(label_names, ['{}'.format(i) for i in range(self.n_class)])
def test_assert_is_classification_dataset(self): if hasattr(self, 'option'): dataset = self.dataset(self.color, self.option) else: dataset = self.dataset(self.color) if self.valid: assert_is_classification_dataset(dataset, 20, color=self.color) else: with self.assertRaises(AssertionError): assert_is_classification_dataset(dataset, 20, color=self.color)