Skip to content

Commit

Permalink
set height and width for img2img pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
noskill committed Jan 10, 2025
1 parent 4e8dc28 commit 20d892f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions multigen/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def __init__(self, model_id, pipe: Optional[StableDiffusionImg2ImgPipeline] = No
self._input_image = None

def setup(self, fimage, image=None, strength=0.75,
guidance_scale=7.5, scale=None, timestep_spacing='linspace', **args):
guidance_scale=7.5, scale=None, timestep_spacing='linspace', width=None, height=None, **args):
"""
Setup pipeline for generation.
Expand All @@ -445,8 +445,11 @@ def setup(self, fimage, image=None, strength=0.75,
self._input_image = Image.open(fimage).convert("RGB") if image is None else image
self._input_image = self.scale_image(self._input_image, scale)
self._original_size = self._input_image.size
logging.debug("origin image size {self._original_size}")
self._input_image = util.pad_image_to_multiple_of_8(self._input_image)
self.pipe_params.update({
"width": self._input_image.width if width is None else width,
"height": self._input_image.height if height is None else height,
"strength": strength,
"guidance_scale": guidance_scale
})
Expand Down Expand Up @@ -499,6 +502,7 @@ def gen(self, inputs: dict):
kwargs.update({"image": self._input_image})
self.try_set_scheduler(kwargs)
image = self.pipe(**kwargs).images[0]
logging.debug(f'generated image {image}')
result = image.crop((0, 0, self._original_size[0], self._original_size[1]))
return result

Expand Down Expand Up @@ -866,8 +870,8 @@ def setup(self, fimage, width=None, height=None,
if self.model_type == ModelType.FLUX and hasattr(cscales, '__len__'):
cscales = cscales[0] # multiple controlnets are not yet supported
self.pipe_params.update({
"width": image.size[0] if width is None else width,
"height": image.size[1] if height is None else height,
"width": image.width if width is None else width,
"height": image.height if height is None else height,
"controlnet_conditioning_scale": cscales,
"guess_mode": guess_mode,
"strength": strength,
Expand Down

0 comments on commit 20d892f

Please sign in to comment.