mask batch, working, infotext broken

This commit is contained in:
continue revolution
2024-02-05 23:55:59 -06:00
parent d60eccb8ba
commit 264634624e
3 changed files with 9 additions and 5 deletions

View File

@@ -37,7 +37,9 @@ def serialize_unit(unit: external_code.ControlNetUnit) -> str:
"generated_image",
"mask_image",
"batch_input_gallery",
"batch_image_dir"
"batch_mask_gallery",
"batch_image_dir",
"batch_mask_dir",
)
log_value = {

View File

@@ -155,7 +155,7 @@ class ControlNetForForgeOfficial(scripts.Script):
mask_path = unit.batch_mask_gallery[idx]['name']
else:
mask_path = unit.batch_mask_gallery[0]['name']
mask = np.ascontiguousarray(cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE))
mask = np.ascontiguousarray(cv2.imread(mask_path)[:, :, ::-1]).copy()
if img is not None:
image_list.append([img, mask])
return image_list, resize_mode
@@ -175,7 +175,7 @@ class ControlNetForForgeOfficial(scripts.Script):
else:
mask_path = unit.batch_mask_dir[0]
mask_path = os.path.join(unit.batch_mask_dir, mask_path)
mask = np.ascontiguousarray(cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE))
mask = np.ascontiguousarray(cv2.imread(mask_path)[:, :, ::-1]).copy()
if img is not None:
image_list.append([img, mask])
return image_list, resize_mode
@@ -340,7 +340,7 @@ class ControlNetForForgeOfficial(scripts.Script):
for input_mask in control_masks:
fill_border = preprocessor.fill_mask_with_one_when_resize_and_fill
control_mask = crop_and_resize_image(input_mask, resize_mode, h, w, fill_border)
p.extra_result_images.append(params.control_mask)
p.extra_result_images.append(control_mask)
control_mask = numpy_to_pytorch(control_mask).movedim(-1, 1)[:, :1]
params.control_mask.append(control_mask)

View File

@@ -87,7 +87,9 @@ def compute_controlnet_weighting(control, cnet):
final_weight = final_weight * sigma_weight * frame_weight
if isinstance(advanced_mask_weighting, torch.Tensor):
control_signal = control_signal * torch.nn.functional.interpolate(advanced_mask_weighting.to(control_signal), size=(B, H, W), mode='bilinear')
if control_signal.shape[0] == 2 * advanced_mask_weighting.shape[0]:
advanced_mask_weighting = advanced_mask_weighting.repeat(2, 1, 1, 1)
control_signal = control_signal * torch.nn.functional.interpolate(advanced_mask_weighting.to(control_signal), size=(H, W), mode='bilinear')
control[k][i] = control_signal * final_weight[:, None, None, None]