Skip to content
Closed
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: 25 additions & 2 deletions examples/community/stable_diffusion_controlnet_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ def torch_dfs(model: torch.nn.Module):


class StableDiffusionControlNetReferencePipeline(StableDiffusionControlNetPipeline):
def _default_height_width(self, height, width, image):
# NOTE: It is possible that a list of images have different
# dimensions for each image, so just checking the first image
# is not _exactly_ correct, but it is simple.
while isinstance(image, list):
image = image[0]

if height is None:
if isinstance(image, PIL.Image.Image):
height = image.height
elif isinstance(image, torch.Tensor):
height = image.shape[2]

height = (height // 8) * 8 # round down to nearest multiple of 8

if width is None:
if isinstance(image, PIL.Image.Image):
width = image.width
elif isinstance(image, torch.Tensor):
width = image.shape[3]

width = (width // 8) * 8 # round down to nearest multiple of 8

return height, width

def prepare_ref_latents(self, refimage, batch_size, dtype, device, generator, do_classifier_free_guidance):
refimage = refimage.to(device=device, dtype=dtype)

Expand Down Expand Up @@ -230,8 +255,6 @@ def __call__(
self.check_inputs(
prompt,
image,
height,
width,
callback_steps,
negative_prompt,
prompt_embeds,
Expand Down