From ed8b8b3b8c4f5bea89a2dc32fb48c83a123a11cd Mon Sep 17 00:00:00 2001 From: RnDMonkey Date: Fri, 23 Sep 2022 22:09:59 -0700 Subject: Fix to XY_Grid script console progress bar and other progress bar improvements (#890) Fix to XY_Grid script console progress bar and other progress bar improvements #890 --- modules/processing.py | 2 +- modules/shared.py | 7 +++++++ scripts/xy_grid.py | 32 ++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/modules/processing.py b/modules/processing.py index 0246e094..a899566d 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -338,7 +338,7 @@ def process_images(p: StableDiffusionProcessing) -> Processed: comments[comment] = 1 if p.n_iter > 1: - shared.state.job = f"Batch {n+1} out of {p.n_iter}" + shared.state.job = f"Image {n+1} out of {p.n_iter}; Batch {(shared.state.job_no // p.n_iter) + 1} of {shared.state.job_count // p.n_iter}" samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength) if state.interrupted: diff --git a/modules/shared.py b/modules/shared.py index 667c3441..7bad7a6d 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -307,6 +307,13 @@ class TotalTQDM: self.reset() self._tqdm.update() + def updateTotal(self, new_total): + if not opts.multiple_tqdm: + return + if self._tqdm is None: + self.reset() + self._tqdm.total=new_total + def clear(self): if self._tqdm is not None: self._tqdm.close() diff --git a/scripts/xy_grid.py b/scripts/xy_grid.py index 6a157722..cb1312ae 100644 --- a/scripts/xy_grid.py +++ b/scripts/xy_grid.py @@ -102,7 +102,7 @@ def draw_xy_grid(p, xs, ys, x_labels, y_labels, cell, draw_legend): for iy, y in enumerate(ys): for ix, x in enumerate(xs): - state.job = f"{ix + iy * len(xs) + 1} out of {len(xs) * len(ys)}" + state.job = f"Image {ix + iy * len(xs) + 1} out of {state.job_count}" processed = cell(x, y) if first_pocessed is None: @@ -141,10 +141,11 @@ class Script(scripts.Script): y_values = gr.Textbox(label="Y values", visible=False, lines=1) draw_legend = gr.Checkbox(label='Draw legend', value=True) - - return [x_type, x_values, y_type, y_values, draw_legend] + fixed_seeds = gr.Checkbox(label='Resolve random seeds before plotting (only applies when plotting "-1" seed values for X or Y axis)', value=False) - def run(self, p, x_type, x_values, y_type, y_values, draw_legend): + return [x_type, x_values, y_type, y_values, draw_legend, fixed_seeds] + + def run(self, p, x_type, x_values, y_type, y_values, draw_legend, fixed_seeds): modules.processing.fix_seed(p) p.batch_size = 1 @@ -207,6 +208,29 @@ class Script(scripts.Script): y_opt = axis_options[y_type] ys = process_axis(y_opt, y_values) + def fix_axis_seeds(axis_opt, axis_list): + if axis_opt.label == 'Seed': + return [int(random.randrange(4294967294)) if val is None or val == '' or val == -1 else val for val in axis_list] + else: + return axis_list + + if fixed_seeds == True: + xs = fix_axis_seeds(x_opt, xs) + ys = fix_axis_seeds(y_opt, ys) + + if x_opt.label == 'Steps': + total_steps = sum(xs) * len(ys) + elif y_opt.label == 'Steps': + total_steps = sum(ys) * len(xs) + else: + total_steps = p.steps * len(xs) * len(ys) + + if p.n_iter > 1: + print(f"Number of seeds/images per prompt is {p.n_iter}.") + + print(f"X/Y plot will create {len(xs) * len(ys) * p.n_iter} images on a {len(xs)} x {len(ys)} grid. (Total steps to process: {total_steps * p.n_iter})") + shared.total_tqdm.updateTotal(total_steps * p.n_iter) + def cell(x, y): pc = copy(p) x_opt.apply(pc, x, xs) -- cgit v1.2.1