Compare commits

..
15 Commits
Author SHA1 Message Date
ausboss 369702d22a Merge pull request #431 from ausboss/fix/changelog-mask-refine-unreleased
CHANGELOG: the Mask Refine edge change came after 2.29.0
2026-11-27 13:40:45 -06:00
ausboss f453bacf5e Merge main: keep both Unreleased entries (Mask Refine edges, LoRA trigger words) 2026-11-27 13:39:53 -06:00
ausboss 48c0bc0000 Merge pull request #432 from ausboss/fix/flat-curve-missing-trigger-words
LoRA Loader: keep a skipped LoRA's trigger words out on a flat curve
2026-11-27 13:39:30 -06:00
ausboss e76d475eb3 LoRA Loader: keep a skipped LoRA's trigger words out on a flat curve
With Stop on missing LoRA off, a row whose file is missing is skipped
and the node leaves its trigger words out by matching the rows
apply_lora_stack reports in `missing` against its own rows by identity.
A flat Strength Curve made apply_lora_stack swap the rows for scaled
copies, so it reported the copy, the match failed, and the skipped
LoRA's words still reached `triggers`.

apply_lora_stack now keeps the caller's rows, loads from the scaled
copies, and reports the caller's own row as missing. Adds tests for a
missing row on a flat and on a moving curve; the flat one fails before
this change.
2026-11-27 10:52:46 -06:00
ausboss b33ea15575 CHANGELOG: the Mask Refine edge change came after 2.29.0 2026-11-27 10:28:25 -06:00
ausboss 2f080686f9 Merge pull request #415 from kajan988/mask-refine-fix
Mask Refine: guided and matting edges follow the picture, plus Detail range and Fix threshold
2026-11-27 10:27:45 -06:00
ausboss 62413eef53 Merge main into mask-refine-fix
# Conflicts:
#	CHANGELOG.md
2026-11-27 10:24:00 -06:00
ausboss 5cdb560c0c Merge main into mask-refine-fix
# Conflicts:
#	CHANGELOG.md
2026-11-27 10:20:24 -06:00
ausboss af923711a2 Pin Mask Refine's two new fallbacks in the saved-fallbacks test 2026-11-27 10:16:03 -06:00
ausboss 4f54298cac Merge main into mask-refine-fix 2026-11-27 10:10:30 -06:00
ausboss 538698d2b2 Keep matting at the subject's size
Fix threshold defaulted to 0.75, which marked the blurred rim as
background and shrank the matte to about two thirds of the subject. It
now defaults to 0.01. Matting no longer reads White point as its upper
bound, so levels and the solve stay separate. When the blur is wider
than the subject, it narrows until the subject keeps a solid core,
instead of silently returning the mask unchanged.

Also: plain tooltips and help rows for Detail range and Fix threshold,
Chinese names for both, a changelog entry, and the card tests updated
for the two new inputs.
2026-11-26 20:49:48 -06:00
ausboss be9db84962 Merge main into mask-refine-fix 2026-11-26 20:45:50 -06:00
kajan988 c47b4bd36e Merge branch 'Mask_refine=otput_node=true' into mask-refine-fix 2026-11-25 07:11:52 +02:00
kajan988 41260de5b3 Mask refine - output node=true 2026-11-25 06:46:42 +02:00
kajan988 e82fdddfb9 Mask Refine: port LayerStyle-grade edge refinement 2026-11-25 05:37:49 +02:00
14 changed files with 261 additions and 68 deletions
+16
View File
@@ -2,6 +2,22 @@
All notable changes to ComfyUI-AusBoss are documented here.
## Unreleased
- **Mask Refine 🆎's guided and matting edges follow the picture.** Both
edge modes now look further from the mask's edge and snap to the real
edge in the guide image, so hair and thin parts a rough mask missed come
back. Two new settings under More, Detail range and Fix threshold, tune
them. Workflows that use guided or matting will give a cleaner, different
edge after updating. The node can also run on its own now, to check a
mask before the rest of the graph. Thanks to kajan988.
- **LoRA Loader 🆎 leaves out a skipped LoRA's trigger words on a flat
curve too.** With Stop on missing LoRA off, a row whose file is missing is
skipped and its trigger words stay out of `triggers`. That broke when the
row followed a Strength Curve that holds one value the whole run: the LoRA
was skipped, but its words still reached the prompt. They stay out now,
as they already did with no curve or a curve that moves.
## 2.29.0 - 2026-11-27
- **H3 Prompt Writer 🆎 can tidy up your lines.** Turn on **More → Tidy up
+16 -6
View File
@@ -6,6 +6,9 @@ quick brush before the mask goes to an inpainter. It can also snap the edge
to a guide image and adjust the mask's levels. Both the refined mask and its
inverse are returned, so no separate invert node is needed.
You can run it on its own, with nothing wired after it, to check the mask
before the rest of the graph runs.
The panel shows the refined mask itself once the node has run, so the effect
of a setting is visible without wiring a preview node beside it. With a batch
or a video it shows the first mask. The small
@@ -58,12 +61,19 @@ run the workflow again. The switch is the node's optional `preview` input.
- **Edge** (`edge_refine`): `off`, **guided** (`guided filter`), or
`matting`. Both refinements snap the mask edge to the connected
**guide_image** and run per frame, so video batches stay interruptible:
- `guided filter` — fast edge-aware filtering of the soft mask against the
guide image. The filter radius scales with **Expand**.
- `matting` — closed-form alpha matting: the binarized mask eroded by the
edge radius counts as definite foreground, the dilation marks where
definite background begins, and the band between is solved against the
guide image. Pair it with the levels remap to tidy the solved alpha.
- `guided filter` — fast. Pulls the mask's edge onto the edges in the
guide image, which picks up thin parts and loose strands a rough mask
missed. **Detail range** sets how far it looks.
- `matting` — slower and finer. Softens the mask's edge over a wide band
and works out the real edge inside it from the guide image. Pair it
with the levels remap to tidy the result.
- **Detail range** (`detail_range`): How far from the mask's edge to look
for the real edge, `12` by default. Raise it for hair or a loose mask,
lower it for a small subject. Used only while **Edge** is on.
- **Fix threshold** (`fix_threshold`): How much of the softened edge
matting may rework. The default, `0.01`, lets it fix the whole edge;
higher values trim the mask inward. Used only while **Edge** is
`matting`.
- **guide_image** (optional input): RGB frames the mask belongs to, matching
the mask's size; one frame is broadcast across a mask batch. Required when
`edge_refine` is not `off`.
+3
View File
@@ -21,6 +21,7 @@ export const ZH = {
"Target size, extend": "目标尺寸与外扩", "Extra context": "额外上下文", "Target width": "目标宽度", "Target height": "目标高度",
"Rescale": "重新缩放", "Extend left": "向左外扩", "Extend right": "向右外扩", "Extend up": "向上外扩", "Extend down": "向下外扩",
"Expand": "扩张", "Fill holes": "填补孔洞", "Max hole size": "最大孔洞", "Smooth": "平滑", "Black point": "黑场", "White point": "白场",
"Detail range": "细节范围", "Fix threshold": "修正阈值",
"From": "来源", "Folder": "文件夹", "Subfolders": "子文件夹", "Order": "排序", "Run": "运行", "Picture": "图片",
"After a run": "运行之后", "At the end": "到末尾时", "Soften": "柔化", "Fine edges": "精细边缘", "Fill small holes": "填补小孔",
"Invert": "反转", "If nothing": "没选中时", "New picture": "换新图时", "Free VRAM": "释放显存", "Canvas": "画布",
@@ -215,6 +216,8 @@ export const ZH = {
// ---- card tooltips and placeholders
"Size of the finished picture. 0 keeps the picture's own size.": "成品图片的大小。0 表示保持图片原有大小。",
"Used only while Fill holes is on.": "仅在“填补孔洞”开启时使用。",
"Used only while Edge is on.": "仅在“边缘”开启时使用。",
"Used only while Edge is matting.": "仅在“边缘”为抠图(matting)时使用。",
"the folder itself": "文件夹本身",
"Choose a folder inside ComfyUI's input or output folder.": "选择 ComfyUI 的 input 或 output 文件夹里的一个文件夹。",
"Prompt, caption, or shared text": "提示词、字幕或共用文字",
+7 -2
View File
@@ -275,8 +275,9 @@ const CARDS = {
// A workflow saved by a 1.x release holds the preview panel's own empty
// value where preview now sits; it loads on, the node's default. One
// saved by 2.x before Max hole size existed holds the card's there; it
// loads 0, no limit, as the node ran then.
resetUnknown: { preview: true, max_hole_size: 0 },
// loads 0, no limit, as the node ran then. detail_range and fix_threshold
// came later still; older saves hold the card's value there.
resetUnknown: { preview: true, max_hole_size: 0, detail_range: 12, fix_threshold: 0.01 },
rows: [
{ widget: "expand", label: "Expand", suffix: "px" },
{ widget: "blur", label: "Blur" },
@@ -288,6 +289,10 @@ const CARDS = {
{ widget: "black_point", label: "Black point", group: "advanced" },
{ widget: "white_point", label: "White point", group: "advanced" },
{ widget: "edge_refine", label: "Edge", kind: "segment", labels: { "guided filter": "guided" }, group: "advanced" },
{ widget: "detail_range", label: "Detail range", group: "advanced",
mute: (values) => values.edge_refine === "off", muteTitle: "Used only while Edge is on." },
{ widget: "fix_threshold", label: "Fix threshold", group: "advanced",
mute: (values) => values.edge_refine !== "matting", muteTitle: "Used only while Edge is matting." },
],
},
// The settings of Image Folder. Its gallery (js/image_folder) sits under
+6
View File
@@ -1272,6 +1272,12 @@
},
"max_hole_size": {
"name": "最大空洞尺寸"
},
"detail_range": {
"name": "细节范围"
},
"fix_threshold": {
"name": "修正阈值"
}
},
"outputs": {
+7 -4
View File
@@ -574,18 +574,21 @@ def apply_lora_stack(
import comfy.sd
follower = None
effective = rows
if curve is not None and any(row.get("curve") and row["enabled"] for row in rows):
from ._curve_helpers import keyframe_plan
plan = keyframe_plan(curve)
if len(plan) == 1:
# A flat curve is a plain strength: nothing to schedule.
rows = [{**row, "strength": clamp_strength(row["strength"] * plan[0][1])}
if row.get("curve") else row for row in rows]
# Scaled copies; ``missing`` still gets the caller's own rows, which
# the node matches by identity to keep a skipped row's words out.
effective = [{**row, "strength": clamp_strength(row["strength"] * plan[0][1])}
if row.get("curve") else row for row in rows]
else:
follower = LoraCurve(curve)
for row in rows:
for given, row in zip(rows, effective):
if not row["enabled"]:
continue
strength_clip = row["strength_clip"] if clip is not None else 0.0
@@ -607,7 +610,7 @@ def apply_lora_stack(
)
_warn_missing(row["name"], str(exc))
if missing is not None:
missing.append(row)
missing.append(given)
continue
try:
lora_sd = _load_lora_file(path)
+75 -41
View File
@@ -334,14 +334,10 @@ def _load_alpha_matting():
except ImportError as exc:
raise RuntimeError(_MATTING_HINT) from exc
estimate = getattr(pymatting, "estimate_alpha_cf", None)
if estimate is None:
fix_trimap = getattr(pymatting, "fix_trimap", None)
if estimate is None or fix_trimap is None:
raise RuntimeError(_MATTING_HINT)
return estimate
def _edge_radius(expand: int) -> int:
"""Working radius at the edge, scaled with how far the mask was moved."""
return max(4, 2 * abs(int(expand)))
return estimate, fix_trimap
def _guide_frames(
@@ -372,68 +368,101 @@ def _guide_frames(
return frames
def _odd(value: int) -> int:
"""Force a positive odd kernel size, the way cv2 and pymatting expect."""
value = int(value)
if value < 1:
value = 1
return value if value % 2 else value + 1
def guided_filter_refine(
mask: torch.Tensor, guide_image: torch.Tensor, expand: int
mask: torch.Tensor, guide_image: torch.Tensor, detail_range: int
) -> torch.Tensor:
"""Snap soft mask edges to guide-image edges with an edge-aware filter."""
"""Snap soft mask edges to guide-image edges with an edge-aware filter.
A window of detail_range + 1 pixels with a firm eps (0.015) pulls a
feathered mask onto the picture's edge; the old tiny eps (1e-4) left the
gray ramp in place.
"""
guided_filter = _load_guided_filter()
count, height, width = mask.shape
guides = _guide_frames(guide_image, count, height, width)
radius = _edge_radius(expand)
radius = _odd(detail_range + 1)
frames = []
for index in range(count):
raise_if_interrupted()
guide = guides[index].detach().float().clamp(0.0, 1.0).contiguous().cpu().numpy()
source = mask[index].detach().float().contiguous().cpu().numpy()
frames.append(torch.from_numpy(guided_filter(guide, source, radius, 1e-4)))
frames.append(torch.from_numpy(guided_filter(guide, source, radius, 0.015)))
return torch.stack(frames).to(device=mask.device, dtype=mask.dtype).clamp(0.0, 1.0)
def matting_refine(
mask: torch.Tensor, guide_image: torch.Tensor, expand: int
mask: torch.Tensor,
guide_image: torch.Tensor,
detail_range: int,
fix_threshold: float,
) -> torch.Tensor:
"""Closed-form alpha matting around the mask edge.
The binarized mask eroded by the edge radius is definite foreground, the
dilation marks where definite background begins, and the band between is
solved by pymatting's estimate_alpha_cf against the guide image.
The mask alpha is blurred with a wide kernel (detail_range*5+1) to open a
broad unknown band, fix_trimap carves that band into definite foreground,
definite background and unknown, and pymatting's estimate_alpha_cf solves
the unknown against the guide image. The wide blur is what lets the solve
reach the edge; a narrow morphological band left the result ragged.
"""
estimate_alpha_cf = _load_alpha_matting()
estimate_alpha_cf, fix_trimap = _load_alpha_matting()
cv2 = _optional_import("cv2")
count, height, width = mask.shape
guides = _guide_frames(guide_image, count, height, width)
band = _edge_radius(expand)
# Morphology once for the whole batch, not per frame: pooling is
# per-sample, so the batched call is bit-identical, and rebuilding the
# trimap inside the loop was paying the erode/dilate `count` times over.
kernel = _odd(detail_range * 5 + 1)
alpha_all = mask.detach().float().cpu()
solid_all = (alpha_all >= 0.5).float()
eroded_all = grow_shrink_mask(solid_all, -band) >= 0.5
dilated_all = grow_shrink_mask(solid_all, band) >= 0.5
frames = []
for index in range(count):
raise_if_interrupted()
alpha_in = alpha_all[index]
# Definite foreground has to be opaque in the mask we were handed, and
# anything carrying any alpha at all is at least possible foreground.
# On a binary mask those reduce to exactly the eroded and dilated
# shapes; on a feathered one the soft ramp widens the unknown band,
# which is what lets the blur control reach the solve instead of being
# thresholded straight back out of it.
sure_fg = eroded_all[index] & (alpha_in >= 1.0 - _SOFT_EPSILON)
possible = dilated_all[index] | (alpha_in > _SOFT_EPSILON)
unknown = possible & ~sure_fg
if not bool(unknown.any()) or not bool(sure_fg.any()) or bool(possible.all()):
# Degenerate trimap (empty mask, mask everywhere, or a shape the
# band swallows whole): keep this frame's mask as it arrived.
# Nothing to solve on an empty or fully solid frame.
if not bool((alpha_in > _SOFT_EPSILON).any()) or bool(
(alpha_in >= 1.0 - _SOFT_EPSILON).all()
):
frames.append(alpha_in)
continue
# Below fix_threshold is definite background, above 0.99 definite
# foreground, the rest is solved. The upper bound is fixed: a blurred
# alpha never reaches exactly 1, and white_point stays a levels
# control rather than also moving the solve. A high fix_threshold
# marks the blurred rim as background and shrinks the mask, so the
# default is the lowest value.
lower = min(max(float(fix_threshold), 0.01), 0.98)
upper = 0.99
source = alpha_in.numpy().astype("float64")
size = kernel
while True:
blurred = cv2.GaussianBlur(source, (size, size), 0)
trimap = fix_trimap(blurred, lower, upper)
# A blur wider than the subject never lets its core reach the
# upper bound, which leaves no foreground and nothing solved.
# Narrow the blur until the subject keeps a solid core.
if bool((trimap >= 0.9).any()) or size <= 3:
break
size = _odd(size // 2)
if not (
bool((trimap >= 0.9).any())
and bool((trimap <= 0.1).any())
and bool((trimap == 0.5).any())
):
# Thresholds left no usable foreground/background/unknown band
# (e.g. a soft mask whose core never nears 1); keep the mask as it
# arrived instead of letting pymatting raise.
frames.append(alpha_in)
continue
trimap = torch.full((height, width), 0.5, dtype=torch.float64)
trimap[~possible] = 0.0
trimap[sure_fg] = 1.0
guide = (
guides[index].detach().float().clamp(0.0, 1.0).contiguous().cpu().numpy().astype("float64")
)
alpha = estimate_alpha_cf(guide, trimap.numpy())
alpha = estimate_alpha_cf(
guide, trimap, laplacian_kwargs={"epsilon": 1e-6}, cg_kwargs={"maxiter": 500}
)
frames.append(torch.from_numpy(alpha).float())
return torch.stack(frames).to(device=mask.device, dtype=mask.dtype).clamp(0.0, 1.0)
@@ -463,11 +492,16 @@ def refine_mask(
edge_refine: str = "off",
guide_image: torch.Tensor | None = None,
max_hole_size: float = 0.0,
detail_range: int = 12,
fix_threshold: float = 0.01,
) -> tuple[torch.Tensor, torch.Tensor]:
"""Expand, fill holes, smooth, feather, edge-refine, then remap levels.
max_hole_size limits fill holes to holes up to that percent of the
frame's area; 0 (the default) fills every hole, as before it existed.
detail_range and fix_threshold tune the edge_refine pass: detail_range sets
the guided-filter window and the matting unknown-band width, fix_threshold
is the lower trimap threshold for matting (higher trims the mask inward).
"""
if edge_refine not in EDGE_REFINE_MODES:
raise ValueError(
@@ -494,9 +528,9 @@ def refine_mask(
refined = smooth_mask(refined, int(smooth))
refined = blur_mask(refined, blur).clamp(0.0, 1.0)
if edge_refine == "guided filter":
refined = guided_filter_refine(refined, guide_image, expand)
refined = guided_filter_refine(refined, guide_image, detail_range)
elif edge_refine == "matting":
refined = matting_refine(refined, guide_image, expand)
refined = matting_refine(refined, guide_image, detail_range, fix_threshold)
refined = remap_mask(refined, black_point, white_point)
return refined, 1.0 - refined
+33 -1
View File
@@ -15,7 +15,9 @@ class AusBossRefineMask:
"without feathering), feather with a gaussian blur, edge-refine "
"against the optional guide_image (guided filter or alpha matting), "
"then remap levels with black_point/white_point to clear gray haze. "
"Returns the refined mask and its inverse."
"detail_range and fix_threshold (under More) tune the edge-refine pass. "
"Returns the refined mask and its inverse. An output node, so it can run "
"on its own to check the mask before anything downstream."
)
# "refine mask" first: the node shipped under that display name, so the
# phrase people already know has to keep finding it. The name itself now
@@ -27,6 +29,8 @@ class AusBossRefineMask:
"fill holes", "smooth", "levels", "guided filter", "alpha matting",
"mask blur", "mask fix", "ausboss",
]
# An output node, so the node can run on its own.
OUTPUT_NODE = True
@classmethod
def INPUT_TYPES(cls):
@@ -139,6 +143,30 @@ class AusBossRefineMask:
),
},
),
"detail_range": (
"INT",
{
"default": 12,
"min": 1,
"max": 256,
"step": 1,
"tooltip": "How far from the mask's edge to look for the real "
"edge in the guide picture. Raise it for hair or a loose mask, "
"lower it for a small subject. Used only while Edge is on.",
},
),
"fix_threshold": (
"FLOAT",
{
"default": 0.01,
"min": 0.01,
"max": 0.99,
"step": 0.01,
"tooltip": "How much of the softened edge matting may rework. "
"Low (the default) lets it fix the whole edge; higher trims "
"the mask inward. Used only while Edge is matting.",
},
),
},
}
@@ -168,6 +196,8 @@ class AusBossRefineMask:
guide_image=None,
preview=True,
max_hole_size=0.0,
detail_range=12,
fix_threshold=0.01,
):
refined, inverted = refine_mask(
mask,
@@ -180,6 +210,8 @@ class AusBossRefineMask:
edge_refine=str(edge_refine),
guide_image=guide_image,
max_hole_size=float(max_hole_size),
detail_range=int(detail_range),
fix_threshold=float(fix_threshold),
)
# The refined mask itself is the preview. Before this the panel showed
# whatever fed the mask input, and a segmentation node upstream has no
+3 -1
View File
@@ -1083,7 +1083,9 @@
"optional": [
"preview",
"guide_image",
"max_hole_size"
"max_hole_size",
"detail_range",
"fix_threshold"
],
"outputs": [
[
+1 -1
View File
@@ -170,7 +170,7 @@ const APPENDED_SINCE = {
AUSBOSS_NODES_LaMaInpaint: { preview: "toggle" },
// Film Grain's Auto, appended after its preview switch.
AUSBOSS_NODES_FilmGrain: { auto: "toggle", auto_amount: "number", auto_size: "number", grain_from: "socket", auto_color: "number" },
AUSBOSS_NODES_RefineMask: { preview: "toggle", max_hole_size: "number" },
AUSBOSS_NODES_RefineMask: { preview: "toggle", max_hole_size: "number", detail_range: "number", fix_threshold: "number" },
AUSBOSS_NODES_SelectFrame: { preview: "toggle" },
AUSBOSS_NODES_LoraLoader: { on_missing: "combo", curve: "socket" },
// Sockets, which hold no saved value.
+64
View File
@@ -438,6 +438,70 @@ class MissingRowPolicyTests(unittest.TestCase):
)
self.assertEqual(triggers, "kept word, parked word")
def test_a_missing_row_on_a_flat_curve_adds_no_trigger_words(self):
# A LoRA that never loaded must not put its words in the prompt. A
# row parked at strength 0 keeps its words, as the node docs promise,
# so comparing with and without it changes only the weights.
try:
from nodes.node_lora_loader import AusBossLoraLoader
except Exception as exc: # pragma: no cover - needs the package importable
self.skipTest(f"node module not importable offline: {exc}")
def resolve(name):
if name == "gone.safetensors":
raise ValueError("LoRA file not found in models/loras: gone.safetensors")
return Path(name)
rows = [
{**self.ROW, "name": "kept.safetensors", "triggers": "kept word"},
{**self.ROW, "triggers": "ghost word", "curve": True},
{**self.ROW, "name": "parked.safetensors", "strength": 0, "strength_clip": 0,
"triggers": "parked word"},
{**self.ROW, "name": "off.safetensors", "enabled": False, "triggers": "off word"},
]
sys.modules["comfy.sd"].load_lora_for_models = lambda model, clip, *_args: (model, clip)
with (
patch.object(_lora_helpers, "resolve_lora_path", side_effect=resolve),
patch.object(_lora_helpers, "_load_lora_file", return_value={}),
contextlib.redirect_stdout(io.StringIO()),
):
_model, _clip, triggers = AusBossLoraLoader().load_loras(
"model", json.dumps(rows), on_missing="skip", curve=[0.5, 0.5, 0.5]
)
self.assertEqual(triggers, "kept word, parked word")
def test_a_missing_row_on_a_moving_curve_adds_no_trigger_words(self):
# A LoRA that never loaded must not put its words in the prompt. A
# row parked at strength 0 keeps its words, as the node docs promise,
# so comparing with and without it changes only the weights.
try:
from nodes.node_lora_loader import AusBossLoraLoader
except Exception as exc: # pragma: no cover - needs the package importable
self.skipTest(f"node module not importable offline: {exc}")
def resolve(name):
if name == "gone.safetensors":
raise ValueError("LoRA file not found in models/loras: gone.safetensors")
return Path(name)
rows = [
{**self.ROW, "name": "kept.safetensors", "triggers": "kept word"},
{**self.ROW, "triggers": "ghost word", "curve": True},
{**self.ROW, "name": "parked.safetensors", "strength": 0, "strength_clip": 0,
"triggers": "parked word"},
{**self.ROW, "name": "off.safetensors", "enabled": False, "triggers": "off word"},
]
sys.modules["comfy.sd"].load_lora_for_models = lambda model, clip, *_args: (model, clip)
with (
patch.object(_lora_helpers, "resolve_lora_path", side_effect=resolve),
patch.object(_lora_helpers, "_load_lora_file", return_value={}),
contextlib.redirect_stdout(io.StringIO()),
):
_model, _clip, triggers = AusBossLoraLoader().load_loras(
"model", json.dumps(rows), on_missing="skip", curve=[1.0, 0.5, 0.0]
)
self.assertEqual(triggers, "kept word, parked word")
def test_the_on_missing_choices_come_from_the_helper(self):
try:
from nodes.node_lora_loader import AusBossLoraLoader
+22 -8
View File
@@ -186,6 +186,9 @@ class FillHolesLimitTests(unittest.TestCase):
everything, _ = node.refine(kept_subject_mask(), **settings)
self.assertTrue(torch.all(everything == 1.0))
def test_mask_refine_is_an_output_node_so_it_can_run_on_its_own(self):
self.assertIs(node_refine_mask.AusBossRefineMask.OUTPUT_NODE, True)
class SmoothTests(unittest.TestCase):
def test_zero_smooth_is_identity(self):
@@ -467,14 +470,6 @@ class MattingSeesTheFeatherTests(unittest.TestCase):
self.mask, 0, blur, False, guide_image=self.guide, edge_refine="matting"
)[0]
def test_a_wider_feather_produces_a_richer_matte(self):
# Distinct alpha levels separate the two behaviours cleanly: seeding
# from the threshold moved this barely at all, seeding from the soft
# values multiplies it.
base = int(torch.unique(self.matted(0.0)).numel())
feathered = int(torch.unique(self.matted(8.0)).numel())
self.assertGreater(feathered, base * 2)
def test_the_matte_changes_materially_with_the_feather(self):
self.assertGreater(float((self.matted(8.0) - self.matted(0.0)).abs().max()), 0.25)
@@ -485,6 +480,25 @@ class MattingSeesTheFeatherTests(unittest.TestCase):
self.assertLessEqual(float(out.max()), 1.0)
self.assertGreater(int(torch.unique(out).numel()), 2)
def test_matting_keeps_the_subject_its_own_size(self):
# A high lower threshold marked the blurred rim as background and the
# matte came back at about two thirds of the subject.
mask = torch.zeros((1, 256, 256))
mask[:, 64:192, 64:192] = 1.0
guide = torch.rand((1, 256, 256, 3)) * 0.2
guide[:, 64:192, 64:192] += 0.6
out = refine_mask(mask, 0, 0.0, False, guide_image=guide, edge_refine="matting")[0]
self.assertGreater(float(out.sum() / mask.sum()), 0.9)
def test_matting_still_solves_a_subject_smaller_than_its_blur(self):
mask = torch.zeros((1, 256, 256))
mask[:, 113:143, 113:143] = 1.0
guide = torch.full((1, 256, 256, 3), 0.8)
guide[:, 113:143, 113:143] = 0.1
out = refine_mask(mask, 0, 0.0, False, guide_image=guide, edge_refine="matting")[0]
self.assertGreater(int(torch.unique(out).numel()), 2)
self.assertGreater(float(out.sum() / mask.sum()), 0.8)
class SeparableMorphologyTests(unittest.TestCase):
"""grow_shrink_mask runs as one separable pass; the result must stay
+1 -1
View File
@@ -84,7 +84,7 @@ class SavedFallbackTests(unittest.TestCase):
def test_the_known_fallbacks_are_read(self):
self.assertEqual(self.fallbacks["AUSBOSS_NODES_StitchInpaint"], {"seam": "classic", "paste_onto": "crop", "follow_changes": False})
self.assertEqual(self.fallbacks["AUSBOSS_NODES_CropForInpaint"], {"keep_inside": True})
self.assertEqual(self.fallbacks["AUSBOSS_NODES_RefineMask"], {"preview": True, "max_hole_size": 0})
self.assertEqual(self.fallbacks["AUSBOSS_NODES_RefineMask"], {"preview": True, "max_hole_size": 0, "detail_range": 12, "fix_threshold": 0.01})
for node_id in ("AUSBOSS_NODES_LaMaInpaint", "AUSBOSS_NODES_SelectFrame"):
self.assertEqual(self.fallbacks[node_id], {"preview": True})
self.assertEqual(self.fallbacks["AUSBOSS_NODES_LoraLoader"], {"on_missing": "error"})
+7 -3
View File
@@ -281,12 +281,16 @@ test("Mask Refine saved before Max hole size opens with no limit, as an API prom
const maxHole = widgets.find((widget) => widget.name === "max_hole_size");
assert.equal(maxHole.value, "", "the old save hands max_hole_size the card's empty value");
assert.deepEqual(resetUnknownValues(widgets, cardFallbacks("AUSBOSS_NODES_RefineMask")), ["max_hole_size"]);
// Detail range and Fix threshold came later still, so the old save resets them too.
assert.deepEqual(resetUnknownValues(widgets, cardFallbacks("AUSBOSS_NODES_RefineMask")), ["max_hole_size", "detail_range", "fix_threshold"]);
assert.equal(widgets.find((widget) => widget.name === "detail_range").value, 12);
assert.equal(widgets.find((widget) => widget.name === "fix_threshold").value, 0.01);
const defaults = maxHoleSizeDefaults();
assert.equal(maxHole.value, 0);
assert.equal(maxHole.value, defaults.widget, "a new node's default");
assert.equal(maxHole.value, defaults.argument, "what an API prompt without max_hole_size runs with");
const others = widgets.filter((widget) => widget.name !== "max_hole_size" && widget.name !== "ausboss_widget_card");
const appended = ["max_hole_size", "detail_range", "fix_threshold", "ausboss_widget_card"];
const others = widgets.filter((widget) => !appended.includes(widget.name));
assert.deepEqual(others.map((widget) => widget.value), REFINE_BEFORE_MAX_HOLE.slice(0, 8));
});
@@ -296,7 +300,7 @@ test("Mask Refine saved since keeps its Max hole size", () => {
for (const size of [0, 2, 0.5]) {
const widgets = restoreByPosition(names, [...REFINE_BEFORE_MAX_HOLE.slice(0, 8), size], REFINE_TYPES);
widgets.find((widget) => widget.name === "edge_refine").options = { values: ["off", "guided filter", "matting"] };
assert.deepEqual(resetUnknownValues(widgets, fallbacks), []);
assert.deepEqual(resetUnknownValues(widgets, fallbacks), ["detail_range", "fix_threshold"]);
assert.equal(widgets.find((widget) => widget.name === "max_hole_size").value, size);
}
});