[to #42322933]modify test_segmentation_pipeline.py for damo models

基于easycv上线的segformer,对应上传了5个对应的达摩院的分割模型,所以修正了tests/pipelines/easycv_pipelines/test_segmentation_pipeline.py内容让其能够便利测试
        Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9934634
This commit is contained in:
pengyu.lpy
2022-09-01 15:48:40 +08:00
committed by yingda.chen
parent 3f97278564
commit ce41ded423

View File

@@ -12,24 +12,54 @@ from modelscope.utils.test_utils import test_level
class EasyCVSegmentationPipelineTest(unittest.TestCase):
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_segformer_b0(self):
img_path = 'data/test/images/image_segmentation.jpg'
model_id = 'EasyCV/EasyCV-Segformer-b0'
img = np.asarray(Image.open(img_path))
img_path = 'data/test/images/image_segmentation.jpg'
def _internal_test__(self, model_id):
img = np.asarray(Image.open(self.img_path))
semantic_seg = pipeline(task=Tasks.image_segmentation, model=model_id)
outputs = semantic_seg(self.img_path)
object_detect = pipeline(task=Tasks.image_segmentation, model=model_id)
outputs = object_detect(img_path)
self.assertEqual(len(outputs), 1)
results = outputs[0]
self.assertListEqual(
list(img.shape)[:2], list(results['seg_pred'][0].shape))
self.assertListEqual(results['seg_pred'][0][1, :10].tolist(),
[161 for i in range(10)])
self.assertListEqual(results['seg_pred'][0][1, 4:10].tolist(),
[161 for i in range(6)])
self.assertListEqual(results['seg_pred'][0][-1, -10:].tolist(),
[133 for i in range(10)])
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_segformer_b0(self):
model_id = 'damo/cv_segformer-b0_image_semantic-segmentation_coco-stuff164k'
self._internal_test__(model_id)
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_segformer_b1(self):
model_id = 'damo/cv_segformer-b1_image_semantic-segmentation_coco-stuff164k'
self._internal_test__(model_id)
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_segformer_b2(self):
model_id = 'damo/cv_segformer-b2_image_semantic-segmentation_coco-stuff164k'
self._internal_test__(model_id)
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_segformer_b3(self):
model_id = 'damo/cv_segformer-b3_image_semantic-segmentation_coco-stuff164k'
self._internal_test__(model_id)
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_segformer_b4(self):
model_id = 'damo/cv_segformer-b4_image_semantic-segmentation_coco-stuff164k'
self._internal_test__(model_id)
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
def test_segformer_b5(self):
model_id = 'damo/cv_segformer-b5_image_semantic-segmentation_coco-stuff164k'
self._internal_test__(model_id)
if __name__ == '__main__':
unittest.main()