From ce41ded4237bc7e2279cf4aff10fa3a21dd1c075 Mon Sep 17 00:00:00 2001 From: "pengyu.lpy" Date: Thu, 1 Sep 2022 15:48:40 +0800 Subject: [PATCH] [to #42322933]modify test_segmentation_pipeline.py for damo models MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 基于easycv上线的segformer,对应上传了5个对应的达摩院的分割模型,所以修正了tests/pipelines/easycv_pipelines/test_segmentation_pipeline.py内容让其能够便利测试 Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9934634 --- .../test_segmentation_pipeline.py | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/tests/pipelines/easycv_pipelines/test_segmentation_pipeline.py b/tests/pipelines/easycv_pipelines/test_segmentation_pipeline.py index 0eca2a7f..6cfdacc6 100644 --- a/tests/pipelines/easycv_pipelines/test_segmentation_pipeline.py +++ b/tests/pipelines/easycv_pipelines/test_segmentation_pipeline.py @@ -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()