|
|
@@ -15,7 +15,7 @@ class EasyCVSegmentationPipelineTest(unittest.TestCase): |
|
|
|
|
|
|
|
|
img_path = 'data/test/images/image_segmentation.jpg' |
|
|
img_path = 'data/test/images/image_segmentation.jpg' |
|
|
|
|
|
|
|
|
def _internal_test__(self, model_id): |
|
|
|
|
|
|
|
|
def _internal_test_(self, model_id): |
|
|
img = np.asarray(Image.open(self.img_path)) |
|
|
img = np.asarray(Image.open(self.img_path)) |
|
|
|
|
|
|
|
|
semantic_seg = pipeline(task=Tasks.image_segmentation, model=model_id) |
|
|
semantic_seg = pipeline(task=Tasks.image_segmentation, model=model_id) |
|
|
@@ -26,12 +26,8 @@ class EasyCVSegmentationPipelineTest(unittest.TestCase): |
|
|
results = outputs[0] |
|
|
results = outputs[0] |
|
|
self.assertListEqual( |
|
|
self.assertListEqual( |
|
|
list(img.shape)[:2], list(results['seg_pred'].shape)) |
|
|
list(img.shape)[:2], list(results['seg_pred'].shape)) |
|
|
self.assertListEqual(results['seg_pred'][1, 4:10].tolist(), |
|
|
|
|
|
[161 for i in range(6)]) |
|
|
|
|
|
self.assertListEqual(results['seg_pred'][-1, -10:].tolist(), |
|
|
|
|
|
[133 for i in range(10)]) |
|
|
|
|
|
|
|
|
|
|
|
def _internal_test_batch(self, model_id, num_samples=2, batch_size=2): |
|
|
|
|
|
|
|
|
def _internal_test_batch_(self, model_id, num_samples=2, batch_size=2): |
|
|
# TODO: support in the future |
|
|
# TODO: support in the future |
|
|
img = np.asarray(Image.open(self.img_path)) |
|
|
img = np.asarray(Image.open(self.img_path)) |
|
|
num_samples = num_samples |
|
|
num_samples = num_samples |
|
|
@@ -48,40 +44,42 @@ class EasyCVSegmentationPipelineTest(unittest.TestCase): |
|
|
for output in outputs: |
|
|
for output in outputs: |
|
|
self.assertListEqual( |
|
|
self.assertListEqual( |
|
|
list(img.shape)[:2], list(output['seg_pred'].shape)) |
|
|
list(img.shape)[:2], list(output['seg_pred'].shape)) |
|
|
self.assertListEqual(output['seg_pred'][1, 4:10].tolist(), |
|
|
|
|
|
[161 for i in range(6)]) |
|
|
|
|
|
self.assertListEqual(output['seg_pred'][-1, -10:].tolist(), |
|
|
|
|
|
[133 for i in range(10)]) |
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
def test_segformer_b0(self): |
|
|
def test_segformer_b0(self): |
|
|
model_id = 'damo/cv_segformer-b0_image_semantic-segmentation_coco-stuff164k' |
|
|
model_id = 'damo/cv_segformer-b0_image_semantic-segmentation_coco-stuff164k' |
|
|
self._internal_test__(model_id) |
|
|
|
|
|
|
|
|
self._internal_test_(model_id) |
|
|
|
|
|
self._internal_test_batch_(model_id) |
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
def test_segformer_b1(self): |
|
|
def test_segformer_b1(self): |
|
|
model_id = 'damo/cv_segformer-b1_image_semantic-segmentation_coco-stuff164k' |
|
|
model_id = 'damo/cv_segformer-b1_image_semantic-segmentation_coco-stuff164k' |
|
|
self._internal_test__(model_id) |
|
|
|
|
|
|
|
|
self._internal_test_(model_id) |
|
|
|
|
|
self._internal_test_batch_(model_id) |
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
def test_segformer_b2(self): |
|
|
def test_segformer_b2(self): |
|
|
model_id = 'damo/cv_segformer-b2_image_semantic-segmentation_coco-stuff164k' |
|
|
model_id = 'damo/cv_segformer-b2_image_semantic-segmentation_coco-stuff164k' |
|
|
self._internal_test__(model_id) |
|
|
|
|
|
|
|
|
self._internal_test_(model_id) |
|
|
|
|
|
self._internal_test_batch_(model_id) |
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
def test_segformer_b3(self): |
|
|
def test_segformer_b3(self): |
|
|
model_id = 'damo/cv_segformer-b3_image_semantic-segmentation_coco-stuff164k' |
|
|
model_id = 'damo/cv_segformer-b3_image_semantic-segmentation_coco-stuff164k' |
|
|
self._internal_test__(model_id) |
|
|
|
|
|
|
|
|
self._internal_test_(model_id) |
|
|
|
|
|
self._internal_test_batch_(model_id) |
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
def test_segformer_b4(self): |
|
|
def test_segformer_b4(self): |
|
|
model_id = 'damo/cv_segformer-b4_image_semantic-segmentation_coco-stuff164k' |
|
|
model_id = 'damo/cv_segformer-b4_image_semantic-segmentation_coco-stuff164k' |
|
|
self._internal_test__(model_id) |
|
|
|
|
|
|
|
|
self._internal_test_(model_id) |
|
|
|
|
|
self._internal_test_batch_(model_id) |
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level') |
|
|
def test_segformer_b5(self): |
|
|
def test_segformer_b5(self): |
|
|
model_id = 'damo/cv_segformer-b5_image_semantic-segmentation_coco-stuff164k' |
|
|
model_id = 'damo/cv_segformer-b5_image_semantic-segmentation_coco-stuff164k' |
|
|
self._internal_test__(model_id) |
|
|
|
|
|
|
|
|
self._internal_test_(model_id) |
|
|
|
|
|
self._internal_test_batch_(model_id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
|