2023-12-25 19:01:50 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.pipelines.cv.anydoor_pipeline import AnydoorPipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AnydoorTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.task = Tasks.image_to_image_generation
|
2023-12-26 16:59:47 +08:00
|
|
|
self.model_id = 'damo/AnyDoor_models'
|
2023-12-25 19:01:50 +08:00
|
|
|
|
2025-08-07 19:26:32 +08:00
|
|
|
@unittest.skipUnless(
|
|
|
|
|
test_level() >= 1,
|
|
|
|
|
'Skip to prevent a downgrade of huggingface_hub and transformers')
|
2023-12-25 19:01:50 +08:00
|
|
|
def test_run(self):
|
2024-01-17 22:19:05 +08:00
|
|
|
ref_image = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_anydoor_fg.jpg'
|
2023-12-27 00:08:20 +08:00
|
|
|
ref_mask = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_anydoor_fg_mask.png'
|
2024-01-17 22:19:05 +08:00
|
|
|
bg_image = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_anydoor_bg.png'
|
2023-12-27 00:08:20 +08:00
|
|
|
bg_mask = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_anydoor_bg_mask.png'
|
2023-12-25 19:01:50 +08:00
|
|
|
save_path = 'data/test/images/image_anydoor_gen.png'
|
|
|
|
|
|
|
|
|
|
anydoor_pipline: AnydoorPipeline = pipeline(
|
2025-05-13 22:52:57 +08:00
|
|
|
self.task, model=self.model_id, trust_remote_code=True)
|
2023-12-25 19:01:50 +08:00
|
|
|
out = anydoor_pipline((ref_image, ref_mask, bg_image, bg_mask))
|
|
|
|
|
image = out['output_img']
|
|
|
|
|
image.save(save_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|