Skip to content

Commit

Permalink
img2img: use multiple Generators to make it more random
Browse files Browse the repository at this point in the history
  • Loading branch information
bghira committed Jul 6, 2023
1 parent 42ecdd7 commit 2795c5c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions discord_tron_client/classes/image_manipulation/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _run_pipeline(
if use_latent_result:
image_return_type = "latent"
if not promptless_variation and image is None:
# Use the Compel library's prompt weights as input instead of LPW pipelines.
# text2img workflow
if "ptx0/s1" in user_config.get("model", ""):
preprocessed_images = pipe(
prompt=positive_prompt,
Expand Down Expand Up @@ -259,17 +259,21 @@ def _run_pipeline(
)
new_image = self._controlnet_all_images(preprocessed_images=preprocessed_images, user_config=user_config, generator=generator)
elif not upscaler and not promptless_variation and image is not None:
# Img2Img workflow
# Create {batch_size} torch.Generator objects in a list:
torch_generators = [torch.Generator() for _ in range(batch_size)]
if "ptx0/s" in user_config.get("model", ""):
alt_weight_algorithm = False
if not alt_weight_algorithm:
new_image = pipe(
prompt=positive_prompt,
negative_prompt=negative_prompt,
num_images_per_prompt=batch_size,
image=image,
strength=user_config["strength"],
num_inference_steps=int(float(steps)),
guidance_scale=guidance_scale,
generator=generator,
generator=torch_generators,
).images
else:
new_image = pipe(
Expand All @@ -281,7 +285,7 @@ def _run_pipeline(
negative_prompt_embeds=negative_embed,
guidance_scale=guidance_scale,
guidance_rescale=user_config.get('guidance_rescale', 0.3),
generator=generator,
generator=torch_generators,
).images
elif promptless_variation:
new_image = self._controlnet_pipeline(image=image, user_config=user_config, pipe=pipe, generator=generator, prompt=positive_prompt, negative_prompt=negative_prompt)
Expand Down Expand Up @@ -451,10 +455,13 @@ def _refiner_pipeline(self, images: Image, user_config: dict, prompt: str = None
if prompt is None:
prompt = user_config["tile_positive"]
negative_prompt = user_config["tile_negative"]
generator = self._get_generator(user_config=user_config)
new_images = []
import random
for image in images:
# Get a random int:
seed = random.randint(0, 2**32)
new_images.append(pipe(
generator = torch.Generator().seed(int(seed))
prompt=prompt,
negative_prompt=negative_prompt,
image=image,
Expand Down

0 comments on commit 2795c5c

Please sign in to comment.