Skip to content

Commit

Permalink
Fix adetailer
Browse files Browse the repository at this point in the history
  • Loading branch information
qinxuye committed Oct 1, 2024
1 parent c1a7837 commit 9866d77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
11 changes: 10 additions & 1 deletion xinference/model/image/adetailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,23 @@ 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:
new_kwargs["width"], new_kwargs["height"] = get_optimal_crop_image_size(
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

Expand Down
4 changes: 1 addition & 3 deletions xinference/model/image/sdapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions xinference/model/image/stable_diffusion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 9866d77

Please sign in to comment.