def _check_example(example, n_fg_class): assert len(example) >= 3, \ 'Each example must have at least four elements:' \ 'img, mask and label.' img, mask, label = example[:3] assert_is_image(img, color=True) _, H, W = img.shape R = mask.shape[0] assert isinstance(mask, np.ndarray), \ 'mask must be a numpy.ndarray.' assert isinstance(label, np.ndarray), \ 'label must be a numpy.ndarray.' assert mask.dtype == np.bool, \ 'The type of mask must be bool' assert label.dtype == np.int32, \ 'The type of label must be numpy.int32.' assert mask.shape == (R, H, W), \ 'The shape of mask must be (R, H, W).' assert label.shape == (R,), \ 'The shape of label must be (R, ).' assert label.min() >= 0 and label.max() < n_fg_class, \ 'The value of label must be in [0, n_fg_class - 1].'
def _check_example(example, n_fg_class): assert len(example) >= 4, \ 'Each example must have at least four elements:' \ 'img, bbox, mask and label.' img, bbox, mask, label = example[:4] assert_is_image(img, color=True) _, H, W = img.shape assert_is_bbox(bbox, size=(H, W)) R = bbox.shape[0] assert isinstance(mask, np.ndarray), \ 'mask must be a numpy.ndarray.' assert isinstance(label, np.ndarray), \ 'label must be a numpy.ndarray.' assert mask.dtype == np.bool, \ 'The type of mask must be bool' assert label.dtype == np.int32, \ 'The type of label must be numpy.int32.' assert mask.shape == (R, H, W), \ 'The shape of mask must be (R, H, W).' assert label.shape == (R,), \ 'The shape of label must be (R, ).' assert label.min() >= 0 and label.max() < n_fg_class, \ 'The value of label must be in [0, n_fg_class - 1].'
def _check_example(self, example): assert_is_image(example[0]) assert example[0].shape == self.img_shape assert example[1].dtype == np.float32 assert example[1].ndim == 1 assert len(example[1]) == self.n_class np.testing.assert_almost_equal(example[1].sum(), 1.0) assert (example[1] >= 0.0).all()
def _check_example(self, example): assert_is_image(example[0]) self.assertEqual(example[0].shape, self.img_shape) self.assertEqual(example[1].dtype, np.float32) self.assertEqual(example[1].ndim, 1) self.assertEqual(example[1].shape[0], self.n_class) self.assertAlmostEqual(example[1].sum(), 1.0) self.assertGreaterEqual(np.min(example[1]), 0.0)
def _check_example(self, example): assert_is_image(example[0]) self.assertEqual(example[0].shape, self.img_shape) assert_is_image(example[2]) self.assertEqual(example[2].shape, self.img_shape) self.assertIsInstance(example[1], np.int32) self.assertEqual(example[1].ndim, 0) self.assertTrue(example[1] >= 0 and example[1] < self.n_class) self.assertIsInstance(example[3], np.int32) self.assertEqual(example[3].ndim, 0) self.assertTrue(example[3] >= 0 and example[1] < self.n_class)
def _check_example(self, example): assert_is_image(example[0]) self.assertEqual(example[0].shape, self.img_shape) assert_is_image(example[2]) self.assertEqual(example[2].shape, self.img_shape) self.assertIsInstance(example[1], np.int32) self.assertEqual(example[1].ndim, 0) self.assertTrue(example[1] >= 0 and example[1] < self.n_class) self.assertIsInstance(example[3], np.int32) self.assertEqual(example[3].ndim, 0) self.assertTrue(example[3] >= 0 and example[1] < self.n_class)
def _check_example(example, n_point=None, no_visible=False): assert len(example) >= 2, \ 'Each example must have at least two elements:' \ 'img, point (visible is optional).' if len(example) == 2 or no_visible: img, point = example[:2] visible = None elif len(example) >= 3: img, point, visible = example[:3] assert_is_image(img, color=True) assert_is_point(point, visible, img.shape[1:], n_point)
def _check_example(example, n_class, color): assert len(example) >= 2, \ 'Each example must have at least two elements:' \ 'img and label.' img, label = example[:2] assert_is_image(img, color=color) assert isinstance(label, np.int32), \ 'label must be a numpy.int32.' assert label.ndim == 0, 'The ndim of label must be 0' assert label >= 0 and label < n_class, \ 'The value of label must be in [0, n_class - 1].'
def _check_example(example, n_class): assert len(example) >= 2, \ 'Each example must have at least two elements:' \ 'img and label.' img, label = example[:2] assert_is_image(img, color=True) assert isinstance(label, np.ndarray), \ 'label must be a numpy.ndarray.' assert label.dtype == np.int32, \ 'The type of label must be numpy.int32.' assert label.shape == img.shape[1:], \ 'The shape of label must be (H, W).' assert label.min() >= -1 and label.max() < n_class, \ 'The value of label must be in [-1, n_class - 1].'
def _check_example(example, n_point=None, no_mask=False): assert len(example) >= 2, \ 'Each example must have at least two elements:' \ 'img, point (mask is optional).' if len(example) == 2 or no_mask: img, point = example[:2] mask = None elif len(example) >= 3: img, point, mask = example[:3] assert_is_image(img, color=True) assert_is_point(point, mask, img.shape[1:]) if n_point is not None: assert point.shape[0] == n_point, \ 'The number of points is different from the expected number.'
def _check_example(example, n_fg_class): assert len(example) >= 3, \ 'Each example must have at least three elements:' \ 'img, bbox and label.' img, bbox, label = example[:3] assert_is_image(img, color=True) assert_is_bbox(bbox, size=img.shape[1:]) assert isinstance(label, np.ndarray), \ 'label must be a numpy.ndarray.' assert label.dtype == np.int32, \ 'The type of label must be numpy.int32.' assert label.shape[1:] == (), \ 'The shape of label must be (*,).' assert len(label) == len(bbox), \ 'The length of label must be same as that of bbox.' assert label.min() >= 0 and label.max() < n_fg_class, \ 'The value of label must be in [0, n_fg_class - 1].'
def test_cityscapes_dataset(self): indices = np.random.permutation(np.arange(len(self.dataset))) for i in indices[:10]: img = self.dataset[i] assert_is_image(img, color=True)
def test_ade20k_dataset(self): indices = np.random.permutation(np.arange(len(self.dataset))) for i in indices[:10]: img = self.dataset[i] assert_is_image(img, color=True)