aboutsummaryrefslogtreecommitdiff
path: root/modules/img2img.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/img2img.py')
-rw-r--r--modules/img2img.py53
1 files changed, 9 insertions, 44 deletions
diff --git a/modules/img2img.py b/modules/img2img.py
index 70c99e33..2dcabc6b 100644
--- a/modules/img2img.py
+++ b/modules/img2img.py
@@ -11,10 +11,9 @@ from modules.ui import plaintext_to_html
import modules.images as images
import modules.scripts
-def img2img(prompt: str, negative_prompt: str, prompt_style: str, init_img, init_img_with_mask, init_mask, mask_mode, steps: int, sampler_index: int, mask_blur: int, inpainting_fill: int, restore_faces: bool, tiling: bool, mode: int, n_iter: int, batch_size: int, cfg_scale: float, denoising_strength: float, denoising_strength_change_factor: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, height: int, width: int, resize_mode: int, upscaler_index: str, upscale_overlap: int, inpaint_full_res: bool, inpainting_mask_invert: int, *args):
+def img2img(prompt: str, negative_prompt: str, prompt_style: str, prompt_style2: str, init_img, init_img_with_mask, init_mask, mask_mode, steps: int, sampler_index: int, mask_blur: int, inpainting_fill: int, restore_faces: bool, tiling: bool, mode: int, n_iter: int, batch_size: int, cfg_scale: float, denoising_strength: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, height: int, width: int, resize_mode: int, upscaler_index: str, upscale_overlap: int, inpaint_full_res: bool, inpainting_mask_invert: int, *args):
is_inpaint = mode == 1
- is_loopback = mode == 2
- is_upscale = mode == 3
+ is_upscale = mode == 2
if is_inpaint:
if mask_mode == 0:
@@ -38,7 +37,7 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: str, init_img, init
outpath_grids=opts.outdir_grids or opts.outdir_img2img_grids,
prompt=prompt,
negative_prompt=negative_prompt,
- prompt_style=prompt_style,
+ styles=[prompt_style, prompt_style2],
seed=seed,
subseed=subseed,
subseed_strength=subseed_strength,
@@ -61,46 +60,10 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: str, init_img, init
denoising_strength=denoising_strength,
inpaint_full_res=inpaint_full_res,
inpainting_mask_invert=inpainting_mask_invert,
- extra_generation_params={
- "Denoising strength change factor": (denoising_strength_change_factor if is_loopback else None)
- }
)
print(f"\nimg2img: {prompt}", file=shared.progress_print_out)
- if is_loopback:
- output_images, info = None, None
- history = []
- initial_seed = None
- initial_info = None
-
- state.job_count = n_iter
-
- for i in range(n_iter):
- p.n_iter = 1
- p.batch_size = 1
- p.do_not_save_grid = True
-
- state.job = f"Batch {i + 1} out of {n_iter}"
- processed = process_images(p)
-
- if initial_seed is None:
- initial_seed = processed.seed
- initial_info = processed.info
-
- init_img = processed.images[0]
-
- p.init_images = [init_img]
- p.seed = processed.seed + 1
- p.denoising_strength = min(max(p.denoising_strength * denoising_strength_change_factor, 0.1), 1)
- history.append(processed.images[0])
-
- grid = images.image_grid(history, batch_size, rows=1)
-
- images.save_image(grid, p.outpath_grids, "grid", initial_seed, prompt, opts.grid_format, info=info, short_filename=not opts.grid_extended_filename, p=p)
-
- processed = Processed(p, history, initial_seed, initial_info)
-
- elif is_upscale:
+ if is_upscale:
initial_info = None
processing.fix_seed(p)
@@ -113,6 +76,7 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: str, init_img, init
grid = images.split_grid(img, tile_w=width, tile_h=height, overlap=upscale_overlap)
+ batch_size = p.batch_size
upscale_count = p.n_iter
p.n_iter = 1
p.do_not_save_grid = True
@@ -124,7 +88,7 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: str, init_img, init
for tiledata in row:
work.append(tiledata[2])
- batch_count = math.ceil(len(work) / p.batch_size)
+ batch_count = math.ceil(len(work) / batch_size)
state.job_count = batch_count * upscale_count
print(f"SD upscaling will process a total of {len(work)} images tiled as {len(grid.tiles[0][2])}x{len(grid.tiles)} per upscale in a total of {state.job_count} batches.")
@@ -136,9 +100,10 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: str, init_img, init
work_results = []
for i in range(batch_count):
- p.init_images = work[i*p.batch_size:(i+1)*p.batch_size]
+ p.batch_size = batch_size
+ p.init_images = work[i*batch_size:(i+1)*batch_size]
- state.job = f"Batch {i + 1} out of {state.job_count}"
+ state.job = f"Batch {i + 1 + n * batch_count} out of {state.job_count}"
processed = process_images(p)
if initial_info is None: