add batch count to sd upscale #169
fix writing empty prompt pictures to rroot directory instead of 'empty' suppress 'Denoising strength change factor' text inimage info unless using loopback mode
This commit is contained in:
parent
955f644ce1
commit
ef0cdb8a42
3 changed files with 32 additions and 27 deletions
|
@ -259,7 +259,7 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
|
||||||
|
|
||||||
if opts.save_to_dirs and not no_prompt:
|
if opts.save_to_dirs and not no_prompt:
|
||||||
words = re_nonletters.split(prompt or "")
|
words = re_nonletters.split(prompt or "")
|
||||||
if len(words) == 0:
|
if len(words[0]) == 0:
|
||||||
words = ["empty"]
|
words = ["empty"]
|
||||||
|
|
||||||
dirname = " ".join(words[0:opts.save_to_dirs_prompt_len]).strip()
|
dirname = " ".join(words[0:opts.save_to_dirs_prompt_len]).strip()
|
||||||
|
|
|
@ -63,7 +63,7 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: int, init_img, init
|
||||||
inpainting_mask_invert=inpainting_mask_invert,
|
inpainting_mask_invert=inpainting_mask_invert,
|
||||||
extra_generation_params={
|
extra_generation_params={
|
||||||
"Denoising strength": denoising_strength,
|
"Denoising strength": denoising_strength,
|
||||||
"Denoising strength change factor": denoising_strength_change_factor
|
"Denoising strength change factor": (denoising_strength_change_factor if is_loopback else None)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
print(f"\nimg2img: {prompt}", file=shared.progress_print_out)
|
print(f"\nimg2img: {prompt}", file=shared.progress_print_out)
|
||||||
|
@ -85,7 +85,6 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: int, init_img, init
|
||||||
|
|
||||||
|
|
||||||
for i in range(n_iter):
|
for i in range(n_iter):
|
||||||
|
|
||||||
if do_color_correction and i == 0:
|
if do_color_correction and i == 0:
|
||||||
correction_target = cv2.cvtColor(np.asarray(init_img.copy()), cv2.COLOR_RGB2LAB)
|
correction_target = cv2.cvtColor(np.asarray(init_img.copy()), cv2.COLOR_RGB2LAB)
|
||||||
|
|
||||||
|
@ -124,9 +123,11 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: int, init_img, init
|
||||||
processed = Processed(p, history, initial_seed, initial_info)
|
processed = Processed(p, history, initial_seed, initial_info)
|
||||||
|
|
||||||
elif is_upscale:
|
elif is_upscale:
|
||||||
initial_seed = None
|
|
||||||
initial_info = None
|
initial_info = None
|
||||||
|
|
||||||
|
processing.fix_seed(p)
|
||||||
|
seed = p.seed
|
||||||
|
|
||||||
upscaler = shared.sd_upscalers[upscaler_index]
|
upscaler = shared.sd_upscalers[upscaler_index]
|
||||||
img = upscaler.upscale(init_img, init_img.width * 2, init_img.height * 2)
|
img = upscaler.upscale(init_img, init_img.width * 2, init_img.height * 2)
|
||||||
|
|
||||||
|
@ -134,47 +135,53 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: int, init_img, init
|
||||||
|
|
||||||
grid = images.split_grid(img, tile_w=width, tile_h=height, overlap=upscale_overlap)
|
grid = images.split_grid(img, tile_w=width, tile_h=height, overlap=upscale_overlap)
|
||||||
|
|
||||||
|
upscale_count = p.n_iter
|
||||||
p.n_iter = 1
|
p.n_iter = 1
|
||||||
p.do_not_save_grid = True
|
p.do_not_save_grid = True
|
||||||
p.do_not_save_samples = True
|
p.do_not_save_samples = True
|
||||||
|
|
||||||
work = []
|
work = []
|
||||||
work_results = []
|
|
||||||
|
|
||||||
for y, h, row in grid.tiles:
|
for y, h, row in grid.tiles:
|
||||||
for tiledata in row:
|
for tiledata in row:
|
||||||
work.append(tiledata[2])
|
work.append(tiledata[2])
|
||||||
|
|
||||||
batch_count = math.ceil(len(work) / p.batch_size)
|
batch_count = math.ceil(len(work) / p.batch_size)
|
||||||
print(f"SD upscaling will process a total of {len(work)} images tiled as {len(grid.tiles[0][2])}x{len(grid.tiles)} in a total of {batch_count} batches.")
|
state.job_count = batch_count * upscale_count
|
||||||
|
|
||||||
state.job_count = batch_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.")
|
||||||
|
|
||||||
for i in range(batch_count):
|
result_images = []
|
||||||
p.init_images = work[i*p.batch_size:(i+1)*p.batch_size]
|
for n in range(upscale_count):
|
||||||
|
start_seed = seed + n
|
||||||
|
p.seed = start_seed
|
||||||
|
|
||||||
state.job = f"Batch {i + 1} out of {batch_count}"
|
work_results = []
|
||||||
processed = process_images(p)
|
for i in range(batch_count):
|
||||||
|
p.init_images = work[i*p.batch_size:(i+1)*p.batch_size]
|
||||||
|
|
||||||
if initial_seed is None:
|
state.job = f"Batch {i + 1} out of {state.job_count}"
|
||||||
initial_seed = processed.seed
|
processed = process_images(p)
|
||||||
initial_info = processed.info
|
|
||||||
|
|
||||||
p.seed = processed.seed + 1
|
if initial_info is None:
|
||||||
work_results += processed.images
|
initial_info = processed.info
|
||||||
|
|
||||||
image_index = 0
|
p.seed = processed.seed + 1
|
||||||
for y, h, row in grid.tiles:
|
work_results += processed.images
|
||||||
for tiledata in row:
|
|
||||||
tiledata[2] = work_results[image_index] if image_index < len(work_results) else Image.new("RGB", (p.width, p.height))
|
|
||||||
image_index += 1
|
|
||||||
|
|
||||||
combined_image = images.combine_grid(grid)
|
image_index = 0
|
||||||
|
for y, h, row in grid.tiles:
|
||||||
|
for tiledata in row:
|
||||||
|
tiledata[2] = work_results[image_index] if image_index < len(work_results) else Image.new("RGB", (p.width, p.height))
|
||||||
|
image_index += 1
|
||||||
|
|
||||||
if opts.samples_save:
|
combined_image = images.combine_grid(grid)
|
||||||
images.save_image(combined_image, p.outpath_samples, "", initial_seed, prompt, opts.grid_format, info=initial_info)
|
result_images.append(combined_image)
|
||||||
|
|
||||||
processed = Processed(p, [combined_image], initial_seed, initial_info)
|
if opts.samples_save:
|
||||||
|
images.save_image(combined_image, p.outpath_samples, "", start_seed, prompt, opts.grid_format, info=initial_info)
|
||||||
|
|
||||||
|
processed = Processed(p, result_images, seed, initial_info)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
|
|
@ -455,7 +455,6 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
|
||||||
mask_mode: gr_show(is_inpaint),
|
mask_mode: gr_show(is_inpaint),
|
||||||
mask_blur: gr_show(is_inpaint),
|
mask_blur: gr_show(is_inpaint),
|
||||||
inpainting_fill: gr_show(is_inpaint),
|
inpainting_fill: gr_show(is_inpaint),
|
||||||
batch_count: gr_show(not is_upscale),
|
|
||||||
batch_size: gr_show(not is_loopback),
|
batch_size: gr_show(not is_loopback),
|
||||||
sd_upscale_upscaler_name: gr_show(is_upscale),
|
sd_upscale_upscaler_name: gr_show(is_upscale),
|
||||||
sd_upscale_overlap: gr_show(is_upscale),
|
sd_upscale_overlap: gr_show(is_upscale),
|
||||||
|
@ -475,7 +474,6 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
|
||||||
mask_mode,
|
mask_mode,
|
||||||
mask_blur,
|
mask_blur,
|
||||||
inpainting_fill,
|
inpainting_fill,
|
||||||
batch_count,
|
|
||||||
batch_size,
|
batch_size,
|
||||||
sd_upscale_upscaler_name,
|
sd_upscale_upscaler_name,
|
||||||
sd_upscale_overlap,
|
sd_upscale_overlap,
|
||||||
|
|
Loading…
Reference in a new issue