图片和代码信息被吞掉了,所以发在这里。 原帖:https://developer.aliyun.com/ask/489145
生成图片的效果如上图。
代码
import cv2 from modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks
text2image = pipeline(Tasks.text_to_image_synthesis, 'damo/cv_diffusion_text-to-image-synthesis_tiny') result = text2image({'text': '中国山水画'})
cv2.imwrite('result.png', result['output_imgs'][0])
环境 - Ubuntu 22.04 - Python 3.9.16 - T4 GPU
Log 2023-03-03 02:57:26,928 - modelscope - INFO - PyTorch version 1.13.1 Found. 2023-03-03 02:57:26,931 - modelscope - INFO - Loading ast index from /home/hysts/.cache/modelscope/ast_indexer 2023-03-03 02:57:26,964 - modelscope - INFO - Loading done! Current index file version is 1.3.2, with md5 854e410f5d06d85f558e291ae3a56af2 and a total number of 754 components indexed 2023-03-03 02:57:29,404 - modelscope - INFO - Model revision not specified, use the latest revision: v1.0.0 2023-03-03 02:57:29,752 - modelscope - INFO - File configuration.json already in cache, skip downloading! 2023-03-03 02:57:29,752 - modelscope - INFO - File diffusion_config.json already in cache, skip downloading! 2023-03-03 02:57:29,753 - modelscope - INFO - File model_config.json already in cache, skip downloading! 2023-03-03 02:57:29,753 - modelscope - INFO - File pytorch_model.bin already in cache, skip downloading! 2023-03-03 02:57:29,753 - modelscope - INFO - File README.md already in cache, skip downloading! 2023-03-03 02:57:29,753 - modelscope - INFO - File vocab.txt already in cache, skip downloading! 2023-03-03 02:57:32,282 - modelscope - INFO - initiate model from /home/hysts/.cache/modelscope/hub/damo/cv_diffusion_text-to-image-synthesis_tiny INFO:modelscope:initiate model from /home/hysts/.cache/modelscope/hub/damo/cv_diffusion_text-to-image-synthesis_tiny 2023-03-03 02:57:32,283 - modelscope - INFO - initiate model from location /home/hysts/.cache/modelscope/hub/damo/cv_diffusion_text-to-image-synthesis_tiny. INFO:modelscope:initiate model from location /home/hysts/.cache/modelscope/hub/damo/cv_diffusion_text-to-image-synthesis_tiny. 2023-03-03 02:57:32,284 - modelscope - INFO - initialize model from /home/hysts/.cache/modelscope/hub/damo/cv_diffusion_text-to-image-synthesis_tiny INFO:modelscope:initialize model from /home/hysts/.cache/modelscope/hub/damo/cv_diffusion_text-to-image-synthesis_tiny 2023-03-03 02:57:48,500 - modelscope - WARNING - No preprocessor field found in cfg. WARNING:modelscope:No preprocessor field found in cfg. 2023-03-03 02:57:48,500 - modelscope - WARNING - No val key and type key found in preprocessor domain of configuration.json file. WARNING:modelscope:No val key and type key found in preprocessor domain of configuration.json file. 2023-03-03 02:57:48,500 - modelscope - WARNING - Cannot find available config to build preprocessor at mode inference, current config: {'model_dir': '/home/hysts/.cache/modelscope/hub/damo/cv_diffusion_text-to-image-synthesis_tiny'}. trying to build by task and model information. WARNING:modelscope:Cannot find available config to build preprocessor at mode inference, current config: {'model_dir': '/home/hysts/.cache/modelscope/hub/damo/cv_diffusion_text-to-image-synthesis_tiny'}. trying to build by task and model information. 2023-03-03 02:57:48,500 - modelscope - WARNING - No preprocessor key ('diffusion-text-to-image-synthesis', 'text-to-image-synthesis') found in PREPROCESSOR_MAP, skip building preprocessor. WARNING:modelscope:No preprocessor key ('diffusion-text-to-image-synthesis', 'text-to-image-synthesis') found in PREPROCESSOR_MAP, skip building preprocessor.
貌似预览的效果和实际发出来有出入。。。
代码在这里
import cv2
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
text2image = pipeline(Tasks.text_to_image_synthesis, 'damo/cv_diffusion_text-to-image-synthesis_tiny')
result = text2image({'text': '中国山水画'})
cv2.imwrite('result.png', result['output_imgs'][0])