本文主要是介绍modelscope 安装 使用实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
安装
图像融合例子:
多卡分配报错:
解决方法:
安装
pip install modelscope
图像融合例子:
import cv2
from modelscope.outputs import OutputKeys
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasksif __name__ == '__main__':image_face_fusion = pipeline(Tasks.image_face_fusion,model='damo/cv_unet-image-face-fusion_damo')template_path = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/facefusion_template.jpg'user_path = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/facefusion_user.jpg'result = image_face_fusion(dict(template=template_path, user=user_path))cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])print('finished!')
多卡分配报错:
Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:0
解决方法:
Lib\site-packages\modelscope\models\cv\image_face_fusion\image_face_fusion.py
中,改之后的代码:
self.device = torch.device('cuda:0')
def __init__(self, model_dir: str, *args, **kwargs):"""initialize the image face fusion model from the `model_dir` path.Args:model_dir (str): the model path."""super().__init__(model_dir, *args, **kwargs)if torch.cuda.is_available():self.device = torch.device('cuda:0')else:self.device = torch.device('cpu')
这篇关于modelscope 安装 使用实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!