Files
modelscope/tests/pipelines/test_text_to_360panorama_image.py

72 lines
2.6 KiB
Python
Raw Permalink Normal View History

add text-to-360pano-image pipeline, mod cv requirements 7月份计划上线的360全景图生成模型,自研 模型权重文件地址https://www.modelscope.cn/models/damo/cv_diffusion_text-to-360panorama-image_generation/summary #### 依赖项说明 ##### 由于要使用xformers,torch版本最好使用1.13.1 ``` pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116 ``` ##### 对应的diffusers和xformers版本如下 ``` pip install -U diffusers==0.18.0 pip install xformers==0.0.16 pip install triton, accelerate, transformers ``` ##### ModelScope Library 需要使用cv ``` pip install modelscope pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html ``` ##### 此外,还需要安装第三方的一个库,Real-ESRGAN, 安装方法如下 ``` # Install basicsr - https://github.com/xinntao/BasicSR # We use BasicSR for both training and inference pip install basicsr # facexlib and gfpgan are for face enhancement pip install facexlib pip install gfpgan pip install Pillow pip install tqdm pip install realesrgan==0.3.0 ``` Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/13346430 * add text-to-360pano-image pipeline * add text-to-360pano-image pipeline, mod cv requirements * rm redundant files and cv requirements; add standard input and output definations * fix diffusers==0.18.0 and run test * fix diffusers==0.18.0 in multi-modal and run test again * add model_revision='v1.0.0' * fix yapf * add trycatch for enabling xformers * fix key error * add install xformers in test/setup * skip highres.fix in ci * feat: Fix conflict, auto commit by WebIDE
2023-07-27 11:33:39 +08:00
# Copyright (c) Alibaba, Inc. and its affiliates.
import subprocess
import sys
import tempfile
import unittest
import cv2
from modelscope.hub.snapshot_download import snapshot_download
from modelscope.outputs import OutputKeys
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.utils.logger import get_logger
from modelscope.utils.test_utils import test_level
logger = get_logger()
@unittest.skip('For need realesrgan')
add text-to-360pano-image pipeline, mod cv requirements 7月份计划上线的360全景图生成模型,自研 模型权重文件地址https://www.modelscope.cn/models/damo/cv_diffusion_text-to-360panorama-image_generation/summary #### 依赖项说明 ##### 由于要使用xformers,torch版本最好使用1.13.1 ``` pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116 ``` ##### 对应的diffusers和xformers版本如下 ``` pip install -U diffusers==0.18.0 pip install xformers==0.0.16 pip install triton, accelerate, transformers ``` ##### ModelScope Library 需要使用cv ``` pip install modelscope pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html ``` ##### 此外,还需要安装第三方的一个库,Real-ESRGAN, 安装方法如下 ``` # Install basicsr - https://github.com/xinntao/BasicSR # We use BasicSR for both training and inference pip install basicsr # facexlib and gfpgan are for face enhancement pip install facexlib pip install gfpgan pip install Pillow pip install tqdm pip install realesrgan==0.3.0 ``` Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/13346430 * add text-to-360pano-image pipeline * add text-to-360pano-image pipeline, mod cv requirements * rm redundant files and cv requirements; add standard input and output definations * fix diffusers==0.18.0 and run test * fix diffusers==0.18.0 in multi-modal and run test again * add model_revision='v1.0.0' * fix yapf * add trycatch for enabling xformers * fix key error * add install xformers in test/setup * skip highres.fix in ci * feat: Fix conflict, auto commit by WebIDE
2023-07-27 11:33:39 +08:00
class Text2360PanoramaImageTest(unittest.TestCase):
def setUp(self) -> None:
logger.info('start install xformers')
cmd = [
sys.executable, '-m', 'pip', 'install', 'xformers', '-f',
'https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html'
]
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
logger.info('install xformers finished')
self.task = Tasks.text_to_360panorama_image
self.model_id = 'damo/cv_diffusion_text-to-360panorama-image_generation'
self.prompt = 'The living room'
self.upscale = False
self.refinement = False
self.input = {
'prompt': self.prompt,
'upscale': self.upscale,
'refinement': self.refinement,
}
@unittest.skipUnless(test_level() >= 3, 'skip test due to gpu oom')
add text-to-360pano-image pipeline, mod cv requirements 7月份计划上线的360全景图生成模型,自研 模型权重文件地址https://www.modelscope.cn/models/damo/cv_diffusion_text-to-360panorama-image_generation/summary #### 依赖项说明 ##### 由于要使用xformers,torch版本最好使用1.13.1 ``` pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116 ``` ##### 对应的diffusers和xformers版本如下 ``` pip install -U diffusers==0.18.0 pip install xformers==0.0.16 pip install triton, accelerate, transformers ``` ##### ModelScope Library 需要使用cv ``` pip install modelscope pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html ``` ##### 此外,还需要安装第三方的一个库,Real-ESRGAN, 安装方法如下 ``` # Install basicsr - https://github.com/xinntao/BasicSR # We use BasicSR for both training and inference pip install basicsr # facexlib and gfpgan are for face enhancement pip install facexlib pip install gfpgan pip install Pillow pip install tqdm pip install realesrgan==0.3.0 ``` Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/13346430 * add text-to-360pano-image pipeline * add text-to-360pano-image pipeline, mod cv requirements * rm redundant files and cv requirements; add standard input and output definations * fix diffusers==0.18.0 and run test * fix diffusers==0.18.0 in multi-modal and run test again * add model_revision='v1.0.0' * fix yapf * add trycatch for enabling xformers * fix key error * add install xformers in test/setup * skip highres.fix in ci * feat: Fix conflict, auto commit by WebIDE
2023-07-27 11:33:39 +08:00
def test_run_by_direct_model_download(self):
from modelscope.pipelines.cv import Text2360PanoramaImagePipeline
add text-to-360pano-image pipeline, mod cv requirements 7月份计划上线的360全景图生成模型,自研 模型权重文件地址https://www.modelscope.cn/models/damo/cv_diffusion_text-to-360panorama-image_generation/summary #### 依赖项说明 ##### 由于要使用xformers,torch版本最好使用1.13.1 ``` pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116 ``` ##### 对应的diffusers和xformers版本如下 ``` pip install -U diffusers==0.18.0 pip install xformers==0.0.16 pip install triton, accelerate, transformers ``` ##### ModelScope Library 需要使用cv ``` pip install modelscope pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html ``` ##### 此外,还需要安装第三方的一个库,Real-ESRGAN, 安装方法如下 ``` # Install basicsr - https://github.com/xinntao/BasicSR # We use BasicSR for both training and inference pip install basicsr # facexlib and gfpgan are for face enhancement pip install facexlib pip install gfpgan pip install Pillow pip install tqdm pip install realesrgan==0.3.0 ``` Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/13346430 * add text-to-360pano-image pipeline * add text-to-360pano-image pipeline, mod cv requirements * rm redundant files and cv requirements; add standard input and output definations * fix diffusers==0.18.0 and run test * fix diffusers==0.18.0 in multi-modal and run test again * add model_revision='v1.0.0' * fix yapf * add trycatch for enabling xformers * fix key error * add install xformers in test/setup * skip highres.fix in ci * feat: Fix conflict, auto commit by WebIDE
2023-07-27 11:33:39 +08:00
output_image_path = tempfile.NamedTemporaryFile(suffix='.png').name
cache_path = snapshot_download(self.model_id)
pipeline = Text2360PanoramaImagePipeline(cache_path)
pipeline.group_key = self.task
output = pipeline(inputs=self.input)[OutputKeys.OUTPUT_IMG]
cv2.imwrite(output_image_path, output)
print(
'pipeline: the output image path is {}'.format(output_image_path))
@unittest.skipUnless(test_level() >= 3, 'skip test due to gpu oom')
add text-to-360pano-image pipeline, mod cv requirements 7月份计划上线的360全景图生成模型,自研 模型权重文件地址https://www.modelscope.cn/models/damo/cv_diffusion_text-to-360panorama-image_generation/summary #### 依赖项说明 ##### 由于要使用xformers,torch版本最好使用1.13.1 ``` pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116 ``` ##### 对应的diffusers和xformers版本如下 ``` pip install -U diffusers==0.18.0 pip install xformers==0.0.16 pip install triton, accelerate, transformers ``` ##### ModelScope Library 需要使用cv ``` pip install modelscope pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html ``` ##### 此外,还需要安装第三方的一个库,Real-ESRGAN, 安装方法如下 ``` # Install basicsr - https://github.com/xinntao/BasicSR # We use BasicSR for both training and inference pip install basicsr # facexlib and gfpgan are for face enhancement pip install facexlib pip install gfpgan pip install Pillow pip install tqdm pip install realesrgan==0.3.0 ``` Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/13346430 * add text-to-360pano-image pipeline * add text-to-360pano-image pipeline, mod cv requirements * rm redundant files and cv requirements; add standard input and output definations * fix diffusers==0.18.0 and run test * fix diffusers==0.18.0 in multi-modal and run test again * add model_revision='v1.0.0' * fix yapf * add trycatch for enabling xformers * fix key error * add install xformers in test/setup * skip highres.fix in ci * feat: Fix conflict, auto commit by WebIDE
2023-07-27 11:33:39 +08:00
def test_run_with_model_from_modelhub(self):
from modelscope.pipelines.cv import Text2360PanoramaImagePipeline
add text-to-360pano-image pipeline, mod cv requirements 7月份计划上线的360全景图生成模型,自研 模型权重文件地址https://www.modelscope.cn/models/damo/cv_diffusion_text-to-360panorama-image_generation/summary #### 依赖项说明 ##### 由于要使用xformers,torch版本最好使用1.13.1 ``` pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116 ``` ##### 对应的diffusers和xformers版本如下 ``` pip install -U diffusers==0.18.0 pip install xformers==0.0.16 pip install triton, accelerate, transformers ``` ##### ModelScope Library 需要使用cv ``` pip install modelscope pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html ``` ##### 此外,还需要安装第三方的一个库,Real-ESRGAN, 安装方法如下 ``` # Install basicsr - https://github.com/xinntao/BasicSR # We use BasicSR for both training and inference pip install basicsr # facexlib and gfpgan are for face enhancement pip install facexlib pip install gfpgan pip install Pillow pip install tqdm pip install realesrgan==0.3.0 ``` Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/13346430 * add text-to-360pano-image pipeline * add text-to-360pano-image pipeline, mod cv requirements * rm redundant files and cv requirements; add standard input and output definations * fix diffusers==0.18.0 and run test * fix diffusers==0.18.0 in multi-modal and run test again * add model_revision='v1.0.0' * fix yapf * add trycatch for enabling xformers * fix key error * add install xformers in test/setup * skip highres.fix in ci * feat: Fix conflict, auto commit by WebIDE
2023-07-27 11:33:39 +08:00
output_image_path = tempfile.NamedTemporaryFile(suffix='.png').name
pipeline_ins = pipeline(
task=Tasks.text_to_360panorama_image,
model=self.model_id,
model_revision='v1.0.0')
output = pipeline_ins(inputs=self.input)[OutputKeys.OUTPUT_IMG]
cv2.imwrite(output_image_path, output)
print(
'pipeline: the output image path is {}'.format(output_image_path))
if __name__ == '__main__':
unittest.main()