From fa4f9db5facb65365cb0b19249637f776d25ebc5 Mon Sep 17 00:00:00 2001 From: "jianqiang.rjq" Date: Tue, 2 Aug 2022 11:01:09 +0800 Subject: [PATCH] =?UTF-8?q?[to=20#42322933]Merge=20request=20from=20?= =?UTF-8?q?=E9=9B=AA=E6=B4=9B:rename-style-transfer=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20Link:=20https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/co?= =?UTF-8?q?dereview/9588372?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modelscope/metainfo.py | 2 +- modelscope/pipelines/builder.py | 4 ++-- modelscope/pipelines/cv/__init__.py | 4 ++-- ...eline.py => image_style_transfer_pipeline.py} | 4 ++-- modelscope/utils/constant.py | 2 +- ..._transfer.py => test_image_style_transfer.py} | 16 +++++++++------- 6 files changed, 17 insertions(+), 15 deletions(-) rename modelscope/pipelines/cv/{style_transfer_pipeline.py => image_style_transfer_pipeline.py} (97%) rename tests/pipelines/{test_style_transfer.py => test_image_style_transfer.py} (80%) diff --git a/modelscope/metainfo.py b/modelscope/metainfo.py index 7713eb4f..a0ae7252 100644 --- a/modelscope/metainfo.py +++ b/modelscope/metainfo.py @@ -82,9 +82,9 @@ class Pipelines(object): image_color_enhance = 'csrnet-image-color-enhance' virtual_tryon = 'virtual_tryon' image_colorization = 'unet-image-colorization' + image_style_transfer = 'AAMS-style-transfer' image_super_resolution = 'rrdb-image-super-resolution' face_image_generation = 'gan-face-image-generation' - style_transfer = 'AAMS-style-transfer' product_retrieval_embedding = 'resnet50-product-retrieval-embedding' face_recognition = 'ir101-face-recognition-cfglint' image_instance_segmentation = 'cascade-mask-rcnn-swin-image-instance-segmentation' diff --git a/modelscope/pipelines/builder.py b/modelscope/pipelines/builder.py index 204a7208..577a7b57 100644 --- a/modelscope/pipelines/builder.py +++ b/modelscope/pipelines/builder.py @@ -103,8 +103,8 @@ DEFAULT_MODEL_FOR_PIPELINE = { Tasks.image_segmentation: (Pipelines.image_instance_segmentation, 'damo/cv_swin-b_image-instance-segmentation_coco'), - Tasks.style_transfer: (Pipelines.style_transfer, - 'damo/cv_aams_style-transfer_damo'), + Tasks.image_style_transfer: (Pipelines.image_style_transfer, + 'damo/cv_aams_style-transfer_damo'), Tasks.face_image_generation: (Pipelines.face_image_generation, 'damo/cv_gan_face-image-generation'), Tasks.image_super_resolution: (Pipelines.image_super_resolution, diff --git a/modelscope/pipelines/cv/__init__.py b/modelscope/pipelines/cv/__init__.py index c2fb9eaa..655e9f85 100644 --- a/modelscope/pipelines/cv/__init__.py +++ b/modelscope/pipelines/cv/__init__.py @@ -19,11 +19,11 @@ if TYPE_CHECKING: from .image_colorization_pipeline import ImageColorizationPipeline from .image_instance_segmentation_pipeline import ImageInstanceSegmentationPipeline from .image_matting_pipeline import ImageMattingPipeline + from .image_style_transfer_pipeline import ImageStyleTransferPipeline from .image_super_resolution_pipeline import ImageSuperResolutionPipeline from .image_to_image_generation_pipeline import Image2ImageGenerationePipeline from .image_to_image_translation_pipeline import Image2ImageTranslationPipeline from .product_retrieval_embedding_pipeline import ProductRetrievalEmbeddingPipeline - from .style_transfer_pipeline import StyleTransferPipeline from .live_category_pipeline import LiveCategoryPipeline from .ocr_detection_pipeline import OCRDetectionPipeline from .video_category_pipeline import VideoCategoryPipeline @@ -46,6 +46,7 @@ else: 'image_instance_segmentation_pipeline': ['ImageInstanceSegmentationPipeline'], 'image_matting_pipeline': ['ImageMattingPipeline'], + 'image_style_transfer_pipeline': ['ImageStyleTransferPipeline'], 'image_super_resolution_pipeline': ['ImageSuperResolutionPipeline'], 'image_to_image_translation_pipeline': ['Image2ImageTranslationPipeline'], @@ -55,7 +56,6 @@ else: 'image_to_image_generation_pipeline': ['Image2ImageGenerationePipeline'], 'ocr_detection_pipeline': ['OCRDetectionPipeline'], - 'style_transfer_pipeline': ['StyleTransferPipeline'], 'video_category_pipeline': ['VideoCategoryPipeline'], 'virtual_tryon_pipeline': ['VirtualTryonPipeline'], } diff --git a/modelscope/pipelines/cv/style_transfer_pipeline.py b/modelscope/pipelines/cv/image_style_transfer_pipeline.py similarity index 97% rename from modelscope/pipelines/cv/style_transfer_pipeline.py rename to modelscope/pipelines/cv/image_style_transfer_pipeline.py index efafc2a7..a67aaec2 100644 --- a/modelscope/pipelines/cv/style_transfer_pipeline.py +++ b/modelscope/pipelines/cv/image_style_transfer_pipeline.py @@ -16,8 +16,8 @@ logger = get_logger() @PIPELINES.register_module( - Tasks.style_transfer, module_name=Pipelines.style_transfer) -class StyleTransferPipeline(Pipeline): + Tasks.image_style_transfer, module_name=Pipelines.image_style_transfer) +class ImageStyleTransferPipeline(Pipeline): def __init__(self, model: str, **kwargs): """ diff --git a/modelscope/utils/constant.py b/modelscope/utils/constant.py index eb4bd5b6..25f6e5f8 100644 --- a/modelscope/utils/constant.py +++ b/modelscope/utils/constant.py @@ -35,8 +35,8 @@ class CVTasks(object): virtual_tryon = 'virtual-tryon' image_colorization = 'image-colorization' face_image_generation = 'face-image-generation' + image_style_transfer = 'image-style-transfer' image_super_resolution = 'image-super-resolution' - style_transfer = 'style-transfer' product_retrieval_embedding = 'product-retrieval-embedding' live_category = 'live-category' video_category = 'video-category' diff --git a/tests/pipelines/test_style_transfer.py b/tests/pipelines/test_image_style_transfer.py similarity index 80% rename from tests/pipelines/test_style_transfer.py rename to tests/pipelines/test_image_style_transfer.py index 7bf7f1c4..d16895ff 100644 --- a/tests/pipelines/test_style_transfer.py +++ b/tests/pipelines/test_image_style_transfer.py @@ -14,7 +14,7 @@ from modelscope.utils.constant import ModelFile, Tasks from modelscope.utils.test_utils import test_level -class StyleTransferTest(unittest.TestCase): +class ImageStyleTransferTest(unittest.TestCase): def setUp(self) -> None: self.model_id = 'damo/cv_aams_style-transfer_damo' @@ -23,18 +23,20 @@ class StyleTransferTest(unittest.TestCase): def test_run_by_direct_model_download(self): snapshot_path = snapshot_download(self.model_id) print('snapshot_path: {}'.format(snapshot_path)) - style_transfer = pipeline(Tasks.style_transfer, model=snapshot_path) + image_style_transfer = pipeline( + Tasks.image_style_transfer, model=snapshot_path) - result = style_transfer( + result = image_style_transfer( 'data/test/images/style_transfer_content.jpg', style='data/test/images/style_transfer_style.jpg') cv2.imwrite('result_styletransfer1.png', result[OutputKeys.OUTPUT_IMG]) @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') def test_run_modelhub(self): - style_transfer = pipeline(Tasks.style_transfer, model=self.model_id) + image_style_transfer = pipeline( + Tasks.image_style_transfer, model=self.model_id) - result = style_transfer( + result = image_style_transfer( 'data/test/images/style_transfer_content.jpg', style='data/test/images/style_transfer_style.jpg') cv2.imwrite('result_styletransfer2.png', result[OutputKeys.OUTPUT_IMG]) @@ -42,9 +44,9 @@ class StyleTransferTest(unittest.TestCase): @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_modelhub_default_model(self): - style_transfer = pipeline(Tasks.style_transfer) + image_style_transfer = pipeline(Tasks.image_style_transfer) - result = style_transfer( + result = image_style_transfer( 'data/test/images/style_transfer_content.jpg', style='data/test/images/style_transfer_style.jpg') cv2.imwrite('result_styletransfer3.png', result[OutputKeys.OUTPUT_IMG])