我正在制作一个修复应用程序,我几乎得到了想要的结果,除了管道对象输出512 * 512的图像,无论我传递的分辨率如何.我在CPU上运行这个,它是onnx转换,AMD友好版本的稳定扩散.

以下是我认为相关的代码:

class CustomDiffuser:
    def __init__(self, provider:Literal['CPUExecutionProvider', 'DmlExecutionProvider']='CPUExecutionProvider'):

        self.pipe_text2image = None
        self.pipe_inpaint = None
        self.image = None
        self.sam = None
        self.provider = provider


    def load_model_for_inpainting(
            self, 
            path: str = '../stable_diffusion_onnx_inpainting', 
            safety_checker=None
    ):
        self.pipe_inpaint = OnnxStableDiffusionInpaintPipeline.from_pretrained(path, provider=self.provider, revision='onnx', safety_checker=safety_checker)        


    def inpaint_with_prompt(
            self, 
            image: cv2.typing.MatLike | Image.Image, 
            mask: cv2.typing.MatLike | Image.Image,
            height: int, 
            width: int,             
            prompt: str = '', 
            negative: str = '',
            steps: int = 10, 
            cfg: float =  7.5,
            noise: float = 0.75
    ):

        pipe = self.pipe_inpaint

        image = image.resize((width, height))
        mask = mask.resize((width, height))

        output_image = pipe(
            prompt,
            image,
            mask,
            #strength=noise,
            guidance_scale=cfg
        )

        return output_image

  
diffuser = CustomDiffuser('CPUExecutionProvider')
    
diffuser.load_model_for_inpainting('C:/path/to/repository/stable_diffusion_onnx_inpainting')

output = diffuser.inpaint_with_prompt(
    Image.open(image_path),
    Image.fromarray(headless_selfie_mask.astype(np.uint8)),
    576, #height first 
    384,                
    'a picture of a man dressed in a darth vader costume, full body shot, front view, light saber',
    ''
)
 

推荐答案

您需要按如下方式传递高度和宽度:

output_image = pipe(
    prompt,
    image,
    mask,
    height,
    width,
    #strength=noise,
    guidance_scale=cfg
)

如果你判断源代码—heightwidth默认为512.

Python相关问答推荐

如何在类和classy-fastapi -fastapi- followup中使用FastAPI创建路由

如何使用根据其他值相似的列从列表中获取的中间值填充空NaN数据

我们可以为Flask模型中的id字段主键设置默认uuid吗

Pandas—合并数据帧,在公共列上保留非空值,在另一列上保留平均值

Python—从np.array中 Select 复杂的列子集

关于Python异步编程的问题和使用await/await def关键字

如何设置视频语言时上传到YouTube与Python API客户端

从嵌套的yaml创建一个嵌套字符串,后面跟着点

如何从需要点击/切换的网页中提取表格?

如果初始groupby找不到满足掩码条件的第一行,我如何更改groupby列,以找到它?

为什么常规操作不以其就地对应操作为基础?

Pandas—MultiIndex Resample—我不想丢失其他索引的信息´

如何过滤组s最大和最小行使用`transform`'

分解polars DataFrame列而不重复其他列值

用0填充没有覆盖范围的垃圾箱

普洛特利express 发布的人口普查数据失败

利用广播使减法更有效率

如何在Django查询集中生成带有值列表的带注释的字段?

根据边界点的属性将图划分为子图

如何计算Pandas 中具有特定条件的行之间的天差