This commit is contained in:
lllyasviel
2024-01-30 14:40:26 -08:00
parent b4dafc07b4
commit 2336ec7da8
2 changed files with 21 additions and 5 deletions

View File

@@ -1,4 +1,6 @@
import cv2
import torch
import numpy as np
from modules_forge.supported_preprocessor import Preprocessor, PreprocessorParameter
from modules_forge.shared import add_supported_preprocessor
@@ -50,6 +52,20 @@ class PreprocessorInpaintOnly(PreprocessorInpaint):
return
def process_after_every_sampling(self, process, params, *args, **kwargs):
a1111_batch_result = args[0]
new_results = []
for img in a1111_batch_result.images:
sigma = 7
mask = self.mask[0, 0].detach().cpu().numpy().astype(np.float32)
mask = cv2.dilate(mask, np.ones((sigma, sigma), dtype=np.uint8))
mask = cv2.blur(mask, (sigma, sigma))[None]
mask = torch.from_numpy(np.ascontiguousarray(mask).copy()).to(img).clip(0, 1)
raw = self.image[0].to(img).clip(0, 1)
img = img.clip(0, 1)
new_results.append(raw * (1.0 - mask) + img * mask)
a1111_batch_result.images = new_results
return

View File

@@ -529,8 +529,8 @@ class ControlNetForForgeOfficial(scripts.Script):
params.model.positive_advanced_weighting = soft_weighting.copy()
params.model.negative_advanced_weighting = soft_weighting.copy()
params.preprocessor.process_before_every_sampling(process=p, cond=cond, **kwargs)
params.model.process_before_every_sampling(process=p, cond=cond, **kwargs)
params.preprocessor.process_before_every_sampling(p, cond, *args, **kwargs)
params.model.process_before_every_sampling(p, cond, *args, **kwargs)
logger.info(f"ControlNet Method {params.preprocessor.name} patched.")
return
@@ -542,8 +542,8 @@ class ControlNetForForgeOfficial(scripts.Script):
params: ControlNetCachedParameters,
*args, **kwargs):
params.preprocessor.process_after_every_sampling(process=p, params=params, **kwargs)
params.model.process_after_every_sampling(process=p, params=params, **kwargs)
params.preprocessor.process_after_every_sampling(p, params, *args, **kwargs)
params.model.process_after_every_sampling(p, params, *args, **kwargs)
return
def process(self, p, *args, **kwargs):
@@ -560,7 +560,7 @@ class ControlNetForForgeOfficial(scripts.Script):
self.process_unit_before_every_sampling(p, unit, self.current_params[i], *args, **kwargs)
return
def postprocess_batch(self, p, *args, **kwargs):
def postprocess_batch_list(self, p, *args, **kwargs):
for i, unit in enumerate(self.get_enabled_units(p)):
self.process_unit_after_every_sampling(p, unit, self.current_params[i], *args, **kwargs)
self.current_params = {}