add batch count to sd upscale

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:
AUTOMATIC 2022-09-10 11:37:06 +03:00
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:
words = re_nonletters.split(prompt or "")
if len(words) == 0:
if len(words[0]) == 0:
words = ["empty"]
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,
extra_generation_params={
"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)
@ -85,7 +85,6 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: int, init_img, init
for i in range(n_iter):
if do_color_correction and i == 0:
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)
elif is_upscale:
initial_seed = None
initial_info = None
processing.fix_seed(p)
seed = p.seed
upscaler = shared.sd_upscalers[upscaler_index]
img = upscaler.upscale(init_img, init_img.width * 2, init_img.height * 2)
@ -134,30 +135,35 @@ 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)
upscale_count = p.n_iter
p.n_iter = 1
p.do_not_save_grid = True
p.do_not_save_samples = True
work = []
work_results = []
for y, h, row in grid.tiles:
for tiledata in row:
work.append(tiledata[2])
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.")
result_images = []
for n in range(upscale_count):
start_seed = seed + n
p.seed = start_seed
work_results = []
for i in range(batch_count):
p.init_images = work[i*p.batch_size:(i+1)*p.batch_size]
state.job = f"Batch {i + 1} out of {batch_count}"
state.job = f"Batch {i + 1} out of {state.job_count}"
processed = process_images(p)
if initial_seed is None:
initial_seed = processed.seed
if initial_info is None:
initial_info = processed.info
p.seed = processed.seed + 1
@ -170,11 +176,12 @@ def img2img(prompt: str, negative_prompt: str, prompt_style: int, init_img, init
image_index += 1
combined_image = images.combine_grid(grid)
result_images.append(combined_image)
if opts.samples_save:
images.save_image(combined_image, p.outpath_samples, "", initial_seed, prompt, opts.grid_format, info=initial_info)
images.save_image(combined_image, p.outpath_samples, "", start_seed, prompt, opts.grid_format, info=initial_info)
processed = Processed(p, [combined_image], initial_seed, initial_info)
processed = Processed(p, result_images, seed, initial_info)
else:

@ -455,7 +455,6 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
mask_mode: gr_show(is_inpaint),
mask_blur: gr_show(is_inpaint),
inpainting_fill: gr_show(is_inpaint),
batch_count: gr_show(not is_upscale),
batch_size: gr_show(not is_loopback),
sd_upscale_upscaler_name: 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_blur,
inpainting_fill,
batch_count,
batch_size,
sd_upscale_upscaler_name,
sd_upscale_overlap,