From da12d2edc532b2e1ea835ea7e1ea473fd88078e0 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Mon, 1 Jul 2024 22:27:12 +0900 Subject: [PATCH 1/3] fix disable during hires fix --- scripts/detail_daemon.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/detail_daemon.py b/scripts/detail_daemon.py index b269317..ce6ee4d 100644 --- a/scripts/detail_daemon.py +++ b/scripts/detail_daemon.py @@ -123,7 +123,6 @@ class Script(scripts.Script): actual_steps = (p.steps * 2 - 1) if p.sampler_name in ['DPM++ SDE', 'DPM++ 2S a', 'Heun', 'DPM2', 'DPM2 a', 'Restart'] else p.steps self.schedule = self.make_schedule(actual_steps, start, end, bias, amount, exponent, start_offset, end_offset, fade, smooth) self.mode = mode - self.is_hires = False self.cfg_scale = p.cfg_scale on_cfg_denoiser(self.denoiser_callback) self.callback_added = True @@ -135,6 +134,9 @@ class Script(scripts.Script): delattr(self, 'callback_added') # tqdm.write('\033[90mINFO: Detail Daemon callback removed\033[0m') + def before_process_batch(self, p, *args, **kwargs): + self.is_hires = False + def postprocess(self, p, processed, *args): if hasattr(self, 'callback_added'): remove_callbacks_for_function(self.denoiser_callback) From 704253022fdf1760211b8931774d586dba27752c Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:06:27 +0900 Subject: [PATCH 2/3] formatting PEP 8: E203 whitespace before ':' PEP 8: E231 missing whitespace after ',' PEP 8: E305 expected 2 blank lines after class or function definition PEP 8: E701 multiple statements on one line (colon) --- scripts/detail_daemon.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/scripts/detail_daemon.py b/scripts/detail_daemon.py index ce6ee4d..d948985 100644 --- a/scripts/detail_daemon.py +++ b/scripts/detail_daemon.py @@ -114,8 +114,8 @@ class Script(scripts.Script): fade = getattr(p, "DD_fade", fade) smooth = getattr(p, "DD_smooth", smooth) - if enabled : - if p.sampler_name == "DPM adaptive" : + if enabled: + if p.sampler_name == "DPM adaptive": tqdm.write(f'\033[33mINFO:\033[0m Detail Daemon does not work with {p.sampler_name}') return # Restart can be handled better, later maybe @@ -150,15 +150,15 @@ class Script(scripts.Script): tqdm.write(f'\033[33mINFO:\033[0m Detail Daemon does not work during Hires Fix') def denoiser_callback(self, params): - if self.is_hires : + if self.is_hires: return idx = params.denoiser.step multiplier = 1 - self.schedule[idx] - if self.mode == "cond" : + if self.mode == "cond": params.sigma[0] *= 1 - self.schedule[idx] * .1 - elif self.mode == "uncond" : + elif self.mode == "uncond": params.sigma[1] *= 1 - self.schedule[idx] * -.1 - else : + else: params.sigma *= 1 - self.schedule[idx] * .1 * self.cfg_scale def make_schedule(self, steps, start, end, bias, amount, exponent, start_offset, end_offset, fade, smooth): @@ -198,7 +198,8 @@ class Script(scripts.Script): values = self.make_schedule(steps, start, end, bias, amount, exponent, start_offset, end_offset, fade, smooth) mean = sum(values)/steps peak = np.clip(max(abs(values)), -1, 1) - if start > end : start = end + if start > end: + start = end mid = start + bias * (end - start) opacity = .1 + (1 - fade) * 0.7 plot_color = (0.5, 0.5, 0.5, opacity) if not enabled else ((1 - peak)**2, 1, 0, opacity) if mean >= 0 else (1, (1 - peak)**2, 0, opacity) @@ -212,23 +213,24 @@ class Script(scripts.Script): "ytick.labelcolor": plot_color, "ytick.color": plot_color, }) - fig, ax = plt.subplots(figsize=(2.15, 2.00),layout="constrained") + fig, ax = plt.subplots(figsize=(2.15, 2.00), layout="constrained") ax.plot(range(steps), values, color=plot_color) ax.axhline(y=0, color=plot_color, linestyle='dotted') ax.axvline(x=mid * (steps - 1), color=plot_color, linestyle='dotted') ax.tick_params(right=False, color=plot_color) ax.set_xticks([i * (steps - 1) / 10 for i in range(10)][1:]) ax.set_xticklabels([]) - ax.set_ylim([-1,1]) - ax.set_xlim([0,steps-1]) + ax.set_ylim([-1, 1]) + ax.set_xlim([0, steps-1]) plt.close() self.last_vis = fig - return fig + return fig except: - if self.last_vis is not None : + if self.last_vis is not None: return self.last_vis return + def xyz_support(): for scriptDataTuple in scripts.scripts_data: if os.path.basename(scriptDataTuple.path) == 'xyz_grid.py': @@ -236,7 +238,7 @@ def xyz_support(): def confirm_mode(p, xs): for x in xs: - if x not in ['both','cond', 'uncond']: + if x not in ['both', 'cond', 'uncond']: raise RuntimeError(f'Invalid Detail Daemon Mode: {x}') mode = xy_grid.AxisOption( '[Detail Daemon] Mode', @@ -295,6 +297,8 @@ def xyz_support(): end_offset, fade, ]) + + try: xyz_support() except Exception as e: From f1a3c5ed8f2ccdc1a60672f214d12dc0a6a30179 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:06:43 +0900 Subject: [PATCH 3/3] PEP 8: E722 do not use bare 'except' --- scripts/detail_daemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/detail_daemon.py b/scripts/detail_daemon.py index d948985..480d68c 100644 --- a/scripts/detail_daemon.py +++ b/scripts/detail_daemon.py @@ -225,7 +225,7 @@ class Script(scripts.Script): plt.close() self.last_vis = fig return fig - except: + except Exception: if self.last_vis is not None: return self.last_vis return