Compare commits

...
24 Commits
Author SHA1 Message Date
Dr.Lt.Data 705698faf2 bump version 2025-06-19 12:40:42 +09:00
Dr.Lt.Data cf43fc4e3c fix: typo in locales 2025-06-19 12:39:30 +09:00
robo 4c292e684e change wildcard {} regex to allow escaping (#968) 2025-06-19 12:39:06 +09:00
Dr.Lt.Data 65f1363a10 feat: LamaRemoverDetailerHookProvider is added 2025-06-17 23:40:50 +09:00
Dr.Lt.Data f57d309932 fixed: avoid potential conflict
- If everything is working as expected, this conflict shouldn't occur. However, some node pack might be adding the `impact` module to `sys.path`.

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/1022
2025-06-17 00:46:43 +09:00
NicolasKlenert 6ccf9bab68 fixed: SegmDetectorCombined - incorrect empty mask dimension (#1021) 2025-06-16 12:34:56 +09:00
Dr.Lt.Data ac3668d946 feat: CustomSamplerDetailerHookProvider is added
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/957
2025-06-11 21:52:25 +09:00
Emmanuel Ferdman 78d3793a77 Resolve regex library warnings (#1011)
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
2025-06-10 12:35:46 +09:00
Dr.Lt.Data 2346b67766 fixed: Switch (Any) - copy&paste error
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/1012
2025-06-01 04:52:24 +09:00
Dr.Lt.Data 025db4b581 fixed: MaskRectArea - type error
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/1001
2025-06-01 04:43:46 +09:00
Dr.Lt.Data f8e16df2be bump version 2025-05-19 08:33:30 +09:00
Dr.Lt.Data 7df60b2107 fixed: install.py - user friendly message with exception handling 2025-05-19 08:31:07 +09:00
Dr.Lt.Data b394c158ea modified: requirements.txt remove pinning <2 for numpy 2025-05-19 05:16:00 +09:00
Dr.Lt.Data 3e3cf3a5b4 support nunchaku lora loading in the wildcard feature
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/993
2025-05-18 18:14:42 +09:00
Dr.Lt.Data 93fc248503 fixed: cannot connect wildcard input/output to the Switch / InversedSwitch nodes
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/992
2025-05-16 04:42:26 +09:00
Dr.Lt.Data 16ffa7d462 hotfix: potential front error
```
TypeError: Cannot read properties of undefined (reading 'type')
```

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/989
2025-05-16 03:59:10 +09:00
filtered cd34cfdd63 Fix empty widgets array throws in console (#988) 2025-05-03 14:37:31 +09:00
Dr.Lt.Data 38bb9ffdf6 fixed: Switch - buggy behavior on firefox browser
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/983#issuecomment-2833471721
2025-04-28 00:54:31 +09:00
Dr.Lt.Data f939e66e1c fixed: this.widgets is undefined
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/977
2025-04-27 22:16:11 +09:00
robo b22aa90cf4 allow for .yml files in wildcards (#966)
both are valid yaml extensions so it makes sense to allow both
2025-04-25 18:50:40 +09:00
Dr.Lt.Data d18aaecb93 bump version 2025-04-25 18:46:18 +09:00
だにえる a7840b4fbf feat: tensor_paste supports RGBA images with alpha channel blending (#962)
This enhancement adds support for properly handling RGBA images in the tensor_paste function.

The previous implementation caused errors when pasting images with alpha channels.
Now the function can handle all combinations of RGB and RGBA images:
- RGB to RGB (unchanged)
- RGBA to RGBA (with proper alpha compositing)
- RGB to RGBA
- RGBA to RGB

Fix for the error: "RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 3"
2025-04-25 18:35:03 +09:00
robo efa0cb66b2 always use impact.wildcards.process fixes server side wildcards.process not getting new wildcard_dict (#967) 2025-04-25 18:21:55 +09:00
Dr.Lt.Data 0b94005b1b hotfix: impactswitch - frontend crash
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/970#issuecomment-2827153556
2025-04-25 08:03:20 +09:00
18 changed files with 313 additions and 128 deletions
+6
View File
@@ -189,6 +189,10 @@ NOTE: The UltralyticsDetectorProvider node is not part of the ComfyUI-Impact-Pac
* `PreviewDetailerHook` - Connecting this hook node helps provide assistance for viewing previews whenever SEGS Detailing tasks are completed. When working with a large number of SEGS, such as Make Tile SEGS, it allows for monitoring the situation as improvements progress incrementally.
* Since this is the hook applied when pasting onto the original image, it has no effect on nodes like `SEGSDetailer`.
* `VariationNoiseDetailerHookProvider` - Apply variation seed to the detailer. It can be applied in multiple stages through combine.
* `CustomSamplerDetailerHookProvider` - Apply a hook that allows you to use a custom sampler in the Detailer nodes. When using `DetailerHookCombine`, the sampler from the first hook is applied.
* `LamaRemoverDetailerHookProvider` – Applies Lama Remover to the upscaled image during the detailing stage. If `skip_sampling` is set to True, Lama Remover can be used alone without the detailing stage, allowing it to simply remove detected regions.
* Not applicable for **AnimateDiff** detailers. When using `DetailerHookCombine`, `skip_sampling` is only applied if it is set to `True` for all hooks.
* To use this node, the node pack at [Layer-norm/comfyui-lama-remover](https://github.com/Layer-norm/comfyui-lama-remover) must be installed.
### Iterative Upscale nodes
* `Iterative Upscale (Latent/on Pixel Space)` - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling.
@@ -488,3 +492,5 @@ BlenderNeok/[ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) - The
WASasquatch/[was-node-suite-comfyui](https://github.com/WASasquatch/was-node-suite-comfyui) - A powerful custom node extensions of ComfyUI.
Trung0246/[ComfyUI-0246](https://github.com/Trung0246/ComfyUI-0246) - Nice bypass hack!
Layer-norm/[comfyui-lama-remover](https://github.com/Layer-norm/comfyui-lama-remover) - Required for using `LamaRemoverDetailerHook`.
+2
View File
@@ -122,6 +122,8 @@ NODE_CLASS_MAPPINGS = {
"UnsamplerHookProvider": UnsamplerHookProvider,
"CoreMLDetailerHookProvider": CoreMLDetailerHookProvider,
"PreviewDetailerHookProvider": PreviewDetailerHookProvider,
"CustomSamplerDetailerHookProvider": CustomSamplerDetailerHookProvider,
"LamaRemoverDetailerHookProvider": LamaRemoverDetailerHookProvider,
"DetailerHookCombine": DetailerHookCombine,
"NoiseInjectionDetailerHookProvider": NoiseInjectionDetailerHookProvider,
+14 -12
View File
@@ -68,7 +68,6 @@ def process_wrap(cmd_str, cwd=None, handler=None, env=None):
try:
import platform
from torchvision.datasets.utils import download_url
import impact.config
@@ -99,7 +98,7 @@ try:
if not os.path.exists(os.path.join(sam_path, "sam_vit_b_01ec64.pth")):
download_url("https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth", sam_path)
except:
print(f"[Impact Pack] Failed to auto-download model files. Please download them manually.")
print("[Impact Pack] Failed to auto-download model files. Please download them manually.")
if not os.path.exists(onnx_path):
print(f"### ComfyUI-Impact-Pack: onnx model directory created ({onnx_path})")
@@ -108,18 +107,21 @@ try:
impact.config.write_config()
# Remove legacy subpack
subpack_path = os.path.join(os.path.dirname(__file__), 'impact_subpack')
if os.path.exists(subpack_path):
shutil.rmtree(subpack_path)
print(f"Legacy subpack is detected. '{subpack_path}' is removed.")
subpack_path = os.path.join(os.path.dirname(__file__), 'subpack')
if os.path.exists(subpack_path):
shutil.rmtree(subpack_path)
print(f"Legacy subpack is detected. '{subpack_path}' is removed.")
try:
subpack_path = os.path.join(os.path.dirname(__file__), 'impact_subpack')
if os.path.exists(subpack_path):
shutil.rmtree(subpack_path)
print(f"Legacy subpack is detected. '{subpack_path}' is removed.")
subpack_path = os.path.join(os.path.dirname(__file__), 'subpack')
if os.path.exists(subpack_path):
shutil.rmtree(subpack_path)
print(f"Legacy subpack is detected. '{subpack_path}' is removed.")
except:
print(f"ERROT: Failed to delete legacy subpack '{subpack_path}'\nPlease delete the folder after terminate ComfyUI.")
install()
except Exception as e:
except Exception:
print("[ERROR] ComfyUI-Impact-Pack: Dependency installation has failed. Please install manually.")
traceback.print_exc()
+31 -15
View File
@@ -370,12 +370,12 @@ app.registerExtension({
if(type == 2) {
// connect output
if(connected){
if(app.graph._nodes_by_id[link_info.target_id].type == 'Reroute') {
if(app.graph._nodes_by_id[link_info.target_id]?.type == 'Reroute') {
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
}
if(this.outputs[0].type == '*'){
if(link_info.type == '*') {
if(link_info.type == '*' && app.graph.getNodeById(link_info.target_id).slots[link_info.target_slot].type != '*') {
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
}
else {
@@ -392,7 +392,7 @@ app.registerExtension({
}
}
else {
if(app.graph._nodes_by_id[link_info.origin_id].type == 'Reroute')
if(app.graph._nodes_by_id[link_info.origin_id]?.type == 'Reroute')
this.disconnectInput(link_info.target_slot);
// connect input
@@ -404,7 +404,7 @@ app.registerExtension({
return; // fallback
}
if(origin_type == '*') {
if(origin_type == '*' && app.graph.getNodeById(link_info.origin_id).slots[link_info.origin_slot].type != '*') {
this.disconnectInput(link_info.target_slot);
return;
}
@@ -428,8 +428,9 @@ app.registerExtension({
!stackTrace.includes('LGraphNode.prototype.connect') && // for touch device
!stackTrace.includes('LGraphNode.connect') && // for mouse device
!stackTrace.includes('loadGraphData')) {
if(this.outputs[link_info.origin_slot].links.length == 0)
if(this.outputs[link_info.origin_slot].links.length == 0) {
this.removeOutput(link_info.origin_slot);
}
}
}
@@ -442,9 +443,12 @@ app.registerExtension({
slot_i++;
}
let last_slot = this.outputs[this.outputs.length - 1];
if (last_slot.slot_index == link_info.origin_slot) {
this.addOutput(`output${slot_i}`, this.outputs[0].type);
if(connected) {
// NOTE: node.slot_index is different with link_info.origin_slot
let last_slot_index = this.outputs.length - 1;
if (last_slot_index == link_info.origin_slot) {
this.addOutput(`output${slot_i}`, this.outputs[0].type);
}
}
let select_slot = this.inputs.find(x => x.name == "select");
@@ -508,9 +512,19 @@ app.registerExtension({
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
const stackTrace = new Error().stack;
if(stackTrace.includes('LGraph.configure')) {
this.widgets[0].options.max = this.inputs.length-3;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
if(stackTrace.includes('loadGraphData')) {
if(this.widgets?.[0]) {
this.widgets[0].options.max = this.inputs.length-3;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
}
return;
}
if(stackTrace.includes('pasteFromClipboard')) {
if(this.widgets?.[0]) {
this.widgets[0].options.max = this.inputs.length-3;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
}
return;
}
@@ -525,7 +539,7 @@ app.registerExtension({
}
if(this.outputs[0].type == '*'){
if(link_info.type == '*') {
if(link_info.type == '*' && app.graph.getNodeById(link_info.target_id).slots[link_info.target_slot].type != '*') {
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
}
else {
@@ -561,7 +575,7 @@ app.registerExtension({
node.connect(link_info.origin_slot, node.id, 'input1');
}
if(origin_type == '*') {
if(origin_type == '*' && app.graph.getNodeById(link_info.origin_id).slots[link_info.origin_slot].type != '*') {
this.disconnectInput(link_info.target_slot);
return;
}
@@ -604,8 +618,10 @@ app.registerExtension({
this.addInput(`${input_name}${slot_i}`, this.outputs[0].type);
}
this.widgets[0].options.max = this.inputs.length-3;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
if(this.widgets?.[0]) {
this.widgets[0].options.max = this.inputs.length-3;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
}
}
}
},
+1 -1
View File
@@ -1196,7 +1196,7 @@
"ImpactWildcardEncode": {
"description": "이 노드는 와일드카드 구문으로 작성된 텍스트 프롬프트를 처리하고 이를 조건으로 출력합니다. 또한 LoRA 구문을 지원하며, 적용된 LoRA는 모델 출력에 반영됩니다.\n\nTIP1: 워크플로가 실행되기 전에 '와일드카드 텍스트'의 처리 결과가 '채워진 텍스트'에 표시되며, 이 값은 워크플로와 함께 저장됩니다. 입력으로 변환된 시드를 사용하려면 '와일드카드 텍스트' 대신 '채워진 텍스트'에 직접 프롬프트를 작성하고, 모드를 '고정(fixed)'로 설정하세요.\nTIP2: 'Inspire Pack'이 설치되어 있으면 LBW(로라 블록 웨이트) 구문도 적용할 수 있습니다.",
"display_name": "와일드카드 처리기 (Impact)",
"display_name": "와일드카드 인코딩 (Impact)",
"inputs": {
"wildcard_text": {
"name": "와일드카드 텍스트",
+1 -1
View File
@@ -1,7 +1,7 @@
import configparser
import os
version_code = [8, 13]
version_code = [8, 17, 1]
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
dependency_version = 24
+64 -48
View File
@@ -320,6 +320,9 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
# upscale
upscaled_image = tensor_resize(image, new_w, new_h)
if detailer_hook is not None:
upscaled_image = detailer_hook.post_upscale(upscaled_image, noise_mask)
cnet_pils = None
if control_net_wrapper is not None:
positive, negative, cnet_pils = control_net_wrapper.apply(positive, negative, upscaled_image, noise_mask)
@@ -327,61 +330,69 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
cnet_pils.extend(cnet_pils2)
# prepare mask
if noise_mask is not None and inpaint_model:
imc_encode = nodes.InpaintModelConditioning().encode
if 'noise_mask' in inspect.signature(imc_encode).parameters:
positive, negative, latent_image = imc_encode(positive, negative, upscaled_image, vae, mask=noise_mask, noise_mask=True)
if detailer_hook is None or not detailer_hook.get_skip_sampling():
if noise_mask is not None and inpaint_model:
imc_encode = nodes.InpaintModelConditioning().encode
if 'noise_mask' in inspect.signature(imc_encode).parameters:
positive, negative, latent_image = imc_encode(positive, negative, upscaled_image, vae, mask=noise_mask, noise_mask=True)
else:
print(f"[Impact Pack] ComfyUI is an outdated version.")
positive, negative, latent_image = imc_encode(positive, negative, upscaled_image, vae, noise_mask)
else:
print(f"[Impact Pack] ComfyUI is an outdated version.")
positive, negative, latent_image = imc_encode(positive, negative, upscaled_image, vae, noise_mask)
else:
latent_image = to_latent_image(upscaled_image, vae, vae_tiled_encode=vae_tiled_encode)
if noise_mask is not None:
latent_image['noise_mask'] = noise_mask
latent_image = to_latent_image(upscaled_image, vae, vae_tiled_encode=vae_tiled_encode)
if noise_mask is not None:
latent_image['noise_mask'] = noise_mask
if detailer_hook is not None:
latent_image = detailer_hook.post_encode(latent_image)
refined_latent = latent_image
# ksampler
for i in range(0, cycle):
if detailer_hook is not None:
latent_image = detailer_hook.post_encode(latent_image)
refined_latent = latent_image
sampler_opt=None
if detailer_hook is not None:
sampler_opt = detailer_hook.get_custom_sampler()
# ksampler
for i in range(0, cycle):
if detailer_hook is not None:
detailer_hook.set_steps((i, cycle))
if detailer_hook is not None:
detailer_hook.set_steps((i, cycle))
refined_latent = detailer_hook.cycle_latent(refined_latent)
refined_latent = detailer_hook.cycle_latent(refined_latent)
model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2, upscaled_latent2, denoise2 = \
detailer_hook.pre_ksample(model, seed+i, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)
noise, is_touched = detailer_hook.get_custom_noise(seed+i, torch.zeros(latent_image['samples'].size()), is_touched=False)
if not is_touched:
model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2, upscaled_latent2, denoise2 = \
detailer_hook.pre_ksample(model, seed+i, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)
noise, is_touched = detailer_hook.get_custom_noise(seed+i, torch.zeros(latent_image['samples'].size()), is_touched=False)
if not is_touched:
noise = None
else:
model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2, upscaled_latent2, denoise2 = \
model, seed + i, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise
noise = None
refined_latent = impact_sampling.ksampler_wrapper(model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2,
refined_latent, denoise2, refiner_ratio, refiner_model, refiner_clip, refiner_positive, refiner_negative,
noise=noise, scheduler_func=scheduler_func, sampler_opt=sampler_opt)
if detailer_hook is not None:
refined_latent = detailer_hook.pre_decode(refined_latent)
# non-latent downscale - latent downscale cause bad quality
start = time.time()
if vae_tiled_decode:
(refined_image,) = nodes.VAEDecodeTiled().decode(vae, refined_latent, 512) # using default settings
print(f"[Impact Pack] vae decoded (tiled) in {time.time() - start:.1f}s")
else:
model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2, upscaled_latent2, denoise2 = \
model, seed + i, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise
noise = None
refined_latent = impact_sampling.ksampler_wrapper(model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2,
refined_latent, denoise2, refiner_ratio, refiner_model, refiner_clip, refiner_positive, refiner_negative,
noise=noise, scheduler_func=scheduler_func)
if detailer_hook is not None:
refined_latent = detailer_hook.pre_decode(refined_latent)
# non-latent downscale - latent downscale cause bad quality
start = time.time()
if vae_tiled_decode:
(refined_image,) = nodes.VAEDecodeTiled().decode(vae, refined_latent, 512) # using default settings
print(f"[Impact Pack] vae decoded (tiled) in {time.time() - start:.1f}s")
try:
refined_image = vae.decode(refined_latent['samples'])
except Exception as e:
# usually an out-of-memory exception from the decode, so try a tiled approach
print(f"[Impact Pack] failed after {time.time() - start:.1f}s, doing vae.decode_tiled 64...")
refined_image = vae.decode_tiled(refined_latent["samples"], tile_x=64, tile_y=64, )
print(f"[Impact Pack] vae decoded in {time.time() - start:.1f}s")
else:
try:
refined_image = vae.decode(refined_latent['samples'])
except Exception as e:
# usually an out-of-memory exception from the decode, so try a tiled approach
print(f"[Impact Pack] failed after {time.time() - start:.1f}s, doing vae.decode_tiled 64...")
refined_image = vae.decode_tiled(refined_latent["samples"], tile_x=64, tile_y=64, )
print(f"[Impact Pack] vae decoded in {time.time() - start:.1f}s")
# skipped
refined_image = upscaled_image
if detailer_hook is not None:
refined_image = detailer_hook.post_decode(refined_image)
@@ -513,11 +524,16 @@ def enhance_detail_for_animatediff(image_frames, model, clip, vae, guide_size, g
'samples': latent_frames
}
sampler_opt=None
if detailer_hook is not None:
sampler_opt = detailer_hook.get_custom_sampler()
if detailer_hook is not None:
latent = detailer_hook.post_encode(latent)
refined_latent = impact_sampling.ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
latent, denoise, refiner_ratio, refiner_model, refiner_clip, refiner_positive, refiner_negative, scheduler_func=scheduler_func)
latent, denoise, refiner_ratio, refiner_model, refiner_clip, refiner_positive, refiner_negative, scheduler_func=scheduler_func, sampler_opt=sampler_opt)
if detailer_hook is not None:
refined_latent = detailer_hook.pre_decode(refined_latent)
@@ -1077,7 +1093,7 @@ class ONNXDetector:
def detect(self, image, threshold, dilation, crop_factor, drop_size=1, detailer_hook=None):
drop_size = max(drop_size, 1)
try:
import impact.onnx as onnx
import impact.impact_onnx as onnx
h = image.shape[1]
w = image.shape[2]
+2 -2
View File
@@ -163,7 +163,7 @@ class SegmDetectorCombined:
mask = segm_detector.detect_combined(image, threshold, dilation)
if mask is None:
mask = torch.zeros((image.shape[2], image.shape[1]), dtype=torch.float32, device="cpu")
mask = torch.zeros((image.shape[1], image.shape[2]), dtype=torch.float32, device="cpu")
return (mask.unsqueeze(0),)
@@ -183,7 +183,7 @@ class BboxDetectorCombined(SegmDetectorCombined):
mask = bbox_detector.detect_combined(image, threshold, dilation)
if mask is None:
mask = torch.zeros((image.shape[2], image.shape[1]), dtype=torch.float32, device="cpu")
mask = torch.zeros((image.shape[1], image.shape[2]), dtype=torch.float32, device="cpu")
return (mask.unsqueeze(0),)
+23
View File
@@ -1,6 +1,8 @@
import sys
from . import hooks
from . import defs
from . import utils
import nodes
class SEGSOrderedFilterDetailerHookProvider:
@@ -83,3 +85,24 @@ class PreviewDetailerHookProvider:
def doit(self, quality, unique_id):
hook = hooks.PreviewDetailerHook(unique_id, quality)
return hook, hook
class LamaRemoverDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask_threshold":("INT", {"default": 250, "min": 0, "max": 255, "step": 1, "display": "slider"}),
"gaussblur_radius": ("INT", {"default": 8, "min": 0, "max": 20, "step": 1, "display": "slider"}),
"skip_sampling": ("BOOLEAN", {"default": True}),
}
}
RETURN_TYPES = ("DETAILER_HOOK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, mask_threshold, gaussblur_radius, skip_sampling):
hook = hooks.LamaRemoverDetailerHook(mask_threshold, gaussblur_radius, skip_sampling)
return (hook, )
+48 -3
View File
@@ -25,7 +25,7 @@ class PixelKSampleHook:
def post_decode(self, pixels):
return pixels
def post_upscale(self, pixels):
def post_upscale(self, pixels, mask=None):
return pixels
def post_encode(self, samples):
@@ -64,8 +64,8 @@ class PixelKSampleHookCombine(PixelKSampleHook):
def post_decode(self, pixels):
return self.hook2.post_decode(self.hook1.post_decode(pixels))
def post_upscale(self, pixels):
return self.hook2.post_upscale(self.hook1.post_upscale(pixels))
def post_upscale(self, pixels, mask=None):
return self.hook2.post_upscale(self.hook1.post_upscale(pixels, mask), mask)
def post_encode(self, samples):
return self.hook2.post_encode(self.hook1.post_encode(samples))
@@ -109,6 +109,15 @@ class DetailerHookCombine(PixelKSampleHookCombine):
noise_2nd, is_touched = self.hook2.get_custom_noise(seed, noise, is_touched)
return noise, is_touched
def get_custom_sampler(self):
if self.hook1.get_custom_sampler() is not None:
return self.hook1.get_custom_sampler()
else:
return self.hook2.get_custom_sampler()
def get_skip_sampling(self):
return self.hook1.get_skip_sampling() and self.hook2.get_skip_sampling()
class SimpleCfgScheduleHook(PixelKSampleHook):
target_cfg = 0
@@ -173,6 +182,21 @@ class DetailerHook(PixelKSampleHook):
def get_custom_noise(self, seed, noise, is_touched):
return noise, is_touched
def get_custom_sampler(self):
return None
def get_skip_sampling(self):
return False
class CustomSamplerDetailerHookProvider(DetailerHook):
def __init__(self, sampler):
super().__init__()
self.sampler = sampler
def get_custom_sampler(self):
return self.sampler
# class CustomNoiseDetailerHookProvider(DetailerHook):
# def __init__(self, noise):
@@ -486,6 +510,27 @@ class SEGSLabelFilterDetailerHook(DetailerHook):
return segs_nodes.SEGSLabelFilter().doit(segs, "", self.labels)[0]
class LamaRemoverDetailerHook(DetailerHook):
def __init__(self, mask_threshold, gaussblur_radius, skip_sampling):
super().__init__()
self.mask_threshold = mask_threshold
self.gaussblur_radius = gaussblur_radius
self.skip_sampling = skip_sampling
def post_upscale(self, img, mask=None):
if "LamaRemover" in nodes.NODE_CLASS_MAPPINGS:
lama_remover_obj = nodes.NODE_CLASS_MAPPINGS['LamaRemover']()
else:
utils.try_install_custom_node('https://github.com/Layer-norm/comfyui-lama-remover',
"To use 'LAMARemoverDetailerHookProvider', 'comfyui-lama-remover' nodepack is required.")
raise Exception("'LamaRemover' node is not installed.")
return lama_remover_obj.lama_remover(img, masks=mask, mask_threshold=self.mask_threshold, gaussblur_radius=self.gaussblur_radius, invert_mask=False)[0]
def get_skip_sampling(self):
return self.skip_sampling
class PreviewDetailerHook(DetailerHook):
def __init__(self, node_id, quality):
super().__init__()
+21 -1
View File
@@ -811,6 +811,26 @@ class CoreMLDetailerHookProvider:
return (hook, )
class CustomSamplerDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"sampler": ("SAMPLER", ),
},
}
RETURN_TYPES = ("DETAILER_HOOK",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detailer"
DESCRIPTION = "Apply a hook that allows you to use a custom sampler in the Detailer nodes. When using `DetailerHookCombine`, the sampler from the first hook is applied."
def doit(self, sampler):
hook = hooks.CustomSamplerDetailerHookProvider(sampler)
return (hook, )
class CfgScheduleHookProvider:
schedules = ["simple"]
@@ -1906,7 +1926,7 @@ class MaskRectArea:
# search for node
node_found = False
for node in extra_pnginfo["workflow"]["nodes"]:
if node["id"] == int(unique_id):
if str(node["id"]) == unique_id:
min_x = node["properties"].get("x", 0) / 100
min_y = node["properties"].get("y", 0) / 100
width = node["properties"].get("w", 0) / 100
+4 -4
View File
@@ -194,7 +194,7 @@ def impact_sample(model, seed, steps, cfg, sampler_name, scheduler, positive, ne
def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise,
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None, refiner_negative=None, sigma_factor=1.0, noise=None, scheduler_func=None):
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None, refiner_negative=None, sigma_factor=1.0, noise=None, scheduler_func=None, sampler_opt=None):
if refiner_ratio is None or refiner_model is None or refiner_clip is None or refiner_positive is None or refiner_negative is None:
# Use separated_sample instead of KSampler for `AYS scheduler`
@@ -206,7 +206,7 @@ def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive,
refined_latent = separated_sample(model, True, seed, advanced_steps, cfg, sampler_name, scheduler,
positive, negative, latent_image, start_at_step, end_at_step, False,
sigma_ratio=sigma_factor, noise=noise, scheduler_func=scheduler_func)
sigma_ratio=sigma_factor, sampler_opt=sampler_opt, noise=noise, scheduler_func=scheduler_func)
else:
advanced_steps = math.floor(steps / denoise)
start_at_step = advanced_steps - steps
@@ -215,7 +215,7 @@ def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive,
# print(f"pre: {start_at_step} .. {end_at_step} / {advanced_steps}")
temp_latent = separated_sample(model, True, seed, advanced_steps, cfg, sampler_name, scheduler,
positive, negative, latent_image, start_at_step, end_at_step, True,
sigma_ratio=sigma_factor, noise=noise, scheduler_func=scheduler_func)
sigma_ratio=sigma_factor, sampler_opt=sampler_opt, noise=noise, scheduler_func=scheduler_func)
if 'noise_mask' in latent_image:
# noise_latent = \
@@ -229,7 +229,7 @@ def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive,
# print(f"post: {end_at_step} .. {advanced_steps + 1} / {advanced_steps}")
refined_latent = separated_sample(refiner_model, False, seed, advanced_steps, cfg, sampler_name, scheduler,
refiner_positive, refiner_negative, temp_latent, end_at_step, advanced_steps + 1, False,
sigma_ratio=sigma_factor, scheduler_func=scheduler_func)
sigma_ratio=sigma_factor, sampler_opt=sampler_opt, scheduler_func=scheduler_func)
return refined_latent
+2 -3
View File
@@ -17,7 +17,6 @@ import numpy as np
import nodes
from PIL import Image
import io
import impact.wildcards as wildcards
import comfy
from io import BytesIO
import random
@@ -183,7 +182,7 @@ async def wildcards_list(request):
@PromptServer.instance.routes.post("/impact/wildcards")
async def populate_wildcards(request):
data = await request.json()
populated = wildcards.process(data['text'], data.get('seed', None))
populated = impact.wildcards.process(data['text'], data.get('seed', None))
return web.json_response({"text": populated})
@@ -512,7 +511,7 @@ def onprompt_populate_wildcards(json_data):
else:
input_seed = int(inputs['seed'])
inputs['populated_text'] = wildcards.process(inputs['wildcard_text'], input_seed)
inputs['populated_text'] = impact.wildcards.process(inputs['wildcard_text'], input_seed)
inputs['mode'] = 'reproduce'
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "populated_text", "type": "STRING", "value": inputs['populated_text']})
+53 -13
View File
@@ -178,31 +178,71 @@ def tensor2numpy(image):
def tensor_paste(image1, image2, left_top, mask):
"""Mask and image2 has to be the same size"""
"""
Pastes image2 onto image1 at position left_top using mask.
Supports both RGB and RGBA images.
"""
_tensor_check_image(image1)
_tensor_check_image(image2)
_tensor_check_mask(mask)
if image2.shape[1:3] != mask.shape[1:3]:
mask = resize_mask(mask.squeeze(dim=3), image2.shape[1:3]).unsqueeze(dim=3)
# raise ValueError(f"Inconsistent size: Image ({image2.shape[1:3]}) != Mask ({mask.shape[1:3]})")
x, y = left_top
_, h1, w1, _ = image1.shape
_, h2, w2, _ = image2.shape
# calculate image patch size
_, h1, w1, c1 = image1.shape
_, h2, w2, c2 = image2.shape
# Calculate image patch size
w = min(w1, x + w2) - x
h = min(h1, y + h2) - y
# If the patch is out of bound, nothing to do!
if w <= 0 or h <= 0:
return
mask = mask[:, :h, :w, :]
image1[:, y:y+h, x:x+w, :] = (
(1 - mask) * image1[:, y:y+h, x:x+w, :] +
mask * image2[:, :h, :w, :]
)
# Get the region to be modified
region1 = image1[:, y:y+h, x:x+w, :]
region2 = image2[:, :h, :w, :]
# Handle RGB and RGBA cases
if c1 == 3 and c2 == 3:
# Both RGB - simple case
image1[:, y:y+h, x:x+w, :] = (1 - mask) * region1 + mask * region2
elif c1 == 4 and c2 == 4:
# Both RGBA - need to handle alpha channel separately
# RGB channels
image1[:, y:y+h, x:x+w, :3] = (
(1 - mask) * region1[:, :, :, :3] +
mask * region2[:, :, :, :3]
)
# Alpha channel - use "over" composition
a1 = region1[:, :, :, 3:4]
a2 = region2[:, :, :, 3:4] * mask
new_alpha = a1 + a2 * (1 - a1)
image1[:, y:y+h, x:x+w, 3:4] = new_alpha
elif c1 == 4 and c2 == 3:
# Target is RGBA, source is RGB - assume source is fully opaque
image1[:, y:y+h, x:x+w, :3] = (
(1 - mask) * region1[:, :, :, :3] +
mask * region2
)
# Alpha channel - reduce alpha where mask is applied
image1[:, y:y+h, x:x+w, 3:4] = region1[:, :, :, 3:4] * (1 - mask) + mask
elif c1 == 3 and c2 == 4:
# Target is RGB, source is RGBA - apply source alpha to mask
effective_mask = mask * region2[:, :, :, 3:4]
image1[:, y:y+h, x:x+w, :] = (
(1 - effective_mask) * region1 +
effective_mask * region2[:, :, :, :3]
)
return
+39 -23
View File
@@ -8,6 +8,7 @@ import numpy as np
import threading
from impact import utils
from impact import config
import logging
wildcards_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "wildcards"))
@@ -65,7 +66,7 @@ def read_wildcard_dict(wildcard_path):
with open(file_path, 'r', encoding="UTF-8", errors="ignore") as f:
lines = f.read().splitlines()
wildcard_dict[key] = [x for x in lines if not x.strip().startswith('#')]
elif file.endswith('.yaml'):
elif file.endswith('.yaml') or file.endswith('.yml'):
file_path = os.path.join(root, file)
try:
@@ -211,7 +212,7 @@ def process(text, seed=None):
selected_items = random_gen.choice(options, p=normalized_probabilities, size=select_count, replace=False)
# x may be numpy.int32, convert to string
selected_items2 = [re.sub(r'^\s*[0-9.]+::', '', str(x), 1) for x in selected_items]
selected_items2 = [re.sub(r'^\s*[0-9.]+::', '', str(x), count=1) for x in selected_items]
replacement = select_sep.join(selected_items2)
if '::' in replacement:
pass
@@ -219,7 +220,7 @@ def process(text, seed=None):
replacements_found = True
return replacement
pattern = r'{([^{}]*?)}'
pattern = r'(?<!\\)\{((?:[^{}]|(?<=\\)[{}])*?)(?<!\\)\}'
replaced_string = re.sub(pattern, replace_option, string)
return replaced_string, replacements_found
@@ -278,7 +279,7 @@ def process(text, seed=None):
normalized_probabilities = [prob / total_prob for prob in adjusted_probabilities]
selected_item = random_gen.choice(options, p=normalized_probabilities, replace=False)
replacement = re.sub(r'^\s*[0-9.]+::', '', selected_item, 1)
replacement = re.sub(r'^\s*[0-9.]+::', '', selected_item, count=1)
replacements_found = True
string = string.replace(f"__{match}__", replacement, 1)
elif '*' in keyword:
@@ -358,6 +359,7 @@ def extract_lora_values(string):
lbw = None
lbw_a = None
lbw_b = None
loader = None
if len(item) > 0:
lora = item[0]
@@ -376,6 +378,8 @@ def extract_lora_values(string):
lbw_b = safe_float(lbw_item[2:].strip())
elif lbw_item.strip() != '':
lbw = lbw_item
elif sub_item.startswith("LOADER="):
loader = sub_item[7:]
if a is None:
a = 1.0
@@ -383,7 +387,7 @@ def extract_lora_values(string):
b = a
if lora is not None and lora not in added:
result.append((lora, a, b, lbw, lbw_a, lbw_b))
result.append((lora, a, b, lbw, lbw_a, lbw_b, loader))
added.add(lora)
return result
@@ -407,6 +411,8 @@ def resolve_lora_name(lora_name_cache, name):
if x.endswith(name):
return x
return None
def process_with_loras(wildcard_opt, model, clip, clip_encoder=None, seed=None, processed=None):
"""
@@ -427,7 +433,7 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None, seed=None,
loras = extract_lora_values(pass1)
pass2 = remove_lora_tags(pass1)
for lora_name, model_weight, clip_weight, lbw, lbw_a, lbw_b in loras:
for lora_name, model_weight, clip_weight, lbw, lbw_a, lbw_b, loader in loras:
lora_name_ext = lora_name.split('.')
if ('.'+lora_name_ext[-1]) not in folder_paths.supported_pt_extensions:
lora_name = lora_name+".safetensors"
@@ -441,26 +447,36 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None, seed=None,
path = None
if path is not None:
print(f"LOAD LORA: {lora_name}: {model_weight}, {clip_weight}, LBW={lbw}, A={lbw_a}, B={lbw_b}")
logging.info(f"LOAD LORA: {lora_name}: {model_weight}, {clip_weight}, LBW={lbw}, A={lbw_a}, B={lbw_b}, LOADER={loader}")
def default_lora():
return nodes.LoraLoader().load_lora(model, clip, lora_name, model_weight, clip_weight)
if lbw is not None:
if 'LoraLoaderBlockWeight //Inspire' not in nodes.NODE_CLASS_MAPPINGS:
utils.try_install_custom_node(
'https://github.com/ltdrdata/ComfyUI-Inspire-Pack',
"To use 'LBW=' syntax in wildcards, 'Inspire Pack' extension is required.")
print(f"'LBW(Lora Block Weight)' is given, but the 'Inspire Pack' is not installed. The LBW= attribute is being ignored.")
model, clip = default_lora()
if loader is not None:
if loader == 'nunchaku':
if 'NunchakuFluxLoraLoader' not in nodes.NODE_CLASS_MAPPINGS:
logging.warning(f"To use `LOADER=nunchaku`, 'ComfyUI-nunchaku' is required. The LOADER= attribute is being ignored.")
cls = nodes.NODE_CLASS_MAPPINGS['NunchakuFluxLoraLoader']
model = cls().load_lora(model, lora_name, model_weight)[0]
else:
cls = nodes.NODE_CLASS_MAPPINGS['LoraLoaderBlockWeight //Inspire']
model, clip, _ = cls().doit(model, clip, lora_name, model_weight, clip_weight, False, 0, lbw_a, lbw_b, "", lbw)
logging.warning(f"LORA LOADER NOT FOUND: '{loader}'")
else:
model, clip = default_lora()
def default_lora():
return nodes.LoraLoader().load_lora(model, clip, lora_name, model_weight, clip_weight)
if lbw is not None:
if 'LoraLoaderBlockWeight //Inspire' not in nodes.NODE_CLASS_MAPPINGS:
utils.try_install_custom_node(
'https://github.com/ltdrdata/ComfyUI-Inspire-Pack',
"To use 'LBW=' syntax in wildcards, 'Inspire Pack' extension is required.")
logging.warning(f"'LBW(Lora Block Weight)' is given, but the 'Inspire Pack' is not installed. The LBW= attribute is being ignored.")
model, clip = default_lora()
else:
cls = nodes.NODE_CLASS_MAPPINGS['LoraLoaderBlockWeight //Inspire']
model, clip, _ = cls().doit(model, clip, lora_name, model_weight, clip_weight, False, 0, lbw_a, lbw_b, "", lbw)
else:
model, clip = default_lora()
else:
print(f"LORA NOT FOUND: {orig_lora_name}")
logging.warning(f"LORA NOT FOUND: {orig_lora_name}")
pass3 = [x.strip() for x in pass2.split("BREAK")]
pass3 = [x for x in pass3 if x != '']
@@ -469,7 +485,7 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None, seed=None,
pass3 = ['']
pass3_str = [f'[{x}]' for x in pass3]
print(f"CLIP: {str.join(' + ', pass3_str)}")
logging.info(f"CLIP: {str.join(' + ', pass3_str)}")
result = None
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui-impact-pack"
description = "This node pack offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler."
version = "8.13"
version = "8.17.1"
license = { file = "LICENSE.txt" }
dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"]
+1 -1
View File
@@ -4,6 +4,6 @@ piexif
transformers
opencv-python-headless
scipy>=1.11.4
numpy<2
numpy
dill
matplotlib