From ca45ff1ae6fdd5c2dcd754fde95dd29f49bd414b Mon Sep 17 00:00:00 2001 From: ljleb Date: Mon, 24 Jul 2023 13:52:24 -0400 Subject: add postprocess_batch_list callback --- modules/processing.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index a74a5302..c16404f4 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -717,7 +717,25 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: p.all_subseeds = [int(subseed) + x for x in range(len(p.all_prompts))] def infotext(iteration=0, position_in_batch=0, use_main_prompt=False): - return create_infotext(p, p.all_prompts, p.all_seeds, p.all_subseeds, comments, iteration, position_in_batch, use_main_prompt) + all_prompts = p.all_prompts[:] + all_seeds = p.all_seeds[:] + all_subseeds = p.all_subseeds[:] + + # apply changes to generation data + all_prompts[n * p.batch_size:(n + 1) * p.batch_size] = p.prompts + all_seeds[n * p.batch_size:(n + 1) * p.batch_size] = p.seeds + all_subseeds[n * p.batch_size:(n + 1) * p.batch_size] = p.subseeds + + # update p.all_negative_prompts in case extensions changed the size of the batch + # create_infotext below uses it + old_negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] + p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] = p.negative_prompts + + try: + return create_infotext(p, all_prompts, all_seeds, all_subseeds, comments, iteration, position_in_batch, use_main_prompt) + finally: + # restore p.all_negative_prompts in case extensions changed the size of the batch + p.all_negative_prompts[n * p.batch_size:n * p.batch_size + len(p.negative_prompts)] = old_negative_prompts if os.path.exists(cmd_opts.embeddings_dir) and not p.do_not_reload_embeddings: model_hijack.embedding_db.load_textual_inversion_embeddings() @@ -806,6 +824,10 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if p.scripts is not None: p.scripts.postprocess_batch(p, x_samples_ddim, batch_number=n) + postprocess_batch_list_args = scripts.PostprocessBatchListArgs(list(x_samples_ddim)) + p.scripts.postprocess_batch_list(p, postprocess_batch_list_args, batch_number=n) + x_samples_ddim = postprocess_batch_list_args.images + for i, x_sample in enumerate(x_samples_ddim): p.batch_index = i -- cgit v1.2.1 From 6b68b590321fcac2ad6d71c5aee1ac02687328d7 Mon Sep 17 00:00:00 2001 From: ljleb Date: Mon, 24 Jul 2023 15:38:52 -0400 Subject: use local vars --- modules/processing.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index c16404f4..7043477f 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -722,20 +722,20 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: all_subseeds = p.all_subseeds[:] # apply changes to generation data - all_prompts[n * p.batch_size:(n + 1) * p.batch_size] = p.prompts - all_seeds[n * p.batch_size:(n + 1) * p.batch_size] = p.seeds - all_subseeds[n * p.batch_size:(n + 1) * p.batch_size] = p.subseeds + all_prompts[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.prompts + all_seeds[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.seeds + all_subseeds[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.subseeds # update p.all_negative_prompts in case extensions changed the size of the batch # create_infotext below uses it - old_negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] - p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] = p.negative_prompts + old_negative_prompts = p.all_negative_prompts[iteration * p.batch_size:(iteration + 1) * p.batch_size] + p.all_negative_prompts[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.negative_prompts try: return create_infotext(p, all_prompts, all_seeds, all_subseeds, comments, iteration, position_in_batch, use_main_prompt) finally: # restore p.all_negative_prompts in case extensions changed the size of the batch - p.all_negative_prompts[n * p.batch_size:n * p.batch_size + len(p.negative_prompts)] = old_negative_prompts + p.all_negative_prompts[iteration * p.batch_size:iteration * p.batch_size + len(p.negative_prompts)] = old_negative_prompts if os.path.exists(cmd_opts.embeddings_dir) and not p.do_not_reload_embeddings: model_hijack.embedding_db.load_textual_inversion_embeddings() -- cgit v1.2.1 From 5b06607476d1ef2c9d16fe8b21c786b2ca13b95c Mon Sep 17 00:00:00 2001 From: ljleb Date: Mon, 24 Jul 2023 15:43:06 -0400 Subject: simplify --- modules/processing.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 7043477f..6dc178e1 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -718,24 +718,26 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: def infotext(iteration=0, position_in_batch=0, use_main_prompt=False): all_prompts = p.all_prompts[:] + all_negative_prompts = p.all_negative_prompts[:] all_seeds = p.all_seeds[:] all_subseeds = p.all_subseeds[:] # apply changes to generation data all_prompts[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.prompts + all_negative_prompts[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.negative_prompts all_seeds[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.seeds all_subseeds[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.subseeds # update p.all_negative_prompts in case extensions changed the size of the batch # create_infotext below uses it - old_negative_prompts = p.all_negative_prompts[iteration * p.batch_size:(iteration + 1) * p.batch_size] - p.all_negative_prompts[iteration * p.batch_size:(iteration + 1) * p.batch_size] = p.negative_prompts + old_negative_prompts = p.all_negative_prompts + p.all_negative_prompts = all_negative_prompts try: return create_infotext(p, all_prompts, all_seeds, all_subseeds, comments, iteration, position_in_batch, use_main_prompt) finally: # restore p.all_negative_prompts in case extensions changed the size of the batch - p.all_negative_prompts[iteration * p.batch_size:iteration * p.batch_size + len(p.negative_prompts)] = old_negative_prompts + p.all_negative_prompts = old_negative_prompts if os.path.exists(cmd_opts.embeddings_dir) and not p.do_not_reload_embeddings: model_hijack.embedding_db.load_textual_inversion_embeddings() -- cgit v1.2.1