feat: support conditioning mask for other detailers
This commit is contained in:
@@ -66,9 +66,27 @@ class SEGSDetailerForAnimateDiff:
|
||||
cropped_image_frames = torch.concat((cropped_image_frames, cropped_image), dim=0)
|
||||
|
||||
cropped_image_frames = cropped_image_frames.cpu().numpy()
|
||||
|
||||
# It is assumed that AnimateDiff does not support conditioning masks based on test results, but it will be added for future consideration.
|
||||
cropped_positive = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, cropped_image_frames, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in positive
|
||||
]
|
||||
|
||||
cropped_negative = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, cropped_image_frames, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in negative
|
||||
]
|
||||
|
||||
enhanced_image_tensor, cnet_images = core.enhance_detail_for_animatediff(cropped_image_frames, model, clip, vae, guide_size, guide_size_for, max_size,
|
||||
seg.bbox, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, denoise, seg.cropped_mask,
|
||||
cropped_positive, cropped_negative, denoise, seg.cropped_mask,
|
||||
refiner_ratio=refiner_ratio, refiner_model=refiner_model,
|
||||
refiner_clip=refiner_clip, refiner_positive=refiner_positive,
|
||||
refiner_negative=refiner_negative, control_net_wrapper=seg.control_net_wrapper,
|
||||
|
||||
@@ -2,7 +2,7 @@ import configparser
|
||||
import os
|
||||
|
||||
|
||||
version_code = [4, 85, 2]
|
||||
version_code = [4, 86]
|
||||
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
|
||||
|
||||
dependency_version = 20
|
||||
|
||||
@@ -1892,6 +1892,12 @@ def adaptive_mask_paste(dest_mask, src_mask, bbox):
|
||||
dest_mask[y1:y2, x1:x2] = bbox_mask
|
||||
|
||||
|
||||
def crop_condition_mask(mask, image, crop_region):
|
||||
cond_scale = (mask.shape[1] / image.shape[1], mask.shape[2] / image.shape[2])
|
||||
mask_region = [round(v * cond_scale[i % 2]) for i, v in enumerate(crop_region)]
|
||||
return crop_ndarray3(mask, mask_region)
|
||||
|
||||
|
||||
class SafeToGPU:
|
||||
def __init__(self, size):
|
||||
self.size = size
|
||||
|
||||
@@ -246,9 +246,25 @@ class DetailerForEach:
|
||||
|
||||
seg_seed = seed + i if seg_seed is None else seg_seed
|
||||
|
||||
cropped_positive = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in positive
|
||||
]
|
||||
|
||||
cropped_negative = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in negative
|
||||
]
|
||||
|
||||
enhanced_image, cnet_pils = core.enhance_detail(cropped_image, model, clip, vae, guide_size, guide_size_for_bbox, max_size,
|
||||
seg.bbox, seg_seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, denoise, cropped_mask, force_inpaint,
|
||||
cropped_positive, cropped_negative, denoise, cropped_mask, force_inpaint,
|
||||
wildcard_opt=wildcard_item, wildcard_opt_concat_mode=wildcard_concat_mode,
|
||||
detailer_hook=detailer_hook,
|
||||
refiner_ratio=refiner_ratio, refiner_model=refiner_model,
|
||||
|
||||
@@ -12,12 +12,6 @@ from . import defs
|
||||
from . import segs_upscaler
|
||||
import math
|
||||
|
||||
def crop_condition_mask(mask, image, crop_region):
|
||||
cond_scale = (mask.shape[1] / image.shape[1], mask.shape[2] / image.shape[2])
|
||||
mask_region = [round(v * cond_scale[i % 2]) for i, v in enumerate(crop_region)]
|
||||
return crop_ndarray3(mask, mask_region)
|
||||
|
||||
|
||||
class SEGSDetailer:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -92,7 +86,7 @@ class SEGSDetailer:
|
||||
|
||||
cropped_positive = [
|
||||
[condition, {
|
||||
k: crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in positive
|
||||
@@ -100,7 +94,7 @@ class SEGSDetailer:
|
||||
|
||||
cropped_negative = [
|
||||
[condition, {
|
||||
k: crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in negative
|
||||
|
||||
Reference in New Issue
Block a user