Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: support padding for sd inpainting model #2165

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions xinference/model/image/stable_diffusion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,19 @@ def image_to_image(
self._i2i_model = model = AutoPipelineForImage2Image.from_pipe(
self._model
)
if size:
width, height = map(int, re.split(r"[^\d]+", size))
kwargs["width"] = width
kwargs["height"] = height

if padding_image_to_multiple := kwargs.pop("padding_image_to_multiple", None):
# Model like SD3 image to image requires image's height and width is times of 16
# padding the image if specified
image = self.pad_to_multiple(image, multiple=int(padding_image_to_multiple))

if size:
width, height = map(int, re.split(r"[^\d]+", size))
if padding_image_to_multiple:
width, height = image.size
kwargs["width"] = width
kwargs["height"] = height

self._filter_kwargs(kwargs)
return self._call_model(
image=image,
Expand All @@ -279,8 +283,8 @@ def image_to_image(

def inpainting(
self,
image: bytes,
mask_image: bytes,
image: PIL.Image,
mask_image: PIL.Image,
prompt: Optional[Union[str, List[str]]] = None,
negative_prompt: Optional[Union[str, List[str]]] = None,
n: int = 1,
Expand All @@ -306,6 +310,17 @@ def inpainting(
model = self._model

width, 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
# padding the image if specified
image = self.pad_to_multiple(image, multiple=int(padding_image_to_multiple))
mask_image = self.pad_to_multiple(
mask_image, multiple=int(padding_image_to_multiple)
)
# calculate actual image size after padding
width, height = image.size

return self._call_model(
image=image,
mask_image=mask_image,
Expand Down
Loading