def test_directory_parsing_label_dataset(self): dataset = DirectoryParsingLabelDataset( 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_label_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 = DirectoryParsingLabelDataset( self.tmp_dir, numerical_sort=True) assert_is_label_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_label_dataset(self): if hasattr(self, 'option'): dataset = self.dataset(self.color, self.option) else: dataset = self.dataset(self.color) if self.valid: assert_is_label_dataset(dataset, 20, color=self.color) else: with self.assertRaises(AssertionError): assert_is_label_dataset(dataset, 20, color=self.color)
def test_cub_label_dataset(self): assert_is_label_dataset( self.dataset, len(cub_label_names), n_example=10) idx = np.random.choice(np.arange(10)) if self.return_bb: bb = self.dataset[idx][2] assert_is_bbox(bb[np.newaxis]) if self.return_prob_map: img = self.dataset[idx][0] prob_map = self.dataset[idx][-1] self.assertEqual(prob_map.dtype, np.float32) self.assertEqual(prob_map.shape, img.shape[1:]) self.assertTrue(np.min(prob_map) >= 0) self.assertTrue(np.max(prob_map) <= 1)
def test_online_products_dataset(self): assert_is_label_dataset( self.dataset, 22634, n_example=10) for _ in range(10): i = np.random.randint(0, len(self.dataset)) _, _, super_label = self.dataset[i] assert isinstance(super_label, np.int32), \ 'label must be a numpy.int32.' assert super_label.ndim == 0, 'The ndim of label must be 0' assert (super_label >= 0 and super_label < len(online_products_super_label_names)), \ 'The value of label must be in [0, n_class - 1].'
def test_cub_label_dataset(self): assert_is_label_dataset(self.dataset, len(cub_label_names), n_example=10) idx = np.random.choice(np.arange(10)) if self.return_bb: bb = self.dataset[idx][2] assert_is_bbox(bb[np.newaxis]) if self.return_prob_map: img = self.dataset[idx][0] prob_map = self.dataset[idx][-1] self.assertEqual(prob_map.dtype, np.float32) self.assertEqual(prob_map.shape, img.shape[1:]) self.assertTrue(np.min(prob_map) >= 0) self.assertTrue(np.max(prob_map) <= 1)