mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
feat: extract attribute canny_high_threshold
This commit is contained in:
@@ -3,25 +3,25 @@ import numpy as np
|
|||||||
import modules.advanced_parameters as advanced_parameters
|
import modules.advanced_parameters as advanced_parameters
|
||||||
|
|
||||||
|
|
||||||
def centered_canny(x: np.ndarray, canny_low_threshold):
|
def centered_canny(x: np.ndarray, canny_low_threshold, canny_high_threshold):
|
||||||
assert isinstance(x, np.ndarray)
|
assert isinstance(x, np.ndarray)
|
||||||
assert x.ndim == 2 and x.dtype == np.uint8
|
assert x.ndim == 2 and x.dtype == np.uint8
|
||||||
|
|
||||||
y = cv2.Canny(x, int(canny_low_threshold), int(advanced_parameters.canny_high_threshold))
|
y = cv2.Canny(x, int(canny_low_threshold), int(canny_high_threshold))
|
||||||
y = y.astype(np.float32) / 255.0
|
y = y.astype(np.float32) / 255.0
|
||||||
return y
|
return y
|
||||||
|
|
||||||
|
|
||||||
def centered_canny_color(x: np.ndarray, canny_low_threshold):
|
def centered_canny_color(x: np.ndarray, canny_low_threshold, canny_high_threshold):
|
||||||
assert isinstance(x, np.ndarray)
|
assert isinstance(x, np.ndarray)
|
||||||
assert x.ndim == 3 and x.shape[2] == 3
|
assert x.ndim == 3 and x.shape[2] == 3
|
||||||
|
|
||||||
result = [centered_canny(x[..., i], canny_low_threshold) for i in range(3)]
|
result = [centered_canny(x[..., i], canny_low_threshold, canny_high_threshold) for i in range(3)]
|
||||||
result = np.stack(result, axis=2)
|
result = np.stack(result, axis=2)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def pyramid_canny_color(x: np.ndarray, canny_low_threshold):
|
def pyramid_canny_color(x: np.ndarray, canny_low_threshold, canny_high_threshold):
|
||||||
assert isinstance(x, np.ndarray)
|
assert isinstance(x, np.ndarray)
|
||||||
assert x.ndim == 3 and x.shape[2] == 3
|
assert x.ndim == 3 and x.shape[2] == 3
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ def pyramid_canny_color(x: np.ndarray, canny_low_threshold):
|
|||||||
for k in [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]:
|
for k in [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]:
|
||||||
Hs, Ws = int(H * k), int(W * k)
|
Hs, Ws = int(H * k), int(W * k)
|
||||||
small = cv2.resize(x, (Ws, Hs), interpolation=cv2.INTER_AREA)
|
small = cv2.resize(x, (Ws, Hs), interpolation=cv2.INTER_AREA)
|
||||||
edge = centered_canny_color(small, canny_low_threshold)
|
edge = centered_canny_color(small, canny_low_threshold, canny_high_threshold)
|
||||||
if acc_edge is None:
|
if acc_edge is None:
|
||||||
acc_edge = edge
|
acc_edge = edge
|
||||||
else:
|
else:
|
||||||
@@ -54,11 +54,11 @@ def norm255(x, low=4, high=96):
|
|||||||
return x * 255.0
|
return x * 255.0
|
||||||
|
|
||||||
|
|
||||||
def canny_pyramid(x, canny_low_threshold):
|
def canny_pyramid(x, canny_low_threshold, canny_high_threshold):
|
||||||
# For some reasons, SAI's Control-lora Canny seems to be trained on canny maps with non-standard resolutions.
|
# For some reasons, SAI's Control-lora Canny seems to be trained on canny maps with non-standard resolutions.
|
||||||
# Then we use pyramid to use all resolutions to avoid missing any structure in specific resolutions.
|
# Then we use pyramid to use all resolutions to avoid missing any structure in specific resolutions.
|
||||||
|
|
||||||
color_canny = pyramid_canny_color(x, canny_low_threshold)
|
color_canny = pyramid_canny_color(x, canny_low_threshold, canny_high_threshold)
|
||||||
result = np.sum(color_canny, axis=2)
|
result = np.sum(color_canny, axis=2)
|
||||||
|
|
||||||
return norm255(result, low=1, high=99).clip(0, 255).astype(np.uint8)
|
return norm255(result, low=1, high=99).clip(0, 255).astype(np.uint8)
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
controlnet_softness, canny_high_threshold, \
|
controlnet_softness, \
|
||||||
refiner_swap_method, \
|
refiner_swap_method, \
|
||||||
freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \
|
freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \
|
||||||
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \
|
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \
|
||||||
inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 16
|
inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 15
|
||||||
|
|
||||||
|
|
||||||
def set_all_advanced_parameters(*args):
|
def set_all_advanced_parameters(*args):
|
||||||
global controlnet_softness, canny_high_threshold, \
|
global controlnet_softness, \
|
||||||
refiner_swap_method, \
|
refiner_swap_method, \
|
||||||
freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \
|
freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \
|
||||||
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \
|
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \
|
||||||
inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate
|
inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate
|
||||||
|
|
||||||
controlnet_softness, canny_high_threshold, \
|
controlnet_softness, \
|
||||||
refiner_swap_method, \
|
refiner_swap_method, \
|
||||||
freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \
|
freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \
|
||||||
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \
|
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ def worker():
|
|||||||
debugging_cn_preprocessor = args.pop()
|
debugging_cn_preprocessor = args.pop()
|
||||||
skipping_cn_preprocessor = args.pop()
|
skipping_cn_preprocessor = args.pop()
|
||||||
canny_low_threshold = args.pop()
|
canny_low_threshold = args.pop()
|
||||||
|
canny_high_threshold = args.pop()
|
||||||
|
|
||||||
cn_tasks = {x: [] for x in flags.ip_list}
|
cn_tasks = {x: [] for x in flags.ip_list}
|
||||||
for _ in range(4):
|
for _ in range(4):
|
||||||
@@ -647,7 +648,7 @@ def worker():
|
|||||||
cn_img = resize_image(HWC3(cn_img), width=width, height=height)
|
cn_img = resize_image(HWC3(cn_img), width=width, height=height)
|
||||||
|
|
||||||
if not skipping_cn_preprocessor:
|
if not skipping_cn_preprocessor:
|
||||||
cn_img = preprocessors.canny_pyramid(cn_img, canny_low_threshold)
|
cn_img = preprocessors.canny_pyramid(cn_img, canny_low_threshold, canny_high_threshold)
|
||||||
|
|
||||||
cn_img = HWC3(cn_img)
|
cn_img = HWC3(cn_img)
|
||||||
task[0] = core.numpy_to_pytorch(cn_img)
|
task[0] = core.numpy_to_pytorch(cn_img)
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ with shared.gradio_root:
|
|||||||
freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)
|
freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)
|
||||||
freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2]
|
freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2]
|
||||||
|
|
||||||
adps = [controlnet_softness, canny_high_threshold, refiner_swap_method]
|
adps = [controlnet_softness, refiner_swap_method]
|
||||||
adps += freeu_ctrls
|
adps += freeu_ctrls
|
||||||
adps += inpaint_ctrls
|
adps += inpaint_ctrls
|
||||||
|
|
||||||
@@ -528,7 +528,7 @@ with shared.gradio_root:
|
|||||||
ctrls += [sampler_name, scheduler_name]
|
ctrls += [sampler_name, scheduler_name]
|
||||||
ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength]
|
ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength]
|
||||||
ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint]
|
ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint]
|
||||||
ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold]
|
ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold]
|
||||||
ctrls += ip_ctrls
|
ctrls += ip_ctrls
|
||||||
|
|
||||||
state_is_generating = gr.State(False)
|
state_is_generating = gr.State(False)
|
||||||
|
|||||||
Reference in New Issue
Block a user