Skip to content

Commit

Permalink
Add setting to disable CN in highres (#1832)
Browse files Browse the repository at this point in the history
  • Loading branch information
catboxanon authored Jul 26, 2023
1 parent ff7aad9 commit efda6dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions scripts/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,8 @@ def on_ui_settings():
1, "Model cache size (requires restart)", gr.Slider, {"minimum": 1, "maximum": 5, "step": 1}, section=section))
shared.opts.add_option("control_net_inpaint_blur_sigma", shared.OptionInfo(
7, "ControlNet inpainting Gaussian blur sigma", gr.Slider, {"minimum": 0, "maximum": 64, "step": 1}, section=section))
shared.opts.add_option("control_net_no_high_res_fix", shared.OptionInfo(
False, "Do not apply ControlNet during highres fix", gr.Checkbox, {"interactive": True}, section=section))
shared.opts.add_option("control_net_no_detectmap", shared.OptionInfo(
False, "Do not append detectmap to output", gr.Checkbox, {"interactive": True}, section=section))
shared.opts.add_option("control_net_detectmap_autosaving", shared.OptionInfo(
Expand Down
13 changes: 12 additions & 1 deletion scripts/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ def forward(self, x, timesteps=None, context=None, **kwargs):
param.used_hint_cond_latent = None
param.used_hint_inpaint_hijack = None

no_high_res_control = is_in_high_res_fix and shared.opts.data.get("control_net_no_high_res_fix", False)

# Convert control image to latent
for param in outer.control_params:
if param.used_hint_cond_latent is not None:
Expand All @@ -399,6 +401,9 @@ def forward(self, x, timesteps=None, context=None, **kwargs):

# handle prompt token control
for param in outer.control_params:
if no_high_res_control:
continue

if param.guidance_stopped:
continue

Expand All @@ -414,6 +419,9 @@ def forward(self, x, timesteps=None, context=None, **kwargs):

# handle ControlNet / T2I_Adapter
for param in outer.control_params:
if no_high_res_control:
continue

if param.guidance_stopped:
continue

Expand Down Expand Up @@ -524,6 +532,9 @@ def forward(self, x, timesteps=None, context=None, **kwargs):

# Handle attention and AdaIn control
for param in outer.control_params:
if no_high_res_control:
continue

if param.guidance_stopped:
continue

Expand Down Expand Up @@ -605,7 +616,7 @@ def forward(self, x, timesteps=None, context=None, **kwargs):
continue

k = int(param.preprocessor['threshold_a'])
if is_in_high_res_fix:
if is_in_high_res_fix and not no_high_res_control:
k *= 2

# Inpaint hijack
Expand Down

0 comments on commit efda6dd

Please sign in to comment.