This commit is contained in:
lllyasviel
2024-01-30 13:36:38 -08:00
parent 4b670d2e65
commit ce07ae6895
4 changed files with 9 additions and 17 deletions

View File

@@ -17,9 +17,6 @@ class PreprocessorInpaintOnly(PreprocessorInpaint):
super().__init__()
self.name = 'inpaint_only'
def __call__(self, input_image, resolution, slider_1=None, slider_2=None, slider_3=None, **kwargs):
return input_image
def process_before_every_sampling(self, process, cond, *args, **kwargs):
return
@@ -32,9 +29,6 @@ class PreprocessorInpaintLama(PreprocessorInpaintOnly):
super().__init__()
self.name = 'inpaint_only+lama'
def __call__(self, input_image, resolution, slider_1=None, slider_2=None, slider_3=None, **kwargs):
return input_image
add_supported_preprocessor(PreprocessorInpaint())

View File

@@ -935,9 +935,9 @@ class ControlNetUiGroup(object):
else None,
)
is_hwc, is_png = judge_image_type(result)
is_image = judge_image_type(result)
if not is_hwc:
if not is_image:
result = img
result = external_code.visualize_inpaint_mask(result)

View File

@@ -411,6 +411,4 @@ def crop_and_resize_image(detected_map, resize_mode, h, w):
def judge_image_type(img):
is_image_hw3or4 = isinstance(img, np.ndarray) and img.ndim == 3 and int(img.shape[2]) in [3, 4]
is_png = is_image_hw3or4 and int(img.shape[2]) == 4
return is_image_hw3or4, is_png
return isinstance(img, np.ndarray) and img.ndim == 3 and int(img.shape[2]) in [3, 4]

View File

@@ -439,7 +439,7 @@ class ControlNetForForgeOfficial(scripts.Script):
slider_2=unit.threshold_b,
)
preprocessor_output_is_image, need_inpaint_fix = judge_image_type(preprocessor_output)
preprocessor_output_is_image = judge_image_type(preprocessor_output)
if preprocessor_output_is_image:
params.control_cond = crop_and_resize_image(preprocessor_output, resize_mode, h, w)
@@ -452,11 +452,6 @@ class ControlNetForForgeOfficial(scripts.Script):
params.control_cond_for_hr_fix = numpy_to_pytorch(params.control_cond_for_hr_fix).movedim(-1, 1)
else:
params.control_cond_for_hr_fix = params.control_cond
if need_inpaint_fix:
fixer = lambda x: x[:, :3] * (1.0 - x[:, 3:]) - x[:, 3:]
params.control_cond = fixer(params.control_cond)
params.control_cond_for_hr_fix = fixer(params.control_cond_for_hr_fix)
else:
params.control_cond = preprocessor_output
params.control_cond_for_hr_fix = preprocessor_output
@@ -494,6 +489,11 @@ class ControlNetForForgeOfficial(scripts.Script):
kwargs.update(dict(unit=unit, params=params))
# CN inpaint fix
if cond.ndim == 4 and cond.shape[1] == 4:
kwargs['cond_before_inpaint_fix'] = cond.clone()
cond = cond[:, :3] * (1.0 - cond[:, 3:]) - cond[:, 3:]
params.model.strength = float(unit.weight)
params.model.start_percent = float(unit.guidance_start)
params.model.end_percent = float(unit.guidance_end)