From 9866d770a6a75eb0a9ca0d1f3a31154a07a9024b Mon Sep 17 00:00:00 2001 From: qinxuye Date: Tue, 1 Oct 2024 15:55:17 +0800 Subject: [PATCH] Fix adetailer --- xinference/model/image/adetailer.py | 11 ++++++++++- xinference/model/image/sdapi.py | 4 +--- xinference/model/image/stable_diffusion/core.py | 7 +++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/xinference/model/image/adetailer.py b/xinference/model/image/adetailer.py index 359923b24d..b8393662af 100644 --- a/xinference/model/image/adetailer.py +++ b/xinference/model/image/adetailer.py @@ -277,6 +277,10 @@ def pred_preprocessing(pred: PredictOutput, args: ADetailerArgs): new_kwargs["image"] = ensure_pil_image(init_image, "RGB") denoising_strength = new_kwargs.get("strength") new_kwargs["strength"] = get_dynamic_denoise_strength(denoising_strength, pred.bboxes[j], image.size) # type: ignore + if adetailer.ad_inpaint_only_masked: + new_kwargs[ + "padding_mask_crop" + ] = adetailer.ad_inpaint_only_masked_padding # Don't override user-defined dimensions. if not adetailer.ad_use_inpaint_width_height: @@ -284,7 +288,12 @@ def pred_preprocessing(pred: PredictOutput, args: ADetailerArgs): width, height, pred.bboxes[j] ) - init_image = model.image_to_image(**new_kwargs)[0] # type: ignore + if "width" in new_kwargs and "size" not in new_kwargs: + new_kwargs[ + "size" + ] = f"{new_kwargs.pop('width')} * {new_kwargs.pop('height')}" + + init_image = model.inpainting(**new_kwargs)[0] # type: ignore image = init_image diff --git a/xinference/model/image/sdapi.py b/xinference/model/image/sdapi.py index 1b28701678..83295eab8e 100644 --- a/xinference/model/image/sdapi.py +++ b/xinference/model/image/sdapi.py @@ -192,9 +192,7 @@ def txt2img(self, **kwargs): "created": int(time.time()), } for i, result_image in enumerate(result_images): - result["data"][i]["b64_json"] = encode_pil_to_base64( - result_image - ).decode() + result["data"][i]["b64_json"] = encode_pil_to_base64(result_image) # convert to SD API result return { diff --git a/xinference/model/image/stable_diffusion/core.py b/xinference/model/image/stable_diffusion/core.py index d55f60b062..abc82cd354 100644 --- a/xinference/model/image/stable_diffusion/core.py +++ b/xinference/model/image/stable_diffusion/core.py @@ -530,7 +530,8 @@ def inpainting( logger.debug("Process mask image with mask_blur: %s", mask_blur) mask_image = model.mask_processor.blur(mask_image, blur_factor=mask_blur) # type: ignore - width, height = map(int, re.split(r"[^\d]+", size)) + if "width" not in kwargs: + kwargs["width"], kwargs["height"] = map(int, re.split(r"[^\d]+", size)) if padding_image_to_multiple := kwargs.pop("padding_image_to_multiple", None): # Model like SD3 inpainting requires image's height and width is times of 16 @@ -543,14 +544,12 @@ def inpainting( mask_image, multiple=int(padding_image_to_multiple) ) # calculate actual image size after padding - width, height = image.size + kwargs["width"], kwargs["height"] = image.size return self._call_model( image=image, mask_image=mask_image, prompt=prompt, - height=height, - width=width, num_images_per_prompt=n, response_format=response_format, model=model,