Compare commits

...
Author SHA1 Message Date
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
Dr.Lt.Data bfcb8674b3 feat: Select Nth Item (Any list)
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/971
2025-04-24 18:00:37 +09:00
Dr.Lt.Data 839e5a9f90 fixed: ImpactSwitch - slot was not shrinked when disconnecting
fixed: ImpactSwitch - invalid upper bounding of the select value

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/972
2025-04-24 12:38:35 +09:00
Dr.Lt.Data 5a2adda580 fixed: impact switch - compatibility patch with new front
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/964
2025-04-22 02:06:08 +09:00
Dr.Lt.Data d05882a9e0 refactor: remove useless legacy code 2025-04-22 01:33:58 +09:00
Dr.Lt.Data d900939861 feat: Impact Sampler - support OSS scheduler 2025-04-13 10:24:35 +09:00
Jaquan cd2696f6fd fix #946 InversedSwitch(Any) was not append outputs after first connect (#956)
InversedSwitch(Any) not increasing number of outputs after connecting first output  (in )
# 953  #946
In the latest ComfyUI_frontend version, output is not appended as expected
2025-04-12 19:01:00 +09:00
Dr.Lt.Data 0b1ac0f1c5 bump version to v8.10 2025-03-24 00:06:42 +09:00
chutchatut 216d7fd60c Added sort=None to SEGS order filter (#944)
* added pick first N SEGs node

* remove take first N segs node and update segs order filter to add order=None

* add comments

* update for readibility

* format code

* remove match statement
2025-03-24 00:06:06 +09:00
chutchatut 28cd2f70b2 Update README.md (#943) 2025-03-21 19:06:24 +09:00
Dr.Lt.Data 2708eba825 bump version v8.9 2025-03-20 21:36:25 +09:00
chutchatut c19ab92172 add intersection and non max suppression SEGS filter (#940) 2025-03-20 21:21:15 +09:00
Robin Huangandsnomiao 6e3d07277b chore(publish): update workflow for node publishing with conditional execution and permissions (#935)
Co-authored-by: snomiao <snomiao+comfy-pr@gmail.com>
2025-03-17 00:19:33 +09:00
Dr.Lt.Data 782c6f439e fixed: controlbridge - better error message
- mute/bypass behavior cannot be used in api mode

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/933
2025-03-12 18:10:42 +09:00
Dr.Lt.Data 0e3e6a193a improved: SAM Loader - don't add 'ESAM' if 'ComfyUI-YoloWorld-EfficientSAM' is not installed 2025-03-04 22:44:31 +09:00
Dr.Lt.Data 798776838e remove sample_error_enhancer 2025-03-04 12:43:03 +09:00
Dr.Lt.Data 66493d8cb4 formatting.. 2025-03-02 16:56:59 +09:00
Dr.Lt.Data b4fd0834e0 fixed: crash when loading api json
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/919
2025-03-02 16:54:16 +09:00
Dr.Lt.Data 808b0dedf0 update README.md 2025-02-23 10:03:04 +09:00
Dr.Lt.Data c6056b132d add example workflow 2025-02-15 11:04:03 +09:00
Dr.Lt.Data 1ae7cae2df version marker 2025-02-02 15:05:41 +09:00
izmp ccb6285548 Fixed several issues related to number handling and wildcard processing (#896) 2025-02-02 15:04:57 +09:00
Dr.Lt.Data 092310bc8f refactor: impact_sampling 2025-01-31 21:01:03 +09:00
Dr.Lt.Data 5c530eb32e fixed: wildcards - cannot edit populated_text on 'fixed' mode
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/898
2025-01-30 16:55:01 +09:00
Dr.Lt.Data e35bc23fd1 add locales partly.
added: more descriptions
added: locales/ko
2025-01-30 16:49:23 +09:00
Dr.Lt.Data 869ac6fd1f version marker 2025-01-28 12:21:26 +09:00
Dijkstra cb168d64ab feat: allow wildcard file to use the adjusted probabilities feature (#891) 2025-01-28 12:16:10 +09:00
Dr.Lt.Data a89e9e01a6 fixed: sam editor - cannot load sam model properly when sams directory is specified manually.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/895
2025-01-28 06:35:51 +09:00
Dr.Lt.Data e70b4df9b5 fixed: reproduce mode is reflected to the saved metadata but it wans't 2025-01-27 11:05:12 +09:00
Dr.Lt.Data af1ef7e441 feat: wildcards nodes - reproduce mode is added.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/882

fixed: js crash
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/886#issuecomment-2613922083

removed: combo bool migration script
2025-01-27 10:55:47 +09:00
Dr.Lt.Data d8738eee2f hotfix: front - robustness fix
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/886#issuecomment-2600716281
2025-01-19 18:08:59 +09:00
Dr.Lt.Data c397c68ca3 version marker 2025-01-19 03:17:25 +09:00
Alex Butler 0e0722ec08 Add tiled vae encoding/decoding toggle to detailer nodes (#883)
* detailers: support optional tiled vae encoding & decoding

* Remove start encoding/decoding logging
2025-01-19 03:16:56 +09:00
Dr.Lt.Data 70d0540895 improved: tooltips 2025-01-14 00:47:27 +09:00
Dr.Lt.Data 7330577a0f version marker 2025-01-10 00:49:38 +09:00
Symbiomatrix b1d760291f Dummy shortcircuit. (#880) 2025-01-10 00:49:06 +09:00
Dr.Lt.Data 12e838a320 improved: refresh wildcard
Now refresh feature is moved to menu item.
`Edit > Impact: Refresh Wildcard`
2025-01-06 22:59:33 +09:00
Dr.Lt.Data 8e8621df49 update .gitignore 2024-12-30 02:32:46 +09:00
Dr.Lt.Data cdb7b4d3b0 fix: compatibility patch for VAEEncodeTiled's overlap
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/863#issuecomment-2560861500
2024-12-25 16:14:51 +09:00
Dr.Lt.Data 21eecb0c03 fix: install script - folder_paths error 2024-12-22 18:40:09 +09:00
Dr.Lt.Data 9402ecf4f9 refactor: use ControlNetApplyAdvanced instead of legacy ControlNetApply 2024-12-21 18:21:58 +09:00
Dr.Lt.Data c21b361e2a fix: VAEEncodeTiled - overlap compatibility patch
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/863
2024-12-21 17:41:24 +09:00
Dr.Lt.Data 8f04714145 fixed: inversed_switch - If the select is pointing to an out-of-range output, remove the input connection instead of the output.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/851#issuecomment-2543353847
2024-12-19 23:29:34 +09:00
Dr.Lt.Data a311f9278d fixed: sam detector - invalid position
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/853
2024-12-19 23:06:49 +09:00
Dr.Lt.Data 0ec21f1a4b version marker 2024-12-19 22:03:11 +09:00
Andrés Zsögön 40a3df3acd Added Mask Rect Area and Mask Rect Area (Advanced) nodes (#861)
Added nodes for simple rectangular masks of arbitrary size and position with built-in preview canvas. Closes issue #856.
2024-12-19 22:02:40 +09:00
Dr.Lt.Data 9ba92862c4 update README.md 2024-12-17 11:03:02 +09:00
Dr.Lt.Data 2c2e148205 update README.md 2024-12-17 10:58:17 +09:00
Dr.Lt.Data ff9c30787c Robustly remove legacy subpack directories. 2024-12-11 23:24:00 +09:00
Dr.Lt.Data 64f709741a The Impact Subpack must now be installed separately. 2024-12-11 21:56:33 +09:00
Dr.Lt.Data 455e993354 Merge branch 'Main' into refactor/subpack 2024-12-11 21:54:51 +09:00
Dr.Lt.Data ce23d436fc improve: switch - disconnect output connection instead of input connection if select_on_prompt 2024-12-11 05:25:01 +09:00
Dr.Lt.Data 5f630466fb fixed: block if empty slot is selected and select_on_prompt
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/846
2024-12-11 03:36:12 +09:00
Dr.Lt.Data 81045cc845 fixed: remove from lazy input if empty slot is selected.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/846
2024-12-11 03:25:29 +09:00
Ikko Eltociear Ashimine 20f2cac6f0 docs: update README.md (#844)
minor fix
2024-12-06 05:10:09 +09:00
Dr.Lt.Data 348c3dcb6b improve: PreviewBridgeLatent - add Latent2RGB-LTXV
improve: LatentSender - add multiple latent formats
2024-12-01 02:02:05 +09:00
Dr.Lt.Data 1ec3037613 FIXED: wildcard, lora selector bug
from https://github.com/ltdrdata/ComfyUI-Impact-Pack/pull/838/files)

FIXED: SAM Detector
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/836
2024-11-30 22:48:00 +09:00
filtered d4136bc955 Prefer widget.callback over stack trace check (#838)
* Prefer widget.callback over stack trace check

Update to LiteGraph included a rename of a local function.  This value was being checked to prevent unwanted value sets.

This has been replaced with widget callback(), which for combo boxes is always called when a value is clicked, regardless of any change.

* nit

* Fix error caused by bug in litegraph

Known issue w/widget.callback and setter/getter.
2024-11-30 21:47:22 +09:00
Dr.Lt.Data c9b3aecd1a fix: install script exception handling for torchvision.download_url 2024-11-26 18:33:27 +09:00
Dr.Lt.Data a2bb6f7c91 feat: LTXV[default] scheduler is added 2024-11-26 01:16:57 +09:00
Dr.Lt.Data e1e408d8c9 improve: add description to wildcard nodes 2024-11-22 21:37:23 +09:00
Jonathan Nogueira f7686845c6 Update core.py - save mask when edited (#817)
* Update core.py - save mask when edited

In order to facilitate the `restore_mask` functionality better, one needs to save the mask to the cache when the mask is edited.

* Update core.py - add missing unsqueeze(0)

mask cache was missing unsqueeze function, giving the resulting mask the wrong size.
2024-11-22 13:41:55 +09:00
FennelFetish 37f465d4a9 Fixes call to make_3d_mask in MakeMaskBatch (#823) 2024-11-22 13:28:50 +09:00
Dr.Lt.Data 48b4254e81 fix: compatibility patch for updated ComfyUI
https://github.com/comfyanonymous/ComfyUI/commit/156a28786be9ba6352061090096462bfb1b485bb

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/821
2024-11-20 09:46:42 +09:00
Dr.Lt.Data 24de5a846b hotfix: failing of ultralytics due to security policy 2024-11-09 19:46:33 +09:00
Dr.Lt.Data 6fe85ed6bf version marker 2024-11-08 22:02:22 +09:00
H.D.Tài 216f4660e1 Typecast possible float values in SEG_ELT to int (#811) 2024-11-08 22:01:28 +09:00
Dr.Lt.Data 314b676cc3 FIX: compatibility patch latest ComfyUI update.
https://github.com/comfyanonymous/ComfyUI/commit/b49616f9511c57c8d54c4032e305d72352ac4ff5

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/812
2024-11-08 21:58:06 +09:00
Dr.Lt.Data cd89590a7d FEAT: List Bridge node is added. 2024-11-07 23:33:59 +09:00
Vedat Baday dc70f40eff perf: cache pip installed packages (#803) 2024-11-03 04:13:37 +09:00
Dr.Lt.Data 66bf101341 Merge branch 'Main' into refactor/subpack 2024-11-02 05:39:28 +09:00
Vedat Baday 825296c3e0 fix: install manual (#794) 2024-11-02 05:39:08 +09:00
Dr.Lt.Data 5c0535942a Merge branch 'Main' into refactor/subpack 2024-11-01 02:31:49 +09:00
Dr.Lt.Data bf0e86a10d FIXED: ImageListToImageBatch - make sure output is not list when item size is less than 2
https://github.com/comfyanonymous/ComfyUI/issues/5039
2024-11-01 02:28:15 +09:00
Dr.Lt.Data 6be257254e Separate Impact Pack and Impact Subpack 2024-11-01 02:25:14 +09:00
Dr.Lt.Data 727295b52e fix: wildcard bugs
- cannot remove comment
- cannot populate <single-wildcard-pattern> if `{count$$<single-wildcard-pattern>}`

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/789

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/788
2024-10-24 00:25:57 +09:00
Dr.Lt.Data 6c23f7691d fixed: wildcard - invalid regex syntax
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/790
2024-10-22 12:20:59 +09:00
Dr.Lt.Data 6248f31402 improved: lora in wildcard - Allows omitting leading zero when specifying floating-point values less than 1.
e.g. .1 instead of 0.1

https://github.com/ltdrdata/ComfyUI-Inspire-Pack/issues/178
2024-10-21 12:44:00 +09:00
Dr.Lt.Data cb0b652703 REFACTOR: GeneralSwitch - better implementation 2024-10-16 21:42:41 +09:00
Dr.Lt.Data 9c4fa5fb27 FIXED: switch any <-> inverse switch disconnection issue
https://github.com/ltdrdata/ComfyUI-extension-tutorials/issues/58#issuecomment-2415330114
2024-10-16 20:27:33 +09:00
Dr.Lt.Data 759b4d0dc9 fix: invalid version check code
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/782
2024-10-15 23:34:25 +09:00
Dr.Lt.Data a65fd56b7f add install-manual.py for manual installation
https://github.com/ltdrdata/ComfyUI-Impact-Pack/pull/773
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/689
2024-10-13 19:28:20 +09:00
Dr.Lt.Data 47d981eca2 feat: preview bridge - restore_mask feature is added 2024-10-13 19:23:51 +09:00
Dr.Lt.Data b2f382776f FIXED: ControlNetApplySEGS - compatiblity patch
- https://github.com/ltdrdata/ComfyUI/commit/7a415f47a90915d755767c29e9f5bcc157fedefe
- Make existing ControlNetApply (SEGS) deprecated
- Rename `ControlNetApplyAdvanced (SEGS)` to `ControlNetApply (SEGS)`

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/764
2024-10-02 01:43:33 +09:00
Dr.Lt.Data 0e4e439d39 feat: SEGS Merge 2024-09-27 23:17:35 +09:00
RyuukeisyouandRyuukeisyou 18d25a29a0 add ImpactBoolean (#759)
Co-authored-by: Ryuukeisyou <jingxiang.liu@live.com>
2024-09-27 22:55:46 +09:00
Dr.Lt.Data 2b724e5ed2 version marker 2024-09-25 11:03:07 +09:00
Dr.Lt.Data 96cc242f78 FIXED: torch.load issue
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/754
2024-09-25 10:39:14 +09:00
Dr.Lt.Data 28267da071 fix: new front compatibilty issue
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/755
2024-09-25 09:36:06 +09:00
Dr.Lt.Data 86d7f73981 update README and version marker 2024-09-24 22:02:32 +09:00
mijuku233 f428182ddf feat: MakeAnyList and AnyPipeToBasic (#753) 2024-09-24 21:53:23 +09:00
Dr.Lt.Data a43dae373e remove useless code 2024-09-24 01:47:46 +09:00
Dr.Lt.Data 1087f2ee06 Restored the default model download feature during the installation step. 2024-09-22 07:30:15 +09:00
Dr.Lt.Data 841a245cd4 FIXED: Anomaly where cropped becomes identical to cropped_refined
https://github.com/ltdrdata/ComfyUI-extension-tutorials/issues/28
2024-09-22 07:18:39 +09:00
Dr.Lt.Data aecc925630 update README 2024-09-21 19:32:05 +09:00
Dr.Lt.Data b5abf19a1b remove automatic installation feature 2024-09-21 19:27:06 +09:00
Dr.Lt.Data 9775a98f03 improve: IterativeUpscale - support noise_mask
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/746
2024-09-21 01:33:32 +09:00
Kristian Helk ac288bbcb9 Make a small fix in wildcard replacement (#743)
Fixes wildcard replacement when multiple wildcards are separated by a symbol that is included in the regex (e.g. "__custom_wildcard__-__another_custom_wildcard__")
2024-09-16 12:43:38 +09:00
Dr.Lt.Data fd69570977 Modified: SEGSPicker - it would be better if it were not an output node.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/742
2024-09-14 15:19:10 +09:00
Dr.Lt.Data 1c488eec11 fix: apply differential diffusion before move to device.
This patch will prevent OOM from DifferentialDiffusion
2024-09-13 18:20:09 +09:00
Dr.Lt.Data c3eed0936f update dependency: dill
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/735
2024-09-08 11:32:20 +09:00
Dr.Lt.Data 44adbbe282 feat: ImpactMakeMaskList, ImpactMakeMaskBatch, MasksToMaskList, MaskListToMaskBatch, ImpactFlattenMask 2024-09-07 00:48:25 +09:00
Dr.Lt.Data 940ad41b15 fix: invalid patch on last commit 2024-09-05 02:12:11 +09:00
Dr.Lt.Data e848a9dfb7 fix: potential null-deref on impact-wildcard.js
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/731
2024-09-05 00:08:29 +09:00
Dr.Lt.Data 76653016dc change default value of PreviewBridge
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/728
2024-09-04 12:42:50 +09:00
Dr.Lt.Data 9ed160123d fix: controlbridge - invalid auto typing of output 2024-09-04 08:21:34 +09:00
Dr.Lt.Data ffbd4ae116 improve: detailer - do not apply differential diffusion if already applied.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/724#issuecomment-2324129835
2024-09-03 02:08:01 +09:00
Dr.Lt.Data 5757c533e6 add description little more 2024-09-01 02:45:53 +09:00
Dr.Lt.Data e99e9aaec2 feat: PreviewBridge - add block mode based on PR2666 2024-08-30 13:21:45 +09:00
Dr.Lt.Data 690b0a0f61 fix: PreviewDetailerHookProvider - invalid behavior since PR2666 2024-08-29 03:38:19 +09:00
Dr.Lt.Data 84fbb3fa2e fix: proper error message for outdated ComfyUI instead of import fail
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/722
2024-08-27 01:03:12 +09:00
Dr.Lt.Data b2c7e06e79 improve: ControlBridge - add Stop behavior
improve: Detailer - new detailer wildcard syntax
- [ASC-SIZE], [DSC-SIZE], [SKIP], [STOP]
2024-08-27 00:06:00 +09:00
Dr.Lt.Data a500aff476 fix: RegionalPrompt compatibility with FLUX.1 2024-08-25 16:25:30 +09:00
Dr.Lt.Data dddac08e28 improve: little more tooltips for switchs 2024-08-24 12:45:54 +09:00
Dr.Lt.Data e325d1b208 improve: InversedSwitch - now use ExecutionBlocker for unselected output 2024-08-24 12:05:40 +09:00
mijuku233 0a7dbe45a9 Add lazy evaluation for impactconditionbranch nodes (#716) 2024-08-24 10:34:12 +09:00
Dr.Lt.Data c43488361f WIP: tooltip 2024-08-22 01:44:22 +09:00
Dr.Lt.Data b065ce88ca feat: PreviewBridgeLatent supports TAEF1 2024-08-17 13:45:59 +09:00
Dr.Lt.Data 06b428ec8c feature: dynamic switch based on Execution Model Inversion. 2024-08-16 11:53:02 +09:00
Dr.Lt.Data 94f30ef317 fix: resize_mask - robust processing 2024-08-15 16:16:53 +09:00
Dr.Lt.Data 6c45402b2b feat: Execution Order Controller node is added.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/699
2024-08-09 21:37:56 +09:00
Dr.Lt.Data 3423c10225 improve: PreviewBridge - embedding workflow 2024-08-09 00:32:43 +09:00
Dr.Lt.Data 182ff558be fix: PixelTiledKSampleUpscalerProvider - provide proper error message for missing custom node 'BlenderNeko/ComfyUI_TiledKSampler'
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/693
2024-08-08 22:50:13 +09:00
Dr.Lt.Data 44c48f11ef fix: make compatible with Advanced ControlNet as possible
https://github.com/ltdrdata/ComfyUI-Inspire-Pack/issues/137
2024-08-07 01:56:51 +09:00
Dr.Lt.Data adb2a97646 fix: impact_sampling - potential device mismatch 2024-08-06 00:05:03 +09:00
Dr.Lt.Data b2d12d04b4 fix: sample_with_custom_noise - move intermediate latent to intermediate device. 2024-08-04 15:53:52 +09:00
haohaocreatesandsnomiao 26c7419553 chore(licence-update): Update PyProject Toml - License (#686)
Co-authored-by: snomiao <snomiao+comfy-pr@gmail.com>
2024-08-03 15:08:44 +09:00
Dr.Lt.Data d4d6c1b02f Supports FLUX.1 model in Impact KSampler, Detailers, PreviewBridgeLatent.
Bump version to 6.0
2024-08-03 03:30:59 +09:00
Dr.Lt.Data f8723ab7ac fix: TwoAdvancedSamplersForMask - doesn't work properly 2024-08-03 02:46:38 +09:00
Dr.Lt.Data 83ad10cdde improve: wildcard normalization
- now replace blank to '-'
2024-07-28 00:56:06 +09:00
Dr.Lt.Data 573ddd8755 fix: robust patch - potential wildcard encoding mismatch error
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/680
2024-07-28 00:42:24 +09:00
Dr.Lt.Data eb5e1372f8 version marker 2024-07-25 01:06:42 +09:00
bymyself c6c68dd194 Add custom wildcards path fallback (#677) 2024-07-25 01:05:38 +09:00
Dr.Lt.Data 2c19c3e6e1 Prevention of crashes due to controlnet mismatch between negative and positive when applying advanced controlnet
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/673
2024-07-22 06:29:19 +09:00
Chenlei Hu 5ef20ec0bd Fix input type on ImpactLogger (#674) 2024-07-19 07:04:01 +09:00
Dr.Lt.Data ab17f88869 fix: Patch to allow fixing the js path as ComfyUI-Impact-Pack instead of the custom_node name to support the upcoming new ComfyUI-Manager 2024-07-06 18:24:58 +09:00
Dr.Lt.Data caa1abbe7b support wildcard refresh in refresh button in new style menu 2024-07-04 00:20:23 +09:00
Dr.Lt.Data 001ddb5493 enhance error message about ComfyUI-YOLO node conflict 2024-07-04 00:03:29 +09:00
Dr.Lt.Data 0841520de1 remove problematic legacy code in install script 2024-07-03 23:35:54 +09:00
Dr.Lt.Data 948a280ce9 remove problematic legacy code in install script 2024-07-03 23:34:10 +09:00
Dr.Lt.Data 33d879a0cf modified: MASK to SEGS - Instead of converting the mask tensor to binary, clip it
This patch allows blurred mask.

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/665
2024-07-03 22:49:26 +09:00
Dr.Lt.Data 1ec5fc0b35 feat: wildcard - support count$$<single wildcards> pattern.
https://github.com/ltdrdata/ComfyUI-extension-tutorials/issues/50#event-13380404576
2024-07-03 22:32:01 +09:00
Dr.Lt.Data a26fe487ef fix: potential ui bug fix
- prevent freezing ui
2024-07-03 00:10:25 +09:00
Dr.Lt.Data 6000e1efa8 update README.md
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/662
2024-07-02 21:18:40 +09:00
Dr.Lt.Data d70befa7d3 update README.md
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/661
2024-07-02 21:12:08 +09:00
Dr.Lt.Data 2f61135d00 Display proper error message.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/657
2024-06-30 07:42:29 +09:00
Marat Zhanabekovandmaratz cbc8384a9e Fix Dont combine option for SEGS Detector for AnimateDiff (#656)
Co-authored-by: maratz <maratz@ngrow.ai>
2024-06-28 22:51:30 +09:00
Dr.Lt.Data f7df6e4445 allows installing into abnormal custom node directory
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/2#issuecomment-2191875544
2024-06-28 00:01:56 +09:00
Dr.Lt.Data a823d244fa version marker 2024-06-26 22:11:07 +09:00
Dr.Lt.Data 660549bbe6 fix: ControlBridge is re-executed always.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/653
2024-06-26 22:10:34 +09:00
Dr.Lt.Data 39e4f8ec33 refactor: reformatting and remove useless code 2024-06-26 21:38:42 +09:00
tombearx 363784c1d5 Fix: Wildcard Prompt from String node (#654)
* Update util_nodes.py

Fix: when no exclude_tags or restrict_to_tags.

* Update Make Tile SEGS

Update crop_factor step to 0.01
2024-06-26 21:31:06 +09:00
Dr.Lt.Data 2e9b51640f fix: browser frozen when ultralytics dir isn't exists.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/648#issuecomment-2188453263
2024-06-25 21:15:29 +09:00
Dr.Lt.Data 4ecce73bf7 feat: MaskDetailer - add bbox_fill and contour_fill.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/650
2024-06-24 21:57:41 +09:00
Dr.Lt.Data c4e20ec6ec improve: add tooltips into nodes in special_samplers 2024-06-23 23:11:54 +09:00
Dr.Lt.Data 07ba46e2bb feat: wildcard - support k: v pair
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/642
2024-06-23 10:00:41 +09:00
Dr.Lt.Data 3ca75549f5 improve: PixelKSampleUpscalerProvider - support tile_cnet_opt 2024-06-22 11:42:06 +09:00
Dr.Lt.Data aad58a99bf refactor: ImpactSchedulerAdapter
- rename widget name ays_scheduler -> extra_scheduler

feat: support GITS[coeff=1.0] scheduler
2024-06-21 08:01:37 +09:00
Dr.Lt.Data 7e47e28884 hotfix: numpy 2 breaks everything!!!! 2024-06-21 07:06:23 +09:00
Dr.Lt.Data 5aaa07cf36 feat: PixelTiledKSampleUpscalerProvider - support tile_cnet_strength
fix: `scheduler_func_opt` invalid arg name fix

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/647#issuecomment-2181586345
2024-06-21 06:41:49 +09:00
Dr.Lt.Data e254cbed49 feat: support GITSScheduler 2024-06-20 23:53:56 +09:00
Dr.Lt.Data 0da935061b fix: PixelKSampleUpscaler - AYS doesn't work properly 2024-06-19 23:51:00 +09:00
Dr.Lt.Data ea33b09360 feat: HF_TransformersClassifierProvider - allows local path
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/645
2024-06-19 01:40:45 +09:00
Dr.Lt.Data 4f081637fa update README 2024-06-19 01:00:33 +09:00
Dr.Lt.Data fba01332e8 improve: SEGS_Classify - provides detected_labels 2024-06-19 00:35:59 +09:00
Dr.Lt.Data 1e5f5d5e0a fix: impact_sampling - ignoring batch_index
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/643
2024-06-18 00:47:09 +09:00
Dr.Lt.Data 8cfc91b05a fix: PreviewBridgeLatent
- ignore latent mismatch if vae_opt is given
2024-06-16 15:23:34 +09:00
Dr.Lt.Data f7205868a1 version marker 2024-06-16 13:30:38 +09:00
Dr.Lt.Data 4c07bb2593 improve: better interpolation for latent2rgb 2024-06-16 13:29:33 +09:00
Dr.Lt.Data 258eb30428 feat: PreviewBridgeLatent - various latent
- SD3, StableCascade, Playground, SD-X4
fix: PreviewBridgeLatent - latent2rgb
- quality issue
2024-06-16 13:22:34 +09:00
Dr.Lt.Data 885ca3d377 fix: sample_with_custom_noise - sd3 compatibility 2024-06-13 01:21:26 +09:00
Dr.Lt.Data 23b7e8fed8 modified: default guide_size to the 512
- 256/384 is too small for SD3
2024-06-13 00:34:50 +09:00
Dr.Lt.Data c5fe4b7d45 feat: ImpactCount_Elts_in_SEGS
improve: ImpactLogger
2024-06-11 23:21:54 +09:00
Dr.Lt.Data 04f9f072b0 fix: segm padding issue
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/606#issuecomment-2157594212

refactor: MAX_RESOLUTION - use nodes.MAX_RESOLUTION instead of impact.config.MAX_RESOLUTION
2024-06-10 19:03:07 +09:00
Dr.Lt.Data 9f8d97c876 Apply ComfyUI patch.
https://github.com/comfyanonymous/ComfyUI/commit/6cd8ffc465ed363b078249b081ea3f975e77cf15
2024-06-08 16:15:50 +09:00
Dr.Lt.Data e350da28e2 fix: segs_scale - crash if batch mask is given
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/628#issuecomment-2153720821
2024-06-07 12:52:23 +09:00
traugdor 6b9d862573 Update core.py (#629)
Fallback to tiled approach to decode refined image. This is done if the normal VAE Decode method fails, usually to video memory memory issues on devices with lower video memory or less-efficient usage of video memory.

This improvement will make this node more accessible to a wider range of devices.
2024-06-07 08:56:16 +09:00
Dr.Lt.Data 69ded9cb40 rename display name of bitwise operations to pixelwise operations
Initially, it was designed with bitwise operations in mind, but it ultimately became a pixelwise operation. Therefore, I determined that the original name is not appropriate.

However, to ensure backward compatibility, the node ID will remain the same, and only the display name will be changed.
2024-06-06 16:13:18 +09:00
Dr.Lt.Data 07a5e13bdb modified: All detailer - default value of force_inpaint is True now.
Reflecting that many users use Detailer for inpainting rather than detailing.
2024-06-06 01:17:08 +09:00
Dr.Lt.Data 0bb54b2656 feat: SEGS Filter - support confidence 2024-06-04 22:46:12 +09:00
Dr.Lt.Data 8f7d07bb23 feat: RegionalPrompt - support variation seed
refactor: convert several doit method to staticmethod
2024-06-02 17:12:25 +09:00
Dr.Lt.Data b1b68426f9 feat: Detailer for AD - supports noise_mask_feather and DifferentialDiffusion
fix: SEGSPaste - device mismatch error on --gpu-only
2024-06-01 01:47:18 +09:00
Jin Liu c31b22537b fix: typo (#619) 2024-05-31 23:55:31 +09:00
Dr.Lt.Data 6060e41bb5 fix: segs_scale_match - robust patch
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/617
2024-05-31 00:05:39 +09:00
Dr.Lt.Data e4e40ecc2d feat: wildcard refresh
refactor: move wildcard load function to wildcards.py

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/492
2024-05-30 23:21:34 +09:00
Dr.Lt.Data ebaf54e2b6 feat: MaskToSEGS for AnimateDiff allows batch mask
refactor: change some doit functions to staticmethod
update README.md

https://github.com/ltdrdata/ComfyUI-extension-tutorials/issues/44
2024-05-30 00:50:58 +09:00
Dr.Lt.Data 0985a88707 feat: wildcard - support # commenting-out 2024-05-28 22:36:17 +09:00
Dr.Lt.Data feeee53247 update README 2024-05-27 11:39:27 +09:00
Dr.Lt.Data 8acae9fe86 update pyproject.toml 2024-05-23 00:47:07 +09:00
haohaocreates a8601cd5ea chore(publish): Add Github Action for Publishing to Comfy Registry (#608) 2024-05-23 00:39:02 +09:00
haohaocreates 1b609cd7fa chore(pyproject): Add pyproject.toml for Custom Node Registry (#607) 2024-05-23 00:38:10 +09:00
Dr.Lt.Data 42199d4843 fix: Preview Bridge (latent)
- crash if masked latent is passed
2024-05-20 23:58:16 +09:00
Dr.Lt.Data 7560f8dcf0 fix: Bitwise (SEGS & SEGS), Bitwise (SEGS - SEGS) wasn't operate properly 2024-05-19 02:18:25 +09:00
Dr.Lt.Data fe662edd94 refactor: ImpactControlBridge
use interrupt_processing instead of raise exception.
2024-05-17 01:27:20 +09:00
Dr.Lt.Data ecab0d5ac5 better install script 2024-05-15 18:39:07 +09:00
Dr.Lt.Data 544a0b9df2 fix: tensor device error
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/597
2024-05-14 13:17:46 +09:00
Dr.Lt.Data a7076b3968 improve: ImageReceiver - supports ImpactInt for converted link_id
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/578
2024-05-11 18:02:08 +09:00
Dr.Lt.Data c01f94ad62 update README.md 2024-05-11 17:19:37 +09:00
Dr.Lt.Data c03945ba37 fix: ImpactWildcardProcessor - doesn't work properly for converted populated_text
fix: ImpactWildcardEncode
- doesn't reflect seed for converted `populated_text`
- doesn't show populated text for converted `populated_text`

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/579#issuecomment-2100681809
2024-05-09 02:01:59 +09:00
Dr.Lt.Data feb07e550c fix: invalid patch 2024-05-08 21:22:11 +09:00
Dr.Lt.Data 6f09cdf99d version marker
refactor: impact sampling
2024-05-08 20:56:04 +09:00
Brodie Ferguson 72f33b3122 fix: impact_sampling - missing UniPC sampler (#592) 2024-05-08 20:55:47 +09:00
DukeSniperandLutz Lehmann c16066ecd5 Escape backslashes (#590)
Co-authored-by: Lutz Lehmann <lutz.lehmann@tasso.net>
2024-05-07 23:14:40 +09:00
Dr.Lt.Data ce18987181 version marker
https://github.com/ltdrdata/ComfyUI-Impact-Pack/pull/586
2024-05-05 10:45:16 +09:00
Brent Liu 1b6c2b7a8e Updated Wildcard.py to fix my previous pull request on Wildcard-Multi-Select-Quantifier. (#586)
* Update wildcards.py

Fixed a big issue of the new wildcard multi-select-pattern quantifier that replaced all sub-subsequent occurrences of the wildcard keyword with the 1st occurrence's keyword, utterly destroying the prompt's identity.

* Update wildcards.py

Further fix for when using "wildcard" character '*' in __wildcard/*__ in combination wildcard-multi-select-pattern-quantifier.  Previous patch breaks the "wildcard" in wildcard scenario and wouldn't work properly.
2024-05-05 10:39:29 +09:00
Dr.Lt.Data 6ba58ccfae fix: DetailerHook made empty noise.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/584
2024-05-04 18:59:52 +09:00
Dr.Lt.Data e1ea93d1b7 version marker
https://github.com/ltdrdata/ComfyUI-Impact-Pack/pull/583
2024-05-04 13:05:48 +09:00
Brent Liu 86d8dda618 Update wildcards.py (#583)
Added pre-processing code for quantifying __wildcards__ to be used with $$ multi_select_pattern functionality, before Impact process works its way.

`{2$$, $$5#__wildcards__}`
turns into
`{2$$, $$__wildcards__|__wildcards__|__wildcards__|__wildcards__|__wildcards__}`
2024-05-04 12:58:47 +09:00
Dr.Lt.Data 790adc3e8a feat: expand AYS scheduler support for other nodes
PixelKSampleUpscaler
PixelKSampleUpscalerProvider
PixelKSampleUpscalerProviderPipe
SEGSDetailer
SEGSUpscaler

fix: KSamplerAdvancedBasicPipe - add_noise, return_with_leftover_noise doesn't working

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/582
2024-05-04 12:35:28 +09:00
Dr.Lt.Data 48d9ce7528 refactor: impact_sampling
allows callback
2024-05-03 01:07:27 +09:00
Dr.Lt.Data c7798e08c1 version marker
update README.md
2024-05-01 19:12:46 +09:00
JonasandJonas Krauss b67669d049 node to create wildcard label prompt from string list (#536)
* node to create wildcard label prompt from string list

* use `is` for checking on None value

* add StringListToString node

* remove `list` from name of wildcard creation node

---------

Co-authored-by: Jonas Krauss <jonas.krauss@stockpulse.de>
2024-05-01 19:05:32 +09:00
Dr.Lt.Data 80e5958355 fix: invalid variation noise logic
- To compensate for the loss of Gaussian noise characteristics due to interpolation between two noises, scale.
2024-05-01 18:31:48 +09:00
Dr.Lt.Data 23d8b83944 feat: VariationNoiseDetailerHookProvider 2024-04-30 23:54:35 +09:00
Dr.Lt.Data f4c20eb424 fix: Switch nodes - crash on api mode
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/566#issuecomment-2082512262
2024-04-29 20:54:24 +09:00
Dr.Lt.Data a1f245b956 update README.md 2024-04-29 20:20:36 +09:00
Dr.Lt.Data 910bc0e4d1 feat: ImpactSchedulerAdapter
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/576
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/568
2024-04-29 20:16:03 +09:00
Dr.Lt.Data 281b4dfd29 fix: impact_sampling - missing ddim sampler
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/576
2024-04-29 17:36:09 +09:00
Dr.Lt.Data 21c737581a fix: impact_sampling bugfix
- The issue where '3m_sde' and '3m_sde_gpu' were operating as '2m_sde' and '2m_sde_gpu'.
2024-04-29 01:01:04 +09:00
Dr.Lt.Data 95b1600c17 hotfix: impact_sampling
OMG...

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/573
2024-04-28 11:52:21 +09:00
Dr.Lt.Data d47c85be07 refactor: remove legacy codes
add: print error message for outdated ComfyUI
2024-04-28 11:23:10 +09:00
Dr.Lt.Data a783e1f2a4 fix: sam_editor_model setting doesn't work
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/570
2024-04-27 16:50:49 +09:00
Dr.Lt.Data f7532d8bce feat: ImpactKSamplers supports AYS scheduler
refactor: impact_sampling
- add: sample_with_custom_noise
- expose separated_sample api through RegionalSampler
2024-04-27 16:39:07 +09:00
narukaze132andDr.Lt.Data f283125334 Add the ability to use a Tile ControlNet for iterative tiled upscaling (#404)
* Added the ability to use a Tile ControlNet for iterative upscaling

* Fixed standard upscaling

* Made CNet use preprocessed image instead of original

---------

Co-authored-by: Dr.Lt.Data <dr.lt.data@gmail.com>
2024-04-27 01:13:49 +09:00
Dr.Lt.Data 0e15af09e1 fix: switch node crash in api
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/566
2024-04-27 00:22:56 +09:00
Dr.Lt.Data 1b4b8305b4 feat: Detailer - support AYS scheduler
AlignYourStepScheduler!
2024-04-25 21:48:27 +09:00
Daniel LewisandDaniel Lewis 93a451de5b Fixed base path for img.src to allow ComfyUI in subfolders (#537)
* Fixed base path for img.src to allow ImpactPack to work when ComfyUI isn't at /

* Update impact-image-util.js

---------

Co-authored-by: Daniel Lewis <daniel.lewis@plailabs.com>
2024-04-23 00:59:47 +09:00
Dr.Lt.Data 1fc6fcad31 fix: missing response
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/557

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/554
2024-04-20 16:36:25 +09:00
Dr.Lt.Data 971c4a37aa fix: SegmDetectorCombined, BboxDetectorCombined - return empty mask instead of None 2024-04-15 11:06:20 +09:00
Dr.Lt.Data 8ffc4efcd6 fix: better compatibility with other nodes.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/547
2024-04-09 21:16:29 +09:00
Dr.Lt.Data 4c44a8ab75 fix: show proper warning message instead of crash
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/548

(commit message fix)
2024-04-09 11:10:13 +09:00
Dr.Lt.Data f09312b33a fix: show proper warning message instead of crash
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/470#issuecomment-2043954600
2024-04-09 11:05:50 +09:00
Dr.Lt.Data 8aac412b0a fix: detailer - inconsistency on overlapping area 2024-04-09 01:02:58 +09:00
Dr.Lt.Data ae5ab7559a fix: unsampler patch again... 2024-04-09 00:08:42 +09:00
Dr.Lt.Data de8cb9087f fix: unsampler compatibility 2024-04-08 13:33:57 +09:00
Hamish Friedlander 7c2456d219 Fix Picker (SEGS) mutating underlying mask (#543) 2024-04-06 22:26:47 +09:00
Dr.Lt.Data cc0afe7ab3 SAMLoader - ESAM supports
required PR `https://github.com/ZHO-ZHO-ZHO/ComfyUI-YoloWorld-EfficientSAM/pull/32`

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/541
2024-04-06 13:05:51 +09:00
Dr.Lt.Data b63b689bc4 fix: SubtractMaskForEach - invalid logic
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/540
2024-04-06 09:58:56 +09:00
Dr.Lt.Data 8d4e244165 fix: impact_sampling - compatibility patch
https://github.com/comfyanonymous/ComfyUI/commit/1a0486bb96fb1ff10f4ea3c0d62eb815e9630585
2024-04-06 09:56:02 +09:00
Dr.Lt.Data a1694e5b04 feat: support conditioning mask for other detailers 2024-04-06 00:57:14 +09:00
Hamish Friedlander 8656245caa Fix conditioning masks not being cropped in SEGSDetailer (#539) 2024-04-06 00:55:25 +09:00
Dr.Lt.Data 15ea57ff30 improve: support conditioning set mask in detailer 2024-04-06 00:52:52 +09:00
Hamish Friedlander 24a6234ce4 Fix conditioning masks not being cropped in SEGSDetailer 2024-04-05 19:40:22 +13:00
Dr.Lt.Data 03fcf1084f fix: detector (combined) - support 3-dim mask instead of 2-dim mask
https://github.com/ltdrdata/ComfyUI-Inspire-Pack/issues/94
2024-04-03 00:25:11 +09:00
Dr.Lt.Data 0b002ef3fb improve: IPAdapterWrapper - support neg_image 2024-03-24 17:14:37 +09:00
Dr.Lt.Data c429ebe5eb fix: support updated ComfyUI IPAdapter Plus 2024-03-24 17:00:40 +09:00
Dr.Lt.Data be034b2df7 update README 2024-03-20 17:34:13 +09:00
6f7d55cc86 improve: IterativeLatentUpscale - use geometric progression for upscale steps (#523)
* improve: IterativeLatentUpscale - use geometric progression for upscale steps

This is a small change to IterativeLatentUpscale that makes the sequence of the upscale steps to use geometric progression rather than arithmetic. This has the advantage that every step scales the intermediate image by the same factor.

* feat: Iterative Upscale - support `step_mode`

---------

Co-authored-by: Dr.Lt.Data <dr.lt.data@gmail.com>
Co-authored-by: Dr.Lt.Data <128333288+ltdrdata@users.noreply.github.com>
2024-03-19 23:10:10 +09:00
Dr.Lt.Data 6b50c18336 improve: SEGSUpscaler apply DifferentialDiffusion by noise_mask_feather 2024-03-17 12:56:29 +09:00
Dr.Lt.Data 92f0182fd6 fix: Upscaler (SEGS) - compensate resolution 2024-03-13 10:32:58 +09:00
Dr.Lt.Data e1570e7679 fix: robust tensor_paste
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/512
2024-03-13 09:41:56 +09:00
Dr.Lt.Data e374bd304a fix: different device error on SEGSPaste 2024-03-11 22:18:42 +09:00
Dr.Lt.Data 949fa3aedb update requirements 2024-03-08 13:25:08 +09:00
Dr.Lt.Data 2fa03f734a fix: missing is_tiled
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/508
2024-03-08 13:21:21 +09:00
Dr.Lt.Data 47741a0067 version marker 2024-03-05 10:46:30 +09:00
Dr.Lt.Data 2fba14e1de fix: previewbridge failure
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/503#issuecomment-1977753647
2024-03-05 10:46:02 +09:00
Dr.Lt.Data ac80b49c3f improve: Detailer - apply DifferentialDiffusion if noise_feather > 0
improve: MakeTileSEGS - prevent redundant tile
fix: MakeTileSEGS - invalid output when empty filter_in_segs_opt is connected.
2024-03-05 02:06:51 +09:00
Dr.Lt.Data 9c1d4eec46 feat: SEGSUpscaler
fix: Make Tile SEGS - Ensuring the overlap of an irregular mask.

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/497
https://github.com/ltdrdata/ComfyUI-Inspire-Pack/issues/79
2024-03-04 01:59:58 +09:00
Dr.Lt.Data d0cb63472a feat: ImpactFrom_SEG_ELT_bbox, ImpactFrom_SEG_ELT_crop_region
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/496
2024-03-03 00:46:02 +09:00
Dr.Lt.Data e984384068 fix: Make Tile SEGS - overlap size fix
https://github.com/ltdrdata/ComfyUI-Inspire-Pack/issues/79
2024-03-03 00:13:33 +09:00
Dr.Lt.Data 8b35530cfb fix: missing doit_ipadapter in ControlNetAdvancedWrapper
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/491
2024-02-29 09:32:12 +09:00
Dr.Lt.Data 5f73ac55c0 feat: ImpactIPAdapterApplySEGS 2024-02-23 01:00:09 +09:00
mijuku233 33f3af04a8 Improve ImpactQueueTriggerCountdown (#479) 2024-02-22 12:54:16 +09:00
Dr.Lt.Data 88d3db9495 improve: SimpleDetectorForEach - better support for YOLO-World 2024-02-21 15:40:29 +09:00
Dr.Lt.Data 7c740a8fb0 version marker
update README
2024-02-20 01:01:41 +09:00
JonasandJonas Krauss b4ce4d9a76 New node SEGSLabelAssign for manually assigning labels to SEGS + fix two bugs (#475)
* fix missing import of os module

* fix variable assignment when choosing wildcard label

* add SEGSLabelAssign node allowing to manually assign labels to segs

* distinguish between LAB and other wmodes

---------

Co-authored-by: Jonas Krauss <jonas.krauss@stockpulse.de>
2024-02-20 00:58:07 +09:00
Dr.Lt.Data dd6d0de968 fix: compatibility patch with recent ComfyUI.
https://github.com/ltdrdata/ComfyUI/commit/3b2e579926d5cf8231de0e68e79096d1ee8091f2
2024-02-19 20:20:25 +09:00
Dr.Lt.Data 43bca637c2 fix: Detailer for AD - robust patch
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/472
2024-02-13 21:36:24 +09:00
Dr.Lt.Data 6aee0aa442 README.md update 2024-02-13 08:01:04 +09:00
Dr.Lt.Data 8a4050ed2a improve: KSamplerAdvancedProvider - add 'sigma_factor' 2024-02-13 00:04:29 +09:00
Dr.Lt.Data dd6ecaf9c2 fix: pk_hook - invalid simple schedule
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/471#issuecomment-1937870178
2024-02-12 15:38:05 +09:00
Dr.Lt.Data 43bb20dc9d feat: StepsScheduleHookProvider
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/471#issuecomment-1937397697

fix: SimpleDetailerDenoiseSchedulerHook never reach to target

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/442

refactor: move ConcatConditionings category to ImpactPack/Util

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/467
2024-02-11 20:08:09 +09:00
Dr.Lt.Data 585787bfa7 feat: ControlNetApply (SEGS) - support ComfyUI-ControlNet-Advanced for AnimateDiff 2024-02-05 22:46:13 +09:00
Dr.Lt.Data 84d7fb848a update README.md 2024-02-05 12:53:39 +09:00
Dr.Lt.Data 3fdede4e90 refactor 2024-02-04 03:01:12 +09:00
Dr.Lt.Data 747afc4980 fix: ControlNetApply (SEGS) - control_image for animatediff_nodes doesn't work properly
feat: Detailer for AD - support cnet_images output
2024-02-04 03:00:43 +09:00
Dr.Lt.Data 042a6fd793 feat: KSamplerAdvancedProvider: support custom sampler, optionally 2024-02-04 01:10:20 +09:00
Dr.Lt.Data f66da62702 refactor: provide modified cloning of REGIONAL_PROMPT, KSamplerAdvancedWrapper
This patch allows `RemoveControlNetFromRegionalPrompts` for Inspire Pack
2024-02-04 00:30:58 +09:00
Dr.Lt.Data ec2040bd78 feat: ControlNetApplySEGS - supports AnimateDiff
refactor: invalid var names
2024-02-03 13:28:09 +09:00
Dr.Lt.Data 606882362e fix: robust GaussianBlurMask
support WAS 4d mask

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/462
2024-02-02 23:07:45 +09:00
Dr.Lt.Data 27ec34e3ed Fix: post_paste was missing in DetailerHookCombine 2024-02-01 17:06:08 +09:00
Dr.Lt.Data 8afba2e654 feat: PreviewDetailerHook 2024-02-01 16:54:18 +09:00
Dr.Lt.Data a823348392 update README.md 2024-01-31 17:24:42 +09:00
mijuku233 f4b7dba485 feat: ImpactLogicalOperators (#461)
* Update __init__.py

* feat: ImpactLogicalOperators
2024-01-31 13:12:16 +09:00
mijuku233andDr.Lt.Data 2ffd006bec new node: ImpactIfNone (#460)
* Update __init__.py

* Update logics.py

---------

Co-authored-by: Dr.Lt.Data <dr.lt.data@gmail.com>
2024-01-30 17:02:45 +09:00
mijuku233 b798ed027f New node: ImpactConvertDataType (#457)
* Add a new node: Convert_data_type.py

* Update __init__.py

* Update logics.py

* Update __init__.py
2024-01-30 15:35:01 +09:00
Dr.Lt.Data cc7812bcfe Merge branch 'improve/regional-sampler' into Main 2024-01-27 18:33:57 +09:00
Dr.Lt.Data decff0d4c6 improve: Regional Sampler - use impact_sampling instead of KSamplerAdvanced.
- Handle the _sde sampler in a more appropriate manner.
2024-01-27 18:24:10 +09:00
Dr.Lt.Data b095838302 feat: DetailerForEachPipeForAnimateDiff
modify: change display name of SEGSDetailerForAnimateDiff
2024-01-27 12:27:48 +09:00
Dr.Lt.Data 0a9327bb5d version marker 2024-01-26 23:54:59 +09:00
Zixaphir 8028d3b6c0 Add "ControlnetApplyAdvanced (SEGS)" node (#452)
"ImpactControlNetApplyAdvancedSEGS"

Add a wrapper node for ControlNetApplyAdvanced that allows
editting the start and end percentages and also applies to the
negative conditioning on top of the positive (untangling these
features would require implementing a separate controlnet path,
as ComfyUI's "ControlNetAdvanced" implementation requires both.)
2024-01-26 23:53:43 +09:00
Dr.Lt.Data f83c907cba improve: UltralyticsDetectorProvider - For models where segm is not provided, X mark is provided indicating that it cannot be used. 2024-01-26 13:33:37 +09:00
Dr.Lt.Data c486e65f0f fix: feathering crash if too small crop_region
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/451
2024-01-25 21:16:12 +09:00
mijuku233 9e7c4ea155 Improve ImpactQueueTriggerCountdown (#450)
* Update logics.py

Improve ImpactQueueTriggerCountdown

* Update logics.py
2024-01-25 20:59:12 +09:00
Dr.Lt.Data 1af01b1ae3 fix: robust SafeToGPU
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/427
2024-01-24 14:26:15 +09:00
Dr.Lt.Data 170c9c35d9 improve: alpha preview for SEGS Picker. 2024-01-24 13:43:20 +09:00
Dr.Lt.Data eb4801e823 feat: ImpactConditionalBranchSelMode 2024-01-24 12:44:14 +09:00
mijuku233 b2dd2ce794 Update logics.py (#446)
Cancel cond forceInput
2024-01-23 12:49:03 +09:00
Dr.Lt.Data 837ac5c1f7 improve: wildcard supports seed (rgthree)
related issue:
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/432
2024-01-15 14:44:31 +09:00
Dr.Lt.Data 6183c00b95 fix: invalid empty mask size
related issue:
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/433
2024-01-15 14:22:12 +09:00
Dr.Lt.Data b9eb80f599 fix: wildcard cannot load lora if extension is not omitted. 2024-01-15 14:14:23 +09:00
Dr.Lt.Data 50bd68238f fix: SAMDetector (combined) return mask which is same size with image even if empty mask 2024-01-13 20:43:42 +09:00
Dr.Lt.Data b15c583917 improve: MakeTileSEGS - irregular mask feature 2024-01-13 20:05:07 +09:00
Dr.Lt.Data 6bc63ef415 feat: detailer - noise_mask_feather 2024-01-13 15:17:54 +09:00
Dr.Lt.Data 31b3db7b16 fix: don't move to device when VRAM isn't enough 2024-01-13 13:56:43 +09:00
Dr.Lt.Data c5c5e5c22d improve: detailer wildcard - random seed support [SEP:R] 2024-01-13 13:44:26 +09:00
Dr.Lt.Data 3f89d6efb5 feat: detailer wildcard - seed support
- syntax [SEP:seed]
2024-01-13 13:26:24 +09:00
Dr.Lt.Data 8fc1073204 fix: detailer - error when noise_mask is disabled 2024-01-13 01:02:28 +09:00
Dr.Lt.Data 1f0b2fb79c improve: SAMLoader - consider smart memory management 2024-01-12 22:28:35 +09:00
Dr.Lt.Data 7f7646b72f feat: ControlNetApply (SEGS) - support control_image
feat: SEGSPreviewCnet
2024-01-12 16:26:01 +09:00
Dr.Lt.Data 3169234402 Revert "refactor: inpaint_model -> inpainting_model"
This reverts commit 01e35166d2.
2024-01-12 10:15:51 +09:00
Dr.Lt.Data 01e35166d2 refactor: inpaint_model -> inpainting_model 2024-01-12 09:47:02 +09:00
Dr.Lt.Data 5ef704c022 detailer supports InpaintModelConditioning node instead of PR (https://github.com/comfyanonymous/ComfyUI/pull/2501)
https://github.com/comfyanonymous/ComfyUI/commit/10f2609fdd2231faf40346df11372601385b6cbb
2024-01-11 19:36:58 +09:00
Dr.Lt.Data 0df8f5809d fix: prevent defineProperty overriding 2024-01-11 13:50:19 +09:00
Dr.Lt.Data 1e445bcacf feat: Detailer - support inpaint_model
support to this PR.
https://github.com/comfyanonymous/ComfyUI/pull/2501
2024-01-10 00:26:26 +09:00
Dr.Lt.Data 5e225e9d5a fix: MakeTileSEGS - invalid calculation on optimization 2024-01-08 00:52:03 +09:00
Dr.Lt.Data f1c3afdbdb optimize: MakeTileSEGS
- make optimal SEGS when filter_in_segs_opt is given
2024-01-07 23:49:59 +09:00
Dr.Lt.Data 510d4355f2 fix: SEGSPreview - sideeffect to cropped_mask in SEGS 2024-01-07 15:47:30 +09:00
Dr.Lt.Data 3c25e6f52e fix: MakeTileSEGS - invalid calculation 2024-01-07 15:20:44 +09:00
Dr.Lt.Data c6a5a0f98a feat: MakeTileSEGS - filter_in_segs_opt, filter_out_segs_opt
improve: detailer - set different seed for each SEGS
2024-01-07 13:12:28 +09:00
Dr.Lt.Data f6ec3a8164 feat: ImpactMakeTileSEGS, RemoveImageFromSEGS
improve: SEGSPreview - add min_alpha

improve: grow default guide_size and max_size

refactor: move several nodes from impact_pack.py -> util_nodes.py
2024-01-06 16:59:48 +09:00
Dr.Lt.Data 4aec82be08 fix: SAMLoader - Confirmed that VRAM is releasing properly in auto mode. 2024-01-04 01:21:28 +09:00
Dr.Lt.Data 265738e71f fix: cnet segs application cannot be stacked 2024-01-02 23:47:29 +09:00
Dr.Lt.Data 77b0cd21b6 refactor: use cm_global instead of sys.CM_api
feat: register extension information
2024-01-02 17:08:05 +09:00
Dr.Lt.Data 5ff4b3f0bc fix: install.py - install GitPython before install subpack 2024-01-01 10:06:46 +09:00
JonasandJonas Krauss c4839a8b91 add check for type of cropped image to support controlnet segs workflow (#407)
Co-authored-by: Jonas Krauss <jonas.krauss@stockpulse.de>
2023-12-31 01:07:19 +09:00
Dr.Lt.Data ddaedfe836 feat: ImpactWildcardEncode - support BREAK syntax 2023-12-30 00:58:08 +09:00
kamnxtandDr.Lt.Data 36fbaab563 Improve wildcards and fix a bug (#319)
* Improve wildcards and fix a bug

This commit fixes two issues with wildcards:

- Using a single count value no longer worked due to .strip() being
  called on a None value from matching the upper range,
  when using a wildcard like {2$$a|b|c},
  while {2-2$$a|b|c} worked fine. Added a check to fix that.

- Choosing options was implemented in an odd way. The code would choose
  up to `count` values, then put them in a `set` to prevent duplicates.
  Then retry up to 10 times to get values in case the correct count
  wasn't reached. This had a few issues: {2$$a|a|b} would always choose
  "b a", always in this order! However, {2$$1::a|a|b}, which should be
  identical, gives either "a a" or "b a"!

- When the number of items to choose was more than the count of items to
  choose, the items would be returned in the original order, meaning for
  example {3-6$$a|b|c|d} returns "a b c d" way more often than it
  should. This is changed to shuffle the order when choosing all the
  items.

- As NumPy already had a way to choose N items without replacement and
  with weights, the code has been changed to use a NumPy Generator. This
  means previous seeds are no longer compatible, but also means we don't
  re-seed the built-in Python `random` generator.

- I have also added a "ImpactWildcardUnprocessed" node, in order to have
  a multiline text input node that doesn't do ComfyUI's built in
  wildcard replacement, so it's possible to put a prompt in a separate
  node from the WildcardProcessor (or have a few ones to connect
  manually). Due to the way things are processed both on the JS side and
  the backend side, sadly concatenating text for use in wildcards
  doesn't work yet.

* fix: random_gen.shuffle is side-effect function

* version marker

---------

Co-authored-by: Dr.Lt.Data <dr.lt.data@gmail.com>
2023-12-29 23:41:04 +09:00
narukaze132 c5cdfa2f40 Added ImpactLatentInfo (#402) 2023-12-29 07:40:13 +09:00
Dr.Lt.Data 9d22e7e55c fix: mask_to_segs - side effect of combined+bbox fill 2023-12-28 22:14:48 +09:00
Dr.Lt.Data 4667ba1a8a fix: mask_to_segs - bbox_fill doesn't work when combined mode 2023-12-28 22:07:12 +09:00
Dr.Lt.Data 7c96cdb771 feat: SEGSOrderedFilterDetailerHook, SEGSRangeFilterDetailerHook, SEGSLabelFilterDetailerHook
refactor: hooks, hook_nodes, defs
2023-12-27 19:50:56 +09:00
Dr.Lt.Data 7f70bf0eee fix: return 3d mask as possible
- MaskComposite requires 3d mask
2023-12-26 23:47:42 +09:00
Dr.Lt.Data da9d04d9a2 feat: Detailer wildcards - [CONCAT] support 2023-12-26 20:32:53 +09:00
TheDudeFromCI f705e47a0f Update requirements.txt (#399) 2023-12-26 00:52:27 +09:00
Dr.Lt.Data a9440d63ec refactor: class name 2023-12-26 00:38:47 +09:00
Dr.Lt.Data f942627b12 fix: SEGSPreview - crash 2023-12-25 23:10:37 +09:00
Dr.Lt.Data 2555beb5cd feat: Detailer For AnimateDiff - support batch mask 2023-12-25 23:06:36 +09:00
Dr.Lt.Data c4ef168cc7 improve: display proper error message for detectors 2023-12-25 00:40:04 +09:00
Dr.Lt.Data 4d39c93122 Merge remote-tracking branch 'origin/Main' into Main 2023-12-24 10:17:54 +09:00
Dr.Lt.Data bcab35a3b1 fix: non pipe FaceDetailer - invalid cropped_enhanced_alpha 2023-12-24 10:17:45 +09:00
narukaze132 0742390991 Fixed LoRA model/clip strength in wildcards (#396) 2023-12-24 09:44:02 +09:00
Dr.Lt.Data 1e6e0f92bf improve: support for installing custom nodes based on the ComfyUI-Manager dependency. 2023-12-23 16:47:22 +09:00
Dr.Lt.Data fe5a8cbf8a improve: better error message
refactor: rename IterativeLatentUpscaler
2023-12-23 13:53:45 +09:00
Dr.Lt.Data 75799f5834 improve: FaceDetailer allows image batch input 2023-12-23 13:16:12 +09:00
Dr.Lt.Data d1aaa4a097 feat: Gaussian Blur Mask, Dilate Mask (SEGS), Gaussian Blur Mask (SEGS)
refactor: feather/gaussian blur
fix: Mask To SEGS - invalid conversion when mask is donut shape
fix: SEGS Paste/SEGS Preview - proper alpha handling
2023-12-23 11:43:38 +09:00
Dr.Lt.Data 483594f6be Included code patch for Unsampler of ComfyUI_Noise in the current codebase. 2023-12-22 22:27:53 +09:00
Dr.Lt.Data 14c26fce8d fix: sam editor crash by 0246 extension 2023-12-22 22:12:38 +09:00
Dr.Lt.Data e089110464 fix: feather issue
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/387
2023-12-21 00:21:12 +09:00
Dr.Lt.Data d511080f04 fix: rollback upscale method to LANCZOS based on PIL 2023-12-20 22:34:52 +09:00
Dr.Lt.Data 3a28fe18c6 improve: better ImpactInversedSwitch 2023-12-20 21:40:45 +09:00
Dr.Lt.Data b02d288635 improve: better handling of ControlBridge
- now support `Reroute (rghtree)`
2023-12-20 21:16:13 +09:00
Dr.Lt.Data 2f5ff69b9e improve: better handling of ControlBridge 2023-12-20 21:12:06 +09:00
Dr.Lt.Data f88a4cfb06 fix: legacy code scale_tensor
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/385
2023-12-20 09:06:59 +09:00
Dr.Lt.Data e118f7b6af optimize: import pipeline ondemand
fix: force cpu device for `tensor_paste`
- prevent device mismatch error
2023-12-19 22:58:41 +09:00
Dr.Lt.Data f3c44a568f fix: device mixing error when --gpu-only, --fp8... is used 2023-12-19 16:55:30 +09:00
Dr.Lt.Data 548b2a3542 update README 2023-12-19 16:38:36 +09:00
Dr.Lt.Data 4ab4f59dc0 improve: resize latent2rgb decoded image to pixelspace size 2023-12-19 14:26:42 +09:00
Dr.Lt.Data 3a9c326a6b improve: PreviewBridgeLatent allows vae_opt input
fix: doesn't work in PreviewBridgeLatent
fix: PreviewBridge, PreviewBridgeLatent doesn't work under specific situation
2023-12-19 14:06:14 +09:00
Dr.Lt.Data a6ace5b6a1 feat: PreviewBridgeLatent 2023-12-19 12:22:40 +09:00
Dr.Lt.Data 686c6e3ca7 feat: PreviewBridgeLatent 2023-12-19 12:21:34 +09:00
Dr.Lt.Data 5426b83d76 fid: invalid max value of target_denoise 2023-12-18 13:47:07 +09:00
Dr.Lt.Data 70196caa30 fix 1: When there are multiple faces, modify the MediaPipe FaceMesh to SEGS to detect multiple faces.
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/375

fix 2: even number of feather crash on tensor_feather_mask (again)

- Instead of simply forcing the thickness to be even, double it and make corrections.

https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/373
2023-12-18 02:48:13 +09:00
Dr.Lt.Data b3360478bc fix: even number of feather crash on tensor_feather_mask
https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/373
2023-12-16 22:23:30 +09:00
Dr.Lt.Data 757d07c789 improve: add vae output to 'IterativeUpscaler (latent)' 2023-12-16 01:42:57 +09:00
Dr.Lt.Data a820a88fb0 fix: prevent put alpha to seg_image 2023-12-16 01:10:32 +09:00
Han Jaeseung 6626cb6781 Remove PIL conversions to support float and uint16 (#371)
* removed intermediate pil conversions

* segs picker bug fix

* segs picker bug fix
2023-12-16 00:44:48 +09:00
Dr.Lt.Data aa47f5c7a1 improve: MaskDetailer - robust patch 2023-12-14 22:54:41 +09:00
Dr.Lt.Data 6e11efd7fe fix: restore ImpactFloat 2023-12-14 09:36:10 +09:00
Dr.Lt.Data 33c68fdd8e feat: Set Default Image for SEGS 2023-12-12 18:39:47 +09:00
Dr.Lt.Data b8a4febd51 fix: Concat Conditionings crash 2023-12-11 19:18:46 +09:00
Dr.Lt.Data 9d3f786e5e fix: Concat Conditionings 2023-12-11 12:16:28 +09:00
Dr.Lt.Data 3cefd47a32 feat: Concat Conditionings 2023-12-11 11:30:39 +09:00
Dr.Lt.Data b6aaa3994b fix: wildcards - crash when 'select' input is not given 2023-12-11 08:03:56 +09:00
Dr.Lt.Data d5598126c7 fix: remove dbg output 2023-12-11 00:42:26 +09:00
Dr.Lt.Data a733b506bd fix: Impact Wildcard's seeds doesn't allow ImpactInt input 2023-12-11 00:41:03 +09:00
Dr.Lt.Data 5d4cf09824 fix: robust mask handling
- prevent crash of 4d mask
2023-12-11 00:04:55 +09:00
Dr.Lt.Data c9a90186f8 fix: Detailer Hoook - compensate total_steps count if schedule isn't from_start 2023-12-10 17:14:51 +09:00
Dr.Lt.Data d3eab72eb8 fix: instant preview update for ImageReceiver when sending 2023-12-10 14:59:38 +09:00
Dr.Lt.Data b47cf8509b fix: MaskDetailer's cropped_enhanced_alpha was always empty. 2023-12-10 13:24:40 +09:00
Dr.Lt.Data bd29e99d63 feat: ImpactRemoteBoolean, ImpactRemoteInt 2023-12-10 12:40:20 +09:00
Dr.Lt.Data 9dfd983da9 improve: ControlBridge supports bypass control 2023-12-10 11:38:40 +09:00
Dr.Lt.Data f0d3bd9d29 improve: lazy type assign - ImpactCompare, ImpactConditionalBranch, ImpactControlBridge 2023-12-10 09:55:34 +09:00
Dr.Lt.Data 177ec41177 feat: UnsamplerHookProvider, UnsamplerDetailerHookProvider 2023-12-09 23:55:59 +09:00
Dr.Lt.Data a6b438f562 fix: injection noise pk_hook - self.from_start crash 2023-12-09 22:46:59 +09:00
Dr.Lt.Data 95d4193815 fix: wildcard crash if unresolved lora is used 2023-12-09 20:34:42 +09:00
Dr.Lt.Data 33b8e7ba93 fix: to_latent_image compatible issue with TAE 2023-12-09 18:40:57 +09:00
Dr.Lt.Data 784c4fb884 feat: DetailerHookCombine, DenoiseSchedulerDetailerHookProvider
improve: NoiseInjectionDetailerHookProvider - add schedule_for_cycle, end_strength
improve: SimpleDetector - add post_dilation
refactor: detailer hook
2023-12-09 18:00:59 +09:00
Dr.Lt.Data c1e26a7008 improve: add post_dilation to simple detector 2023-12-09 16:16:45 +09:00
Dr.Lt.Data ef8095b9af optimize: wildcard in detailer pipe nodes 2023-12-09 15:44:23 +09:00
Dr.Lt.Data cbe1acb91c refactor: expose wildcard api
improve: Fixing the combo box when selecting Lora.
2023-12-09 15:30:18 +09:00
Dr.Lt.Data a295802b35 optimize: background wildcard loading
refactor: use onprompt instead of js for wildcard processing
2023-12-09 14:34:26 +09:00
55 changed files with 18776 additions and 3035 deletions
+25
View File
@@ -0,0 +1,25 @@
name: Publish to Comfy registry
on:
workflow_dispatch:
push:
branches:
- main
paths:
- "pyproject.toml"
permissions:
issues: write
jobs:
publish-node:
name: Publish Custom Node to registry
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'ltdrdata' }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Publish Custom Node
uses: Comfy-Org/publish-node-action@v1
with:
## Add your own personal access token to your Github Repository secrets and reference it here.
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
+5 -1
View File
@@ -4,4 +4,8 @@ wildcards/**
.vscode/
.idea/
subpack
impact_subpack
impact_subpack
*.txt
*.yaml
!requirements.txt
!LICENSE.txt
+269 -190
View File
@@ -2,11 +2,21 @@
# ComfyUI-Impact-Pack
**Custom nodes pack for ComfyUI**
This custom node helps to conveniently enhance images through Detector, Detailer, Upscaler, Pipe, and more.
**Custom node pack for ComfyUI**
This node pack helps to conveniently enhance images through Detector, Detailer, Upscaler, Pipe, and more.
NOTE: The UltralyticsDetectorProvider node is not part of the ComfyUI-Impact-Pack. To use the UltralyticsDetectorProvider node, please install the ComfyUI-Impact-Subpack separately.
## NOTICE
## NOTICE
* V8.0: The `Impact Subpack` is no longer installed automatically. To use `UltralyticsDetectorProvider` nodes, please install the `Impact Subpack` separately.
* V7.6: Automatic installation is no longer supported. Please install using ComfyUI-Manager, or manually install requirements.txt and run install.py to complete the installation.
* V7.0: Supports Switch based on Execution Model Inversion.
* V6.0: Supports FLUX.1 model in Impact KSampler, Detailers, PreviewBridgeLatent
* V5.0: It is no longer compatible with versions of ComfyUI before 2024.04.08.
* V4.87.4: Update to a version of ComfyUI after 2024.04.08 for proper functionality.
* V4.85: Incompatible with the outdated **ComfyUI IPAdapter Plus**. (A version dated March 24th or later is required.)
* V4.77: Compatibility patch applied. Requires ComfyUI version (Oct. 8th) or later.
* V4.73.3: ControlNetApply (SEGS) supports AnimateDiff
* V4.20.1: Due to the feature update in `RegionalSampler`, the parameter order has changed, causing malfunctions in previously created `RegionalSamplers`. Please adjust the parameters accordingly.
* V4.12: `MASKS` is changed to `MASK`.
* V4.7.2 isn't compatible with old version of `ControlNet Auxiliary Preprocessor`. If you will use `MediaPipe FaceMesh to SEGS` update to latest version(Sep. 17th).
@@ -22,182 +32,268 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* With the addition of wildcard support in FaceDetailer, the structure of DETAILER_PIPE-related nodes and Detailer nodes has changed. There may be malfunctions when using the existing workflow.
## How To Install
### **Recommended**
* Install via [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager).
### **Manual**
* Navigate to `ComfyUI/custom_nodes` in your terminal (cmd).
* Clone the repository under the `custom_nodes` directory using the following command:
```
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui-impact-pack
cd comfyui-impact-pack
```
* Install dependencies in your Python environment.
* For Windows Portable, run the following command inside `ComfyUI\custom_nodes\comfyui-impact-pack`:
```
..\..\..\python_embeded\python.exe -m pip install -r requirements.txt
```
* If using venv or conda, activate your Python environment first, then run:
```
pip install -r requirements.txt
```
### Companion Pack
* If you need the `Ultralytics Detector Provider` to use various YOLO detection models, you should also install [ComfyUI-Impact-Subpack](https://github.com/ltdrdata/ComfyUI-Impact-Subpack).
## Custom Nodes
* [Detectors](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/detectors.md)
* SAMLoader - Loads the SAM model.
* UltralyticsDetectorProvider - Loads the Ultralystics model to provide SEGM_DETECTOR, BBOX_DETECTOR.
- Unlike `MMDetDetectorProvider`, for segm models, `BBOX_DETECTOR` is also provided.
- The various models available in UltralyticsDetectorProvider can be downloaded through **ComfyUI-Manager**.
* ONNXDetectorProvider - Loads the ONNX model to provide BBOX_DETECTOR.
* CLIPSegDetectorProvider - Wrapper for CLIPSeg to provide BBOX_DETECTOR.
### [Detector nodes](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/detectors.md)
* `SAMLoader` - Loads the SAM model.
* `ONNXDetectorProvider` - Loads the ONNX model to provide BBOX_DETECTOR.
* `CLIPSegDetectorProvider` - Wrapper for CLIPSeg to provide BBOX_DETECTOR.
* You need to install the ComfyUI-CLIPSeg node extension.
* SEGM Detector (combined) - Detects segmentation and returns a mask from the input image.
* BBOX Detector (combined) - Detects bounding boxes and returns a mask from the input image.
* SAMDetector (combined) - Utilizes the SAM technology to extract the segment at the location indicated by the input SEGS on the input image and outputs it as a unified mask.
* SAMDetector (Segmented) - It is similar to `SAMDetector (combined)`, but it separates and outputs the detected segments. Multiple segments can be found for the same detected area, and currently, a policy is in place to group them arbitrarily in sets of three. This aspect is expected to be improved in the future.
* `SEGM Detector (combined)` - Detects segmentation and returns a mask from the input image.
* `BBOX Detector (combined)` - Detects bounding boxes and returns a mask from the input image.
* `SAMDetector (combined)` - Utilizes the SAM technology to extract the segment at the location indicated by the input SEGS on the input image and outputs it as a unified mask.
* `SAMDetector (Segmented)` - It is similar to `SAMDetector (combined)`, but it separates and outputs the detected segments. Multiple segments can be found for the same detected area, and currently, a policy is in place to group them arbitrarily in sets of three. This aspect is expected to be improved in the future.
* As a result, it outputs the `combined_mask`, which is a unified mask, and `batch_masks`, which are multiple masks grouped together in batch form.
* While `batch_masks` may not be completely separated, it provides functionality to perform some level of segmentation.
* Simple Detector (SEGS) - Operating primarily with `BBOX_DETECTOR`, and with the additional provision of `SAM_MODEL` or `SEGM_DETECTOR`, this node internally generates improved SEGS through mask operations on both *bbox* and *silhouette*. It serves as a convenient tool to simplify a somewhat intricate workflow.
* `Simple Detector (SEGS)` - Operating primarily with `BBOX_DETECTOR`, and with the additional provision of `SAM_MODEL` or `SEGM_DETECTOR`, this node internally generates improved SEGS through mask operations on both *bbox* and *silhouette*. It serves as a convenient tool to simplify a somewhat intricate workflow.
* ControlNetApply (SEGS) - To apply ControlNet in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
### ControlNet, IPAdapter
* `ControlNetApply (SEGS)` - To apply ControlNet in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
* `segs_preprocessor` and `control_image` can be selectively applied. If a `control_image` is given, `segs_preprocessor` will be ignored.
* If set to `control_image`, you can preview the cropped cnet image through `SEGSPreview (CNET Image)`. Images generated by `segs_preprocessor` should be verified through the `cnet_images` output of each Detailer.
* The `segs_preprocessor` operates by applying preprocessing on-the-fly based on the cropped image during the detailing process, while `control_image` will be cropped and used as input to `ControlNetApply (SEGS)`.
* `ControlNetClear (SEGS)` - Clear applied ControlNet in SEGS
* `IPAdapterApply (SEGS)` - To apply IPAdapter in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
* Bitwise(SEGS & SEGS) - Performs a 'bitwise and' operation between two SEGS.
* Bitwise(SEGS - SEGS) - Subtracts one SEGS from another.
* Bitwise(SEGS & MASK) - Performs a bitwise AND operation between SEGS and MASK.
* Bitwise(SEGS & MASKS ForEach) - Performs a bitwise AND operation between SEGS and MASKS.
* Please note that this operation is performed with batches of MASKS, not just a single MASK.
* Bitwise(MASK & MASK) - Performs a 'bitwise and' operation between two masks.
* Bitwise(MASK - MASK) - Subtracts one mask from another.
* Bitwise(MASK + MASK) - Combine two masks.
* SEGM Detector (SEGS) - Detects segmentation and returns SEGS from the input image.
* BBOX Detector (SEGS) - Detects bounding boxes and returns SEGS from the input image.
### Mask operation
* `Pixelwise(SEGS & SEGS)` - Performs a 'pixelwise and' operation between two SEGS.
* `Pixelwise(SEGS - SEGS)` - Subtracts one SEGS from another.
* `Pixelwise(SEGS & MASK)` - Performs a pixelwise AND operation between SEGS and MASK.
* `Pixelwise(SEGS & MASKS ForEach)` - Performs a pixelwise AND operation between SEGS and MASKS.
* Please note that this operation is performed with batches of MASKS, not just a single MASK.
* `Pixelwise(MASK & MASK)` - Performs a 'pixelwise and' operation between two masks.
* `Pixelwise(MASK - MASK)` - Subtracts one mask from another.
* `Pixelwise(MASK + MASK)` - Combine two masks.
* `SEGM Detector (SEGS)` - Detects segmentation and returns SEGS from the input image.
* `BBOX Detector (SEGS)` - Detects bounding boxes and returns SEGS from the input image.
* `Dilate Mask` - Dilate Mask.
* Support erosion for negative value.
* `Gaussian Blur Mask` - Apply Gaussian Blur to Mask. You can utilize this for mask feathering.
* `Mask Rect Area` - Create a rectangular mask defined by percentages with preview canvas.
* `Mask Rect Area (Advanced)` - Create a rectangular mask defined by pixels and image size.
* Detailer
* Detailer (SEGS) - Refines the image based on SEGS.
* DetailerDebug (SEGS) - Refines the image based on SEGS. Additionally, it provides the ability to monitor the cropped image and the refined image of the cropped image.
### [Detailer nodes](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/detailers.md)
* `Detailer (SEGS)` - Refines the image based on SEGS.
* `DetailerDebug (SEGS)` - Refines the image based on SEGS. Additionally, it provides the ability to monitor the cropped image and the refined image of the cropped image.
* To prevent regeneration caused by the seed that does not change every time when using 'external_seed', please disable the 'seed random generate' option in the 'Detailer...' node.
* MASK to SEGS - Generates SEGS based on the mask.
* MASK to SEGS For AnimateDiff - Generates SEGS based on the mask for AnimateDiff.
* MediaPipe FaceMesh to SEGS - Separate each landmark from the mediapipe facemesh image to create labeled SEGS.
* `MASK to SEGS` - Generates SEGS based on the mask.
* `MASK to SEGS For AnimateDiff` - Generates SEGS based on the mask for AnimateDiff.
* When using a single mask, convert it to SEGS to apply it to the entire frame.
* When using a batch mask, the contour fill feature is disabled.
* `MediaPipe FaceMesh to SEGS` - Separate each landmark from the mediapipe facemesh image to create labeled SEGS.
* Usually, the size of images created through the MediaPipe facemesh preprocessor is downscaled. It resizes the MediaPipe facemesh image to the original size given as reference_image_opt for matching sizes during processing.
* ToBinaryMask - Separates the mask generated with alpha values between 0 and 255 into 0 and 255. The non-zero parts are always set to 255.
* Masks to Mask List - This node converts the MASKS in batch form to a list of individual masks.
* Mask List to Masks - This node converts the MASK list to MASK batch form.
* EmptySEGS - Provides an empty SEGS.
* MaskPainter - Provides a feature to draw masks.
* FaceDetailer - Easily detects faces and improves them.
* FaceDetailer (pipe) - Easily detects faces and improves them (for multipass).
* MaskDetailer (pipe) - This is a simple inpaint node that applies the Detailer to the mask area.
* `ToBinaryMask` - Separates the mask generated with alpha values between 0 and 255 into 0 and 255. The non-zero parts are always set to 255.
* `Masks to Mask List` - This node converts the MASKS in batch form to a list of individual masks.
* `Mask List to Masks` - This node converts the MASK list to MASK batch form.
* `EmptySEGS` - Provides an empty SEGS.
* `MaskPainter` - Provides a feature to draw masks.
* `FaceDetailer` - Easily detects faces and improves them.
* `FaceDetailer (pipe)` - Easily detects faces and improves them (for multipass).
* `MaskDetailer (pipe)` - This is a simple inpaint node that applies the Detailer to the mask area.
* `FromDetailer (SDXL/pipe), BasicPipe -> DetailerPipe (SDXL), Edit DetailerPipe (SDXL)` - These are pipe functions used in Detailer for utilizing the refiner model of SDXL.
* `FromDetailer (SDXL/pipe)`, `BasicPipe -> DetailerPipe (SDXL)`, `Edit DetailerPipe (SDXL)` - These are pipe functions used in Detailer for utilizing the refiner model of SDXL.
* `Any PIPE -> BasicPipe` - Convert the PIPE Value of other custom nodes that are not BASIC_PIPE but internally have the same structure as BASIC_PIPE to BASIC_PIPE. If an incompatible type is applied, it may cause runtime errors.
* SEGS Manipulation nodes
* SEGSDetailer - Performs detailed work on SEGS without pasting it back onto the original image.
* SEGSPaste - Pastes the results of SEGS onto the original image.
### SEGS Manipulation nodes
* `SEGSDetailer` - Performs detailed work on SEGS without pasting it back onto the original image.
* `SEGSPaste` - Pastes the results of SEGS onto the original image.
* If `ref_image_opt` is present, the images contained within SEGS are ignored. Instead, the image within `ref_image_opt` corresponding to the crop area of SEGS is taken and pasted. The size of the image in `ref_image_opt` should be the same as the original image size.
* This node can be used in conjunction with the processing results of AnimateDiff.
* SEGSPreview - Provides a preview of SEGS.
* `SEGSPreview` - Provides a preview of SEGS.
* This option is used to preview the improved image through `SEGSDetailer` before merging it into the original. Prior to going through ```SEGSDetailer```, SEGS only contains mask information without image information. If fallback_image_opt is connected to the original image, SEGS without image information will generate a preview using the original image. However, if SEGS already contains image information, fallback_image_opt will be ignored.
* This node can be used in conjunction with the processing results of AnimateDiff.
* SEGSToImageList - Convert SEGS To Image List
* SEGSToMaskList - Convert SEGS To Mask List
* SEGS Filter (label) - This node filters SEGS based on the label of the detected areas.
* SEGS Filter (ordered) - This node sorts SEGS based on size and position and retrieves SEGs within a certain range.
* SEGS Filter (range) - This node retrieves only SEGs from SEGS that have a size and position within a certain range.
* SEGSConcat - Concatenate segs1 and segs2. If source shape of segs1 and segs2 are different from segs2 will be ignored.
* Picker (SEGS) - Among the input SEGS, you can select a specific SEG through a dialog. If no SEG is selected, it outputs an empty SEGS. Increasing the batch_size of SEGSDetailer can be used for the purpose of selecting from the candidates.
* DecomposeSEGS - Decompose SEGS to allow for detailed manipulation.
* AssembleSEGS - Reassemble the decomposed SEGS.
* From SEG_ELT - Extract detailed information from SEG_ELT.
* Edit SEG_ELT - Modify some of the information in SEG_ELT.
* Dilate SEG_ELT - Dilate the mask of SEG_ELT.
* Dilate Mask - Dilate Mask.
* Support erosion for negative value.
* `SEGSPreview (CNET Image)` - Show images configured with `ControlNetApply (SEGS)` for debugging purposes.
* `SEGSToImageList` - Convert SEGS To Image List
* `SEGSToMaskList` - Convert SEGS To Mask List
* `SEGS Filter (label)` - This node filters SEGS based on the label of the detected areas.
* `SEGS Filter (ordered)` - This node sorts SEGS based on size and position and retrieves SEGs within a certain range.
* `SEGS Filter (range)` - This node retrieves only SEGs from SEGS that have a size and position within a certain range.
* `SEGS Filter (non max suppression)` - This node filters SEGS by removing those with high overlap based on the Intersection over Union (IoU) threshold, keeping only the most confident detections.
* `SEGS Filter (intersection)` - This node filters segs1, keeping only the SEGS that do not significantly overlap with any SEGS in segs2, based on the Intersection over Area (IoA) threshold.
* `SEGS Assign (label)` - Assign labels sequentially to SEGS. This node is useful when used with `[LAB]` of FaceDetailer.
* `SEGSConcat` - Concatenate segs1 and segs2. If source shape of segs1 and segs2 are different from segs2 will be ignored.
* `SEGS Merge` - SEGS contains multiple SEGs. SEGS Merge integrates several SEGs into a single merged SEG. The label is changed to `merged` and the confidence becomes the minimum confidence. The applied controlnet and cropped_image are removed.
* `Picker (SEGS)` - Among the input SEGS, you can select a specific SEG through a dialog. If no SEG is selected, it outputs an empty SEGS. Increasing the batch_size of SEGSDetailer can be used for the purpose of selecting from the candidates.
* `Set Default Image For SEGS` - Set a default image for SEGS. SEGS with images set this way do not need to have a fallback image set. When override is set to false, the original image is preserved.
* `Remove Image from SEGS` - Remove the image set for the SEGS that has been configured by "Set Default Image for SEGS" or SEGSDetailer. When the image for the SEGS is removed, the Detailer node will operate based on the currently processed image instead of the SEGS.
* `Make Tile SEGS` - [experimental] Create SEGS in the form of tiles from an image to facilitate experiments for Tiled Upscale using the Detailer.
* The `filter_in_segs_opt` and `filter_out_segs_opt` are optional inputs. If these inputs are provided, when creating the tiles, the mask for each tile is generated by overlapping with the mask of `filter_in_segs_opt` and excluding the overlap with the mask of `filter_out_segs_opt`. Tiles with an empty mask will not be created as SEGS.
* `Dilate Mask (SEGS)` - Dilate/Erosion Mask in SEGS
* `Gaussian Blur Mask (SEGS)` - Apply Gaussian Blur to Mask in SEGS
* `SEGS_ELT Manipulation` - experimental nodes
* `DecomposeSEGS` - Decompose SEGS to allow for detailed manipulation.
* `AssembleSEGS` - Reassemble the decomposed SEGS.
* `From SEG_ELT` - Extract detailed information from SEG_ELT.
* `Edit SEG_ELT` - Modify some of the information in SEG_ELT.
* `Dilate SEG_ELT` - Dilate the mask of SEG_ELT.
* `From SEG_ELT` bbox - Extract coordinate from bbox in SEG_ELT
* `From SEG_ELT` crop_region - Extract coordinate from crop_region in SEG_ELT
* `Count Elt in SEGS` - Number of Elts ins SEGS
* Pipe nodes
* ToDetailerPipe, FromDetailerPipe - These nodes are used to bundle multiple inputs used in the detailer, such as models and vae, ..., into a single DETAILER_PIPE or extract the elements that are bundled in the DETAILER_PIPE.
* ToBasicPipe, FromBasicPipe - These nodes are used to bundle model, clip, vae, positive conditioning, and negative conditioning into a single BASIC_PIPE, or extract each element from the BASIC_PIPE.
* EditBasicPipe, EditDetailerPipe - These nodes are used to replace some elements in BASIC_PIPE or DETAILER_PIPE.
* FromDetailerPipe_v2, FromBasicPipe_v2 - It has the same functionality as `FromDetailerPipe` and `FromBasicPipe`, but it has an additional output that directly exports the input pipe. It is useful when editing EditBasicPipe and EditDetailerPipe.
* Latent Scale (on Pixel Space) - This node converts latent to pixel space, upscales it, and then converts it back to latent.
### Pipe nodes
* `ToDetailerPipe`, `FromDetailerPipe` - These nodes are used to bundle multiple inputs used in the detailer, such as models and vae, ..., into a single DETAILER_PIPE or extract the elements that are bundled in the DETAILER_PIPE.
* `ToBasicPipe`, `FromBasicPipe` - These nodes are used to bundle model, clip, vae, positive conditioning, and negative conditioning into a single BASIC_PIPE, or extract each element from the BASIC_PIPE.
* `EditBasicPipe`, `EditDetailerPipe` - These nodes are used to replace some elements in BASIC_PIPE or DETAILER_PIPE.
* `FromDetailerPipe_v2`, `FromBasicPipe_v2` - It has the same functionality as `FromDetailerPipe` and `FromBasicPipe`, but it has an additional output that directly exports the input pipe. It is useful when editing EditBasicPipe and EditDetailerPipe.
* `Latent Scale (on Pixel Space)` - This node converts latent to pixel space, upscales it, and then converts it back to latent.
* If upscale_model_opt is provided, it uses the model to upscale the pixel and then downscales it using the interpolation method provided in scale_method to the target resolution.
* PixelKSampleUpscalerProvider - An upscaler is provided that converts latent to pixels using VAEDecode, performs upscaling, converts back to latent using VAEEncode, and then performs k-sampling. This upscaler can be attached to nodes such as 'Iterative Upscale' for use.
* Similar to 'Latent Scale (on Pixel Space)', if upscale_model_opt is provided, it performs pixel upscaling using the model.
* PixelTiledKSampleUpscalerProvider - It is similar to PixelKSampleUpscalerProvider, but it uses ComfyUI_TiledKSampler and Tiled VAE Decoder/Encoder to avoid GPU VRAM issues at high resolutions.
* `PixelKSampleUpscalerProvider` - An upscaler is provided that converts latent to pixels using VAEDecode, performs upscaling, converts back to latent using VAEEncode, and then performs k-sampling. This upscaler can be attached to nodes such as `Iterative Upscale` for use.
* Similar to `Latent Scale (on Pixel Space)`, if upscale_model_opt is provided, it performs pixel upscaling using the model.
* `PixelTiledKSampleUpscalerProvider` - It is similar to `PixelKSampleUpscalerProvider`, but it uses `ComfyUI_TiledKSampler` and Tiled VAE Decoder/Encoder to avoid GPU VRAM issues at high resolutions.
* You need to install the [BlenderNeko/ComfyUI_TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) node extension.
* DenoiseScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the denoise to target_denoise as the step progresses.
* CfgScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the cfg to target_cfg as the step progresses.
* PixelKSampleHookCombine - This is used to connect two PK_HOOKs. hook1 is executed first and then hook2 is executed.
* If you want to simultaneously change cfg and denoise, you can combine the PK_HOOKs of CfgScheduleHookProvider and PixelKSampleHookCombine.
* NoiseInjectionHookProvider - During each iteration of IterativeUpscale, noise is injected into the latent space while varying the strength according to a schedule.
* You need to install the [BlenderNeko/ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) node extension.
* The seed serves as the initial value required for generating noise, and it increments by 1 with each iteration as the process unfolds.
* The source determines the types of CPU noise and GPU noise to be configured.
* Currently, there is only a simple schedule available, where the strength of the noise varies from start_strength to end_strength during the progression of each iteration.
* NoiseInjectionDetailerHookProvider - The `detailer_hook` is a hook in the `Detailer` that injects noise during the processing of each SEGS.
* CoreMLDetailerHookProvider - CoreML supports only 512x512, 512x768, 768x512, 768x768 size sampling. CoreMLDetailerHookProvider precisely fixes the upscale of the crop_region to this size. When using this hook, it will always be selected size, regardless of the guide_size. However, if the guide_size is too small, skipping will occur.
### PK_HOOK
* `DenoiseScheduleHookProvider` - IterativeUpscale provides a hook that gradually changes the denoise to target_denoise as the iterative-step progresses.
* `CfgScheduleHookProvider` - IterativeUpscale provides a hook that gradually changes the cfg to target_cfg as the iterative-step progresses.
* `StepsScheduleHookProvider` - IterativeUpscale provides a hook that gradually changes the sampling-steps to target_steps as the iterative-step progresses.
* `NoiseInjectionHookProvider` - During each iteration of IterativeUpscale, noise is injected into the latent space while varying the strength according to a schedule.
* You need to install the [BlenderNeko/ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) node extension.
* The seed serves as the initial value required for generating noise, and it increments by 1 with each iteration as the process unfolds.
* The source determines the types of CPU noise and GPU noise to be configured.
* Currently, there is only a simple schedule available, where the strength of the noise varies from start_strength to end_strength during the progression of each iteration.
* `UnsamplerHookProvider` - Apply Unsampler during each iteration. To use this node, ComfyUI_Noise must be installed.
* `PixelKSampleHookCombine` - This is used to connect two PK_HOOKs. hook1 is executed first and then hook2 is executed.
* If you want to simultaneously change cfg and denoise, you can combine the PK_HOOKs of CfgScheduleHookProvider and PixelKSampleHookCombine.
### DETAILER_HOOK
* `NoiseInjectionDetailerHookProvider` - The `detailer_hook` is a hook in the `Detailer` that injects noise during the processing of each SEGS.
* `UnsamplerDetailerHookProvider` - Apply Unsampler during each cycle. To use this node, ComfyUI_Noise must be installed.
* `DenoiseSchedulerDetailerHookProvider` - During the progress of the cycle, the detailer's denoise is altered up to the `target_denoise`.
* `CoreMLDetailerHookProvider` - CoreML supports only 512x512, 512x768, 768x512, 768x768 size sampling. CoreMLDetailerHookProvider precisely fixes the upscale of the crop_region to this size. When using this hook, it will always be selected size, regardless of the guide_size. However, if the guide_size is too small, skipping will occur.
* `DetailerHookCombine` - This is used to connect two DETAILER_HOOKs. Similar to PixelKSampleHookCombine.
* `SEGSOrderedFilterDetailerHook`, SEGSRangeFilterDetailerHook, SEGSLabelFilterDetailerHook - There are a wrapper node that provides SEGSFilter nodes to be applied in FaceDetailer or Detector by creating DETAILER_HOOK.
* `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.
* Iterative Upscale (Latent) - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling.
This takes latent as input and outputs latent as the result.
* Iterative Upscale (Image) - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling. This takes image as input and outputs image as the result.
* Internally, this node uses 'Iterative Upscale (Latent)'.
### 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.
This takes latent as input and outputs latent as the result.
* `Iterative Upscale (Image)` - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling. This takes image as input and outputs image as the result.
* Internally, this node uses 'Iterative Upscale (Latent)'.
* TwoSamplersForMask - This node can apply two samplers depending on the mask area. The base_sampler is applied to the area where the mask is 0, while the mask_sampler is applied to the area where the mask is 1.
### TwoSamplers nodes
* `TwoSamplersForMask` - This node can apply two samplers depending on the mask area. The base_sampler is applied to the area where the mask is 0, while the mask_sampler is applied to the area where the mask is 1.
* Note: The latent encoded through VAEEncodeForInpaint cannot be used.
* KSamplerProvider - This is a wrapper that enables KSampler to be used in TwoSamplersForMask TwoSamplersForMaskUpscalerProvider.
* TiledKSamplerProvider - ComfyUI_TiledKSampler is a wrapper that provides KSAMPLER.
* `KSamplerProvider` - This is a wrapper that enables KSampler to be used in TwoSamplersForMask TwoSamplersForMaskUpscalerProvider.
* `TiledKSamplerProvider` - ComfyUI_TiledKSampler is a wrapper that provides KSAMPLER.
* You need to install the [BlenderNeko/ComfyUI_TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) node extension.
* TwoAdvancedSamplersForMask - TwoSamplersForMask is similar to TwoAdvancedSamplersForMask, but they differ in their operation. TwoSamplersForMask performs sampling in the mask area only after all the samples in the base area are finished. On the other hand, TwoAdvancedSamplersForMask performs sampling in both the base area and the mask area sequentially at each step.
* KSamplerAdvancedProvider - This is a wrapper that enables KSampler to be used in TwoAdvancedSamplersForMask.
* `TwoAdvancedSamplersForMask` - TwoSamplersForMask is similar to TwoAdvancedSamplersForMask, but they differ in their operation. TwoSamplersForMask performs sampling in the mask area only after all the samples in the base area are finished. On the other hand, TwoAdvancedSamplersForMask performs sampling in both the base area and the mask area sequentially at each step.
* `KSamplerAdvancedProvider` - This is a wrapper that enables KSampler to be used in TwoAdvancedSamplersForMask, RegionalSampler.
* sigma_factor: By multiplying the denoise schedule by the sigma_factor, you can adjust the amount of denoising based on the configured denoise.
* TwoSamplersForMaskUpscalerProvider - This is an Upscaler that extends TwoSamplersForMask to be used in Iterative Upscale.
* `TwoSamplersForMaskUpscalerProvider` - This is an Upscaler that extends TwoSamplersForMask to be used in Iterative Upscale.
* TwoSamplersForMaskUpscalerProviderPipe - pipe version of TwoSamplersForMaskUpscalerProvider.
* PreviewBridge - This custom node can be used with a bridge when using the MaskEditor feature of Clipspace.
* ImageSender, ImageReceiver - The images generated in ImageSender are automatically sent to the ImageReceiver with the same link_id.
* LatentSender, LatentReceiver - The latent generated in LatentSender are automatically sent to the LatentReceiver with the same link_id.
* Furthermore, LatentSender is implemented with PreviewLatent, which stores the latent in payload form within the image thumbnail.
* Due to the current structure of ComfyUI, it is unable to distinguish between SDXL latent and SD1.5/SD2.1 latent. Therefore, it generates thumbnails by decoding them using the SD1.5 method.
### Image Utils
* `PreviewBridge (image)` - This custom node can be used with a bridge for image when using the MaskEditor feature of Clipspace.
* `PreviewBridge (latent)` - This custom node can be used with a bridge for latent image when using the MaskEditor feature of Clipspace.
* If a latent with a mask is provided as input, it displays the mask. Additionally, the mask output provides the mask set in the latent.
* If a latent without a mask is provided as input, it outputs the original latent as is, but the mask output provides an output with the entire region set as a mask.
* When set mask through MaskEditor, a mask is applied to the latent, and the output includes the stored mask. The same mask is also output as the mask output.
* When connected to `vae_opt`, it takes higher priority than the `preview_method`.
* `ImageSender`, `ImageReceiver` - The images generated in ImageSender are automatically sent to the ImageReceiver with the same link_id.
* `LatentSender`, `LatentReceiver` - The latent generated in LatentSender are automatically sent to the LatentReceiver with the same link_id.
* Furthermore, LatentSender is implemented with PreviewLatent, which stores the latent in payload form within the image thumbnail.
* Due to the current structure of ComfyUI, it is unable to distinguish between SDXL latent and SD1.5/SD2.1 latent. Therefore, it generates thumbnails by decoding them using the SD1.5 method.
* Switch nodes
* Switch (image,mask), Switch (latent), Switch (SEGS) - Among multiple inputs, it selects the input designated by the selector and outputs it. The first input must be provided, while the others are optional. However, if the input specified by the selector is not connected, an error may occur.
* Switch (Any) - This is a Switch node that takes an arbitrary number of inputs and produces a single output. Its type is determined when connected to any node, and connecting inputs increases the available slots for connections.
* Inversed Switch (Any) - In contrast to `Switch (Any)`, it takes a single input and outputs one of many. Due to ComfyUI's functional limitations, the value of `select` must be determined at the time of queuing a prompt, and while it can serve as a `Primitive Node` or `ImpactInt`, it cannot function properly when connected through other nodes.
* Guide
* When the `Switch (Any)` and `Inversed Switch (Any)` selects are transformed into primitives, it's important to be cautious because the select range is not appropriately constrained, potentially leading to unintended behavior.
* `Switch (image,mask)`, `Switch (latent)`, `Switch (SEGS)`, `Switch (Any)` supports `sel_mode` param. The `sel_mode` sets the moment at which the `select` parameter is determined. `select_on_prompt` determines the `select` at the time of queuing the prompt, while `select_on_execution` determines it during the execution of the workflow. While `select_on_execution` offers more flexibility, it can potentially trigger workflow execution errors due to running nodes that may be impossible to execute within the limitations of ComfyUI. `select_on_prompt` bypasses this constraint by treating any inputs not selected as if they were disconnected. However, please note that when using `select_on_prompt`, the `select` can only be used with widgets or `Primitive Nodes` determined at the queue prompt.
* There is an issue when connecting the built-in reroute node with the switch's input/output slots. it can lead to forced disconnections during workflow loading. Therefore, it is advisable not to use reroute for making connections in such cases. However, there are no issues when using the reroute node in Pythongossss.
### Switch nodes
* `Switch (image,mask)`, `Switch (latent)`, `Switch (SEGS)` - Among multiple inputs, it selects the input designated by the selector and outputs it. The first input must be provided, while the others are optional. However, if the input specified by the selector is not connected, an error may occur.
* `Switch (Any)` - This is a Switch node that takes an arbitrary number of inputs and produces a single output. Its type is determined when connected to any node, and connecting inputs increases the available slots for connections.
* `Inversed Switch (Any)` - In contrast to `Switch (Any)`, it takes a single input and outputs one of many.
* NOTE: See this [tutorial](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/switch.md)
* [Wildcards](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ImpactWildcard.md) - These are nodes that supports syntax in the form of `__wildcard-name__` and dynamic prompt syntax like `{a|b|c}`.
### [Wildcards](http://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ImpactWildcard.md) nodes
* These are nodes that supports syntax in the form of `__wildcard-name__` and dynamic prompt syntax like `{a|b|c}`.
* Wildcard files can be used by placing `.txt` or `.yaml` files under either `ComfyUI-Impact-Pack/wildcards` or `ComfyUI-Impact-Pack/custom_wildcards` paths.
* You can download and use [Wildcard YAML](https://civitai.com/models/138970/billions-of-wildcards-all-in-one) files in this format.
* After the first execution, you can change the custom wildcards path in the `custom_wildcards` entry within the `ComfyUI-Impact-Pack/impact-pack.ini` file created.
* ImpactWildcardProcessor - The text is generated by processing the wildcard in the Text. If the mode is set to "populate", a dynamic prompt is generated with each execution and the input is filled in the second textbox. If the mode is set to "fixed", the content of the second textbox remains unchanged.
* `ImpactWildcardProcessor` - The text is generated by processing the wildcard in the Text. If the mode is set to "populate", a dynamic prompt is generated with each execution and the input is filled in the second textbox. If the mode is set to "fixed", the content of the second textbox remains unchanged.
* When an image is generated with the "fixed" mode, the prompt used for that particular generation is stored in the metadata.
* ImpactWildcardEncode - Similar to ImpactWildcardProcessor, this provides the loading functionality of LoRAs (e.g. `<lora:some_awesome_lora:0.7:1.2>`). Populated prompts are encoded using the clip after all the lora loading is done.
* `ImpactWildcardEncode` - Similar to ImpactWildcardProcessor, this provides the loading functionality of LoRAs (e.g. `<lora:some_awesome_lora:0.7:1.2>`). Populated prompts are encoded using the clip after all the lora loading is done.
* If the `Inspire Pack` is installed, you can use **Lora Block Weight** in the form of `LBW=lbw spec;`
* `<lora:chunli:1.0:1.0:LBW=B11:0,0,0,0,0,0,0,0,0,0,A,0,0,0,0,0,0;A=0.;>`, `<lora:chunli:1.0:1.0:LBW=0,0,0,0,0,0,0,0,0,0,A,B,0,0,0,0,0;A=0.5;B=0.2;>`, `<lora:chunli:1.0:1.0:LBW=SD-MIDD;>`
* Regional Sampling - These nodes offer the capability to divide regions and perform partial sampling using a mask. Unlike TwoSamplersForMask, sampling for each region is applied during each step.
* RegionalPrompt - This node combines a **mask** for specifying regions and the **sampler** to apply to each region to create `REGIONAL_PROMPTS`.
* CombineRegionalPrompts - Combine multiple `REGIONAL_PROMPTS` to create a single `REGIONAL_PROMPTS`.
* RegionalSampler - This node performs sampling using a base sampler and regional prompts. Sampling by the base sampler is executed at each step, while sampling for each region is performed through the sampler bound to each region.
### Regional Sampling
* These nodes offer the capability to divide regions and perform partial sampling using a mask. Unlike TwoSamplersForMask, sampling for each region is applied during each step.
* `RegionalPrompt` - This node combines a **mask** for specifying regions and the **sampler** to apply to each region to create `REGIONAL_PROMPTS`.
* `CombineRegionalPrompts` - Combine multiple `REGIONAL_PROMPTS` to create a single `REGIONAL_PROMPTS`.
* `RegionalSampler` - This node performs sampling using a base sampler and regional prompts. Sampling by the base sampler is executed at each step, while sampling for each region is performed through the sampler bound to each region.
* overlap_factor - Specifies the amount of overlap for each region to blend well with the area outside the mask.
* restore_latent - When sampling each region, restore the areas outside the mask to the base latent, preventing additional noise from being introduced outside the mask during region sampling.
* RegionalSamplerAdvanced - This is the Advanced version of the RegionalSampler. You can control it using `step` instead of `denoise`.
* NOTE: The `sde` sampler and `uni_pc` sampler introduce additional noise during each step of the sampling process. To mitigate this, when sampling each region, the `uni_pc` sampler applies additional `dpmpp_fast`, and the sde sampler applies the `dpmpp_2m` sampler as an additional measure.
* `RegionalSamplerAdvanced` - This is the Advanced version of the RegionalSampler. You can control it using `step` instead of `denoise`.
> NOTE: The `sde` sampler and `uni_pc` sampler introduce additional noise during each step of the sampling process. To mitigate this, when sampling each region, the `uni_pc` sampler applies additional `dpmpp_fast`, and the sde sampler applies the `dpmpp_2m` sampler as an additional measure.
* KSampler (pipe), KSampler (advanced/pipe)
* Image batch To Image List - Convert Image batch to Image List
- You can use images generated in a multi batch to handle them
* Make Image List - Convert multiple images into a single image list
* Make Image Batch - Convert multiple images into a single image batch
- The input of images can be scaled up as needed
### Impact KSampler
* These samplers support basic_pipe and AYS/OSS/GITS scheduler
* `KSampler (pipe)` - pipe version of KSampler
* `KSampler (advanced/pipe)` - pipe version of KSamplerAdvacned
* When converting the scheduler widget to input, refer to the `Impact Scheduler Adapter` node to resolve compatibility issues.
* `GITSScheduler Func Provider` - provider scheduler function for GITSScheduler
* String Selector - It selects and returns a portion of the string. When `multiline` mode is disabled, it simply returns the string of the line pointed to by the selector. When `multiline` mode is enabled, it divides the string based on lines that start with `#` and returns them. If the `select` value is larger than the number of items, it will start counting from the first line again and return accordingly.
* Combine Conditionings - It takes multiple conditionings as input and combines them into a single conditioning.
### Batch/List Util
* `Image Batch to Image List` - Convert Image batch to Image List
- You can use images generated in a multi batch to handle them
* `Image List to Image Batch` - Convert Image List to Image Batch
* `Make Image List` - Convert multiple images into a single image list
* `Make Image Batch` - Convert multiple images into a single image batch
- The input of images can be scaled up as needed
* `Masks to Mask List`, `Mask List to Masks`, `Make Mask List`, `Make Mask Batch` - It has the same functionality as the nodes above, but uses mask as input instead of image.
* `Flatten Mask Batch` - Flattens a Mask Batch into a single Mask. Normal operation is not guaranteed for non-binary masks.
* `Make List (Any)` - Create a list with arbitrary values.
* `Select Nth Item (Any list)` - Selects the Nth item from a list. If the index is out of range, it returns the last item in the list.
* Logics (experimental) - These nodes are experimental nodes designed to implement the logic for loops and dynamic switching.
* ImpactCompare, ImpactConditionalBranch, ImpactInt, ImpactValueSender, ImpactValueReceiver, ImpactImageInfo, ImpactMinMax, ImpactNeg, ImpactConditionalStopIteration
* ImpactIsNotEmptySEGS - This node returns `true` only if the input SEGS is not empty.
* Queue Trigger - When this node is executed, it adds a new queue to assist with repetitive tasks. It will only execute if the signal's status changes.
* Queue Trigger (Countdown) - Like the Queue Trigger, it adds a queue, but only adds it if it's greater than 1, and decrements the count by one each time it runs.
* Sleep - Waits for the specified time (in seconds).
* Set Widget Value - This node sets one of the optional inputs to the specified node's widget. An error may occur if the types do not match.
* Set Mute State - This node changes the mute state of a specific node.
* Control Bridge - Depending on whether the mode is set to `block` or `pass`, it changes the mute status of connected nodes. If there are nodes that require a change, the current execution is paused, the mute status is updated, and a new prompt queue is inserted.
### Logics (experimental)
* These nodes are experimental nodes designed to implement the logic for loops and dynamic switching.
* `ImpactCompare`, `ImpactConditionalBranch`, `ImpactConditionalBranchSelMode`, `ImpactInt`, `ImpactBoolean`, `ImpactValueSender`, `ImpactValueReceiver`, `ImpactImageInfo`, `ImpactMinMax`, `ImpactNeg`, `ImpactConditionalStopIteration`
* `ImpactIsNotEmptySEGS` - This node returns `true` only if the input SEGS is not empty.
* `ImpactIfNone` - Returns `true` if any_input is None, and returns `false` if it is not None.
* `Queue Trigger` - When this node is executed, it adds a new queue to assist with repetitive tasks. It will only execute if the signal's status changes.
* `Queue Trigger (Countdown)` - Like the Queue Trigger, it adds a queue, but only adds it if it's greater than 1, and decrements the count by one each time it runs.
* `Sleep` - Waits for the specified time (in seconds).
* `Set Widget Value` - This node sets one of the optional inputs to the specified node's widget. An error may occur if the types do not match.
* `Set Mute State` - This node changes the mute state of a specific node.
* `Control Bridge` - This node modifies the state of the connected control nodes based on the `mode` and `behavior` . If there are nodes that require a change, the current execution is paused, the mute status is updated, and a new prompt queue is inserted.
* When the `mode` is `active`, it makes the connected control nodes active regardless of the behavior.
* When the `mode` is `Bypass/Mute`, it changes the state of the connected nodes based on whether the behavior is `Bypass` or `Mute`.
* **Limitation**: Due to these characteristics, it does not function correctly when the batch count exceeds 1. Additionally, it does not guarantee proper operation when the seed is randomized or when the state of nodes is altered by actions such as `Queue Trigger`, `Set Widget Value`, `Set Mute`, before the Control Bridge.
* When utilizing this node, please structure the workflow in such a way that `Queue Trigger`, `Set Widget Value`, `Set Mute State`, and similar actions are executed at the end of the workflow.
* If you want to change the value of the seed at each iteration, please ensure that Set Widget Value is executed at the end of the workflow instead of using randomization.
* It is not a problem if the seed changes due to randomization as long as it occurs after the Control Bridge section.
* `Remote Boolean (on prompt)`, `Remote Int (on prompt)` - At the start of the prompt, this node forcibly sets the `widget_value` of `node_id`. It is disregarded if the target widget type is different.
* You can find the `node_id` by checking through [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager) using the format `Badge: #ID Nickname`.
* Experimental set of nodes for implementing loop functionality (tutorial to be prepared later / [example workflow](test/loop-test.json)).
* HuggingFace - These nodes provide functionalities based on HuggingFace repository models.
### HuggingFace nodes
* These nodes provide functionalities based on HuggingFace repository models.
* The path where the HuggingFace model cache is stored can be changed through the `HF_HOME` environment variable.
* `HF Transformers Classifier Provider` - This is a node that provides a classifier based on HuggingFace's transformers models.
* The 'repo id' parameter should contain HuggingFace's repo id. When `preset_repo_id` is set to `Manual repo id`, use the manually entered repo id in `manual_repo_id`.
* e.g. 'rizvandwiki/gender-classification-2' is a repository that provides a model for gender classification.
@@ -207,79 +303,62 @@ This takes latent as input and outputs latent as the result.
* For supported labels, please refer to the `config.json` of the respective HuggingFace repository.
* `#Female` and `#Male` are symbols that group multiple labels such as `Female, women, woman, ...`, for convenience, rather than being single labels.
## MMDet nodes
* MMDetDetectorProvider - Loads the MMDet model to provide BBOX_DETECTOR and SEGM_DETECTOR.
* To use the existing MMDetDetectorProvider, you need to enable the MMDet usage configuration.
### Etc nodes
* `Impact Scheduler Adapter` - With the addition of AYS to the scheduler of the Impact Pack and Inspire Pack, there is an issue of incompatibility when the existing scheduler widget is converted to input. The Impact Scheduler Adapter allows for an indirect connection to be possible.
* `StringListToString` - Convert String List to String
* `WildcardPromptFromString` - Create labeled wildcard for detailer from string.
* This node works well when used with MakeTileSEGS. [[Link](https://github.com/ltdrdata/ComfyUI-Impact-Pack/pull/536#discussion_r1586060779)]
* `String Selector` - It selects and returns a portion of the string. When `multiline` mode is disabled, it simply returns the string of the line pointed to by the selector. When `multiline` mode is enabled, it divides the string based on lines that start with `#` and returns them. If the `select` value is larger than the number of items, it will start counting from the first line again and return accordingly.
* `Combine Conditionings` - It takes multiple conditionings as input and combines them into a single conditioning.
* `Concat Conditionings` - It takes multiple conditionings as input and concat them into a single conditioning.
* `Negative Cond Placeholder` - Models like FLUX.1 do not use Negative Conditioning. This is a placeholder node for them. You can use FLUX.1 by replacing the Negative Conditioning used in Impact KSampler, KSampler (Inspire), and Detailer with this node.
* `Execution Order Controller` - A helper node that can forcibly control the execution order of nodes.
* Connect the output of the node that should be executed first to the signal, and make the input of the node that should be executed later pass through this node.
* `List Bridge` - When passing the list output through this node, it collects and organizes the data before forwarding it, which ensures that the previous stage's sub-workflow has been completed.
## Feature
* Interactive SAM Detector (Clipspace) - When you right-click on a node that has 'MASK' and 'IMAGE' outputs, a context menu will open. From this menu, you can either open a dialog to create a SAM Mask using 'Open in SAM Detector', or copy the content (likely mask data) using 'Copy (Clipspace)' and generate a mask using 'Impact SAM Detector' from the clipspace menu, and then paste it using 'Paste (Clipspace)'.
* `Interactive SAM Detector (Clipspace)` - When you right-click on a node that has 'MASK' and 'IMAGE' outputs, a context menu will open. From this menu, you can either open a dialog to create a SAM Mask using 'Open in SAM Detector', or copy the content (likely mask data) using 'Copy (Clipspace)' and generate a mask using 'Impact SAM Detector' from the clipspace menu, and then paste it using 'Paste (Clipspace)'.
* Providing a feature to detect errors that occur when mixing models and clips from checkpoints such as `SDXL Base`, `SDXL Refiner`, `SD1.x`, `SD2.x` during sample execution, and reporting appropriate errors.
## Deprecated
* The following nodes have been kept only for compatibility with existing workflows, and are no longer supported. Please replace them with new nodes.
* ONNX Detector (SEGS) - BBOX Detector (SEGS)
* MMDetLoader -> MMDetDetectorProvider
* SegsMaskCombine -> SEGS to MASK (combined)
* BboxDetectorForEach -> BBOX Detector (SEGS)
* SegmDetectorForEach -> SEGM Detector (SEGS)
* BboxDetectorCombined -> BBOX Detector (combined)
* SegmDetectorCombined -> SEGM Detector (combined)
* MaskPainter -> PreviewBridge
* To use the existing deprecated legacy nodes, you need to enable the MMDet usage configuration.
## How To Install?
## Ultralytics models
* huggingface.co/Bingsu/[adetailer](https://github.com/ultralytics/assets/releases/) - You can download face, people detection models, and clothing detection models.
* ultralytics/[assets](https://github.com/ultralytics/assets/releases/) - You can download various types of detection models other than faces or people.
## How to activate 'MMDet usage'
* Upon the initial execution, an `impact-pack.ini` file will be generated in the custom_nodes/ComfyUI-Impact-Pack directory.
```
[default]
dependency_version = 2
mmdet_skip = True
```
* Change `mmdet_skip = True` to `mmdet_skip = False`
```
[default]
dependency_version = 2
mmdet_skip = False
```
* Restart ComfyUI
## Installation
### Install via ComfyUI-Manager (Recommended)
* Search `ComfyUI Impact Pack` in ComfyUI-Manager and click `Install` button.
### Manual Install (Not Recommended)
1. `cd custom_nodes`
1. `git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack.git`
2. `git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack`
3. `cd ComfyUI-Impact-Pack`
4. (optional) `git submodule update --init --recursive`
* Impact Pack will automatically download subpack during its initial launch.
5. (optional) `python install.py`
* Impact Pack will automatically install its dependencies during its initial launch.
* For the portable version, you should execute the command `..\..\..\python_embeded\python.exe install.py` to run the installation script.
4. `pip install -r requirements.txt`
* **IMPORTANT**:
* You must install it within the Python environment where ComfyUI is running.
* For the portable version, use `<installed path>\python_embeded\python.exe -m pip` instead of `pip`. For a `venv`, activate the `venv` first and then use `pip`.
5. Restart ComfyUI
* NOTE1: If an error occurs during the installation process, please refer to [Troubleshooting Page](troubleshooting/TROUBLESHOOTING.md) for assistance.
* NOTE2: You can use this colab notebook [colab notebook](https://colab.research.google.com/github/ltdrdata/ComfyUI-Impact-Pack/blob/Main/notebook/comfyui_colab_impact_pack.ipynb) to launch it. This notebook automatically downloads the impact pack to the custom_nodes directory, installs the tested dependencies, and runs it.
* NOTE3: If you create an empty file named `skip_download_model` in the `ComfyUI/custom_nodes/` directory, it will skip the model download step during the installation of the impact pack.
6. Restart ComfyUI
* NOTE: If an error occurs during the installation process, please refer to [Troubleshooting Page](troubleshooting/TROUBLESHOOTING.md) for assistance.
* You can use this colab notebook [colab notebook](https://colab.research.google.com/github/ltdrdata/ComfyUI-Impact-Pack/blob/Main/notebook/comfyui_colab_impact_pack.ipynb) to launch it. This notebook automatically downloads the impact pack to the custom_nodes directory, installs the tested dependencies, and runs it.
## Package Dependencies (If you need to manual setup.)
* pip install
* openmim
* segment-anything
* ultralytics
* scikit-image
* piexif
* (optional) pycocotools
* piexif
* opencv-python
* scipy
* numpy<2
* dill
* matplotlib
* (optional) onnxruntime
* (deprecated) openmim # for mim
* (deprecated) pycocotools # for mim
* mim install (optional)
* mmcv==2.0.0, mmdet==3.0.0, mmengine==0.7.2
* linux packages (ubuntu)
* libgl1-mesa-glx
* libglib2.0-0
@@ -302,17 +381,16 @@ sam_editor_model = sam_vit_b_01ec64.pth
```
## Other Materials (auto-download on initial startup)
## Other Materials (auto-download when installing)
* ComfyUI/models/mmdets/bbox <= https://huggingface.co/dustysys/ddetailer/resolve/main/mmdet/bbox/mmdet_anime-face_yolov3.pth
* ComfyUI/models/mmdets/bbox <= https://raw.githubusercontent.com/Bing-su/dddetailer/master/config/mmdet_anime-face_yolov3.py
* ComfyUI/models/sams <= https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth
## Troubleshooting page
* [Troubleshooting Page](troubleshooting/TROUBLESHOOTING.md)
## How to use (DDetailer feature)
## How To Use (DDetailer feature)
#### 1. Basic auto face detection and refine exapmle.
![simple](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/simple.png)
@@ -403,9 +481,10 @@ open-mmlab/[mmdetection](https://github.com/open-mmlab/mmdetection) - Object det
biegert/[ComfyUI-CLIPSeg](https://github.com/biegert/ComfyUI-CLIPSeg) - This is a custom node that enables the use of CLIPSeg technology, which can find segments through prompts, in ComfyUI.
BlenderNeok/[ComfyUI-TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) -
The tile sampler allows high-resolution sampling even in places with low GPU VRAM.
BlenderNeok/[ComfyUI-TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) - The tile sampler allows high-resolution sampling even in places with low GPU VRAM.
BlenderNeok/[ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) - The noise injection feature relies on this function.
BlenderNeok/[ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) - The noise injection feature relies on this function and slerp code for noise variation
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!
+160 -98
View File
@@ -13,45 +13,20 @@ import traceback
comfy_path = os.path.dirname(folder_paths.__file__)
impact_path = os.path.join(os.path.dirname(__file__))
subpack_path = os.path.join(os.path.dirname(__file__), "impact_subpack")
modules_path = os.path.join(os.path.dirname(__file__), "modules")
wildcards_path = os.path.join(os.path.dirname(__file__), "wildcards")
custom_wildcards_path = os.path.join(os.path.dirname(__file__), "custom_wildcards")
sys.path.append(modules_path)
import impact.config
import impact.sample_error_enhancer
print(f"### Loading: ComfyUI-Impact-Pack ({impact.config.version})")
def do_install():
import importlib
spec = importlib.util.spec_from_file_location('impact_install', os.path.join(os.path.dirname(__file__), 'install.py'))
impact_install = importlib.util.module_from_spec(spec)
spec.loader.exec_module(impact_install)
# ensure dependency
if not os.path.exists(os.path.join(subpack_path, ".git")) and os.path.exists(subpack_path):
print(f"### CompfyUI-Impact-Pack: corrupted subpack detected.")
shutil.rmtree(subpack_path)
if impact.config.get_config()['dependency_version'] < impact.config.dependency_version or not os.path.exists(subpack_path):
print(f"### ComfyUI-Impact-Pack: Updating dependencies [{impact.config.get_config()['dependency_version']} -> {impact.config.dependency_version}]")
do_install()
sys.path.append(subpack_path)
# Core
# recheck dependencies for colab
try:
import impact.subpack_nodes # This import must be done before cv2.
import folder_paths
import torch
import cv2
from cv2 import setNumThreads
import numpy as np
import comfy.samplers
import comfy.sd
@@ -65,52 +40,32 @@ try:
import mmcv
from mmdet.apis import (inference_detector, init_detector)
from mmdet.evaluation import get_classes
except:
import importlib
print("### ComfyUI-Impact-Pack: Reinstall dependencies (several dependencies are missing.)")
do_install()
except Exception as e:
import logging
logging.error("[Impact Pack] Failed to import due to several dependencies are missing!!!!")
raise e
import impact.impact_server # to load server api
def setup_js():
import nodes
js_dest_path = os.path.join(comfy_path, "web", "extensions", "impact-pack")
from .modules.impact.impact_pack import *
from .modules.impact.detectors import *
from .modules.impact.pipe import *
from .modules.impact.logics import *
from .modules.impact.util_nodes import *
from .modules.impact.segs_nodes import *
from .modules.impact.special_samplers import *
from .modules.impact.hf_nodes import *
from .modules.impact.bridge_nodes import *
from .modules.impact.hook_nodes import *
from .modules.impact.animatediff_nodes import *
from .modules.impact.segs_upscaler import *
if hasattr(nodes, "EXTENSION_WEB_DIRS"):
if os.path.exists(js_dest_path):
shutil.rmtree(js_dest_path)
else:
print(f"[WARN] ComfyUI-Impact-Pack: Your ComfyUI version is outdated. Please update to the latest version.")
# setup js
if not os.path.exists(js_dest_path):
os.makedirs(js_dest_path)
js_src_path = os.path.join(impact_path, "js", "impact-pack.js")
shutil.copy(js_src_path, js_dest_path)
js_src_path = os.path.join(impact_path, "js", "impact-sam-editor.js")
shutil.copy(js_src_path, js_dest_path)
js_src_path = os.path.join(impact_path, "js", "comboBoolMigration.js")
shutil.copy(js_src_path, js_dest_path)
import threading
setup_js()
threading.Thread(target=impact.wildcards.wildcard_load).start()
from impact.impact_pack import *
from impact.detectors import *
from impact.pipe import *
from impact.logics import *
from impact.util_nodes import *
from impact.segs_nodes import *
from impact.special_samplers import *
from impact.hf_nodes import *
impact.wildcards.read_wildcard_dict(wildcards_path)
try:
impact.wildcards.read_wildcard_dict(impact.config.get_config()['custom_wildcards'])
except Exception as e:
print(f"[Impact Pack] Failed to load custom wildcards directory.")
NODE_CLASS_MAPPINGS = {
"SAMLoader": SAMLoader,
@@ -124,6 +79,7 @@ NODE_CLASS_MAPPINGS = {
"DetailerForEachDebug": DetailerForEachTest,
"DetailerForEachPipe": DetailerForEachPipe,
"DetailerForEachDebugPipe": DetailerForEachTestPipe,
"DetailerForEachPipeForAnimateDiff": DetailerForEachPipeForAnimateDiff,
"SAMDetectorCombined": SAMDetectorCombined,
"SAMDetectorSegmented": SAMDetectorSegmented,
@@ -137,6 +93,7 @@ NODE_CLASS_MAPPINGS = {
"FromDetailerPipe": FromDetailerPipe,
"FromDetailerPipe_v2": FromDetailerPipe_v2,
"FromDetailerPipeSDXL": FromDetailerPipe_SDXL,
"AnyPipeToBasic": AnyPipeToBasic,
"ToBasicPipe": ToBasicPipe,
"FromBasicPipe": FromBasicPipe,
"FromBasicPipe_v2": FromBasicPipe_v2,
@@ -159,17 +116,32 @@ NODE_CLASS_MAPPINGS = {
"PixelKSampleHookCombine": PixelKSampleHookCombine,
"DenoiseScheduleHookProvider": DenoiseScheduleHookProvider,
"StepsScheduleHookProvider": StepsScheduleHookProvider,
"CfgScheduleHookProvider": CfgScheduleHookProvider,
"NoiseInjectionHookProvider": NoiseInjectionHookProvider,
"NoiseInjectionDetailerHookProvider": NoiseInjectionDetailerHookProvider,
"UnsamplerHookProvider": UnsamplerHookProvider,
"CoreMLDetailerHookProvider": CoreMLDetailerHookProvider,
"PreviewDetailerHookProvider": PreviewDetailerHookProvider,
"DetailerHookCombine": DetailerHookCombine,
"NoiseInjectionDetailerHookProvider": NoiseInjectionDetailerHookProvider,
"UnsamplerDetailerHookProvider": UnsamplerDetailerHookProvider,
"DenoiseSchedulerDetailerHookProvider": DenoiseSchedulerDetailerHookProvider,
"SEGSOrderedFilterDetailerHookProvider": SEGSOrderedFilterDetailerHookProvider,
"SEGSRangeFilterDetailerHookProvider": SEGSRangeFilterDetailerHookProvider,
"SEGSLabelFilterDetailerHookProvider": SEGSLabelFilterDetailerHookProvider,
"VariationNoiseDetailerHookProvider": VariationNoiseDetailerHookProvider,
# "CustomNoiseDetailerHookProvider": CustomNoiseDetailerHookProvider,
"BitwiseAndMask": BitwiseAndMask,
"SubtractMask": SubtractMask,
"AddMask": AddMask,
"MaskRectArea": MaskRectArea,
"MaskRectAreaAdvanced": MaskRectAreaAdvanced,
"ImpactSegsAndMask": SegsBitwiseAndMask,
"ImpactSegsAndMaskForEach": SegsBitwiseAndMaskForEach,
"EmptySegs": EmptySEGS,
"ImpactFlattenMask": FlattenMask,
"MediaPipeFaceMeshToSEGS": MediaPipeFaceMeshToSEGS,
"MaskToSEGS": MaskToSEGS,
@@ -177,7 +149,9 @@ NODE_CLASS_MAPPINGS = {
"ToBinaryMask": ToBinaryMask,
"MasksToMaskList": MasksToMaskList,
"MaskListToMaskBatch": MaskListToMaskBatch,
"ImageListToImageBatch": ImageListToMaskBatch,
"ImageListToImageBatch": ImageListToImageBatch,
"SetDefaultImageForSEGS": DefaultImageForSEGS,
"RemoveImageFromSEGS": RemoveImageFromSEGS,
"BboxDetectorSEGS": BboxDetectorForEach,
"SegmDetectorSEGS": SegmDetectorForEach,
@@ -186,6 +160,9 @@ NODE_CLASS_MAPPINGS = {
"ImpactSimpleDetectorSEGS": SimpleDetectorForEach,
"ImpactSimpleDetectorSEGSPipe": SimpleDetectorForEachPipe,
"ImpactControlNetApplySEGS": ControlNetApplySEGS,
"ImpactControlNetApplyAdvancedSEGS": ControlNetApplyAdvancedSEGS,
"ImpactControlNetClearSEGS": ControlNetClearSEGS,
"ImpactIPAdapterApplySEGS": IPAdapterApplySEGS,
"ImpactDecomposeSEGS": DecomposeSEGS,
"ImpactAssembleSEGS": AssembleSEGS,
@@ -193,7 +170,13 @@ NODE_CLASS_MAPPINGS = {
"ImpactEdit_SEG_ELT": Edit_SEG_ELT,
"ImpactDilate_Mask_SEG_ELT": Dilate_SEG_ELT,
"ImpactDilateMask": DilateMask,
"ImpactGaussianBlurMask": GaussianBlurMask,
"ImpactDilateMaskInSEGS": DilateMaskInSEGS,
"ImpactGaussianBlurMaskInSEGS": GaussianBlurMaskInSEGS,
"ImpactScaleBy_BBOX_SEG_ELT": SEG_ELT_BBOX_ScaleBy,
"ImpactFrom_SEG_ELT_bbox": From_SEG_ELT_bbox,
"ImpactFrom_SEG_ELT_crop_region": From_SEG_ELT_crop_region,
"ImpactCount_Elts_in_SEGS": Count_Elts_in_SEGS,
"BboxDetectorCombined_v2": BboxDetectorCombined,
"SegmDetectorCombined_v2": SegmDetectorCombined,
@@ -206,7 +189,10 @@ NODE_CLASS_MAPPINGS = {
"KSamplerAdvancedProvider": KSamplerAdvancedProvider,
"TwoAdvancedSamplersForMask": TwoAdvancedSamplersForMask,
"ImpactNegativeConditioningPlaceholder": NegativeConditioningPlaceholder,
"PreviewBridge": PreviewBridge,
"PreviewBridgeLatent": PreviewBridgeLatent,
"ImageSender": ImageSender,
"ImageReceiver": ImageReceiver,
"LatentSender": LatentSender,
@@ -220,14 +206,19 @@ NODE_CLASS_MAPPINGS = {
"ImpactWildcardProcessor": ImpactWildcardProcessor,
"ImpactWildcardEncode": ImpactWildcardEncode,
"SEGSUpscaler": SEGSUpscaler,
"SEGSUpscalerPipe": SEGSUpscalerPipe,
"SEGSDetailer": SEGSDetailer,
"SEGSPaste": SEGSPaste,
"SEGSPreview": SEGSPreview,
"SEGSPreviewCNet": SEGSPreviewCNet,
"SEGSToImageList": SEGSToImageList,
"ImpactSEGSToMaskList": SEGSToMaskList,
"ImpactSEGSToMaskBatch": SEGSToMaskBatch,
"ImpactSEGSConcat": SEGSConcat,
"ImpactSEGSPicker": SEGSPicker,
"ImpactMakeTileSEGS": MakeTileSEGS,
"ImpactSEGSMerge": SEGSMerge,
"SEGSDetailerForAnimateDiff": SEGSDetailerForAnimateDiff,
@@ -240,6 +231,10 @@ NODE_CLASS_MAPPINGS = {
"ImpactImageBatchToImageList": ImageBatchToImageList,
"ImpactMakeImageList": MakeImageList,
"ImpactMakeImageBatch": MakeImageBatch,
"ImpactMakeAnyList": MakeAnyList,
"ImpactMakeMaskList": MakeMaskList,
"ImpactMakeMaskBatch": MakeMaskBatch,
"ImpactSelectNthItemOfAnyList": NthItemOfAnyList,
"RegionalSampler": RegionalSampler,
"RegionalSamplerAdvanced": RegionalSamplerAdvanced,
@@ -247,22 +242,36 @@ NODE_CLASS_MAPPINGS = {
"RegionalPrompt": RegionalPrompt,
"ImpactCombineConditionings": CombineConditionings,
"ImpactConcatConditionings": ConcatConditionings,
"ImpactSEGSLabelAssign": SEGSLabelAssign,
"ImpactSEGSLabelFilter": SEGSLabelFilter,
"ImpactSEGSRangeFilter": SEGSRangeFilter,
"ImpactSEGSOrderedFilter": SEGSOrderedFilter,
"ImpactSEGSIntersectionFilter": SEGSIntersectionFilter,
"ImpactSEGSNMSFilter": SEGSNMSFilter,
"ImpactCompare": ImpactCompare,
"ImpactConditionalBranch": ImpactConditionalBranch,
"ImpactConditionalBranchSelMode": ImpactConditionalBranchSelMode,
"ImpactIfNone": ImpactIfNone,
"ImpactConvertDataType": ImpactConvertDataType,
"ImpactLogicalOperators": ImpactLogicalOperators,
"ImpactInt": ImpactInt,
# "ImpactFloat": ImpactFloat,
"ImpactFloat": ImpactFloat,
"ImpactBoolean": ImpactBoolean,
"ImpactValueSender": ImpactValueSender,
"ImpactValueReceiver": ImpactValueReceiver,
"ImpactImageInfo": ImpactImageInfo,
"ImpactLatentInfo": ImpactLatentInfo,
"ImpactMinMax": ImpactMinMax,
"ImpactNeg": ImpactNeg,
"ImpactConditionalStopIteration": ImpactConditionalStopIteration,
"ImpactStringSelector": StringSelector,
"StringListToString": StringListToString,
"WildcardPromptFromString": WildcardPromptFromString,
"ImpactExecutionOrderController": ImpactExecutionOrderController,
"ImpactListBridge": ImpactListBridge,
"RemoveNoiseMask": RemoveNoiseMask,
@@ -276,20 +285,29 @@ NODE_CLASS_MAPPINGS = {
"ImpactControlBridge": ImpactControlBridge,
"ImpactIsNotEmptySEGS": ImpactNotEmptySEGS,
"ImpactSleep": ImpactSleep,
"ImpactRemoteBoolean": ImpactRemoteBoolean,
"ImpactRemoteInt": ImpactRemoteInt,
"ImpactHFTransformersClassifierProvider": HF_TransformersClassifierProvider,
"ImpactSEGSClassify": SEGS_Classify
"ImpactSEGSClassify": SEGS_Classify,
"ImpactSchedulerAdapter": ImpactSchedulerAdapter,
"GITSSchedulerFuncProvider": GITSSchedulerFuncProvider
}
NODE_DISPLAY_NAME_MAPPINGS = {
"SAMLoader": "SAMLoader (Impact)",
"BboxDetectorSEGS": "BBOX Detector (SEGS)",
"SegmDetectorSEGS": "SEGM Detector (SEGS)",
"ONNXDetectorSEGS": "ONNX Detector (SEGS/legacy) - use BBOXDetector",
"ImpactSimpleDetectorSEGS_for_AD": "Simple Detector for AnimateDiff (SEGS)",
"ImpactSimpleDetectorSEGS": "Simple Detector (SEGS)",
"ImpactSimpleDetectorSEGSPipe": "Simple Detector (SEGS/pipe)",
"ImpactControlNetApplySEGS": "ControlNetApply (SEGS)",
"ImpactControlNetApplySEGS": "ControlNetApply (SEGS) - DEPRECATED",
"ImpactControlNetApplyAdvancedSEGS": "ControlNetApply (SEGS)",
"ImpactIPAdapterApplySEGS": "IPAdapterApply (SEGS)",
"BboxDetectorCombined_v2": "BBOX Detector (combined)",
"SegmDetectorCombined_v2": "SEGM Detector (combined)",
@@ -297,23 +315,29 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"MediaPipeFaceMeshToSEGS": "MediaPipe FaceMesh to SEGS",
"MaskToSEGS": "MASK to SEGS",
"MaskToSEGS_for_AnimateDiff": "MASK to SEGS for AnimateDiff",
"BitwiseAndMaskForEach": "Bitwise(SEGS & SEGS)",
"SubtractMaskForEach": "Bitwise(SEGS - SEGS)",
"ImpactSegsAndMask": "Bitwise(SEGS & MASK)",
"ImpactSegsAndMaskForEach": "Bitwise(SEGS & MASKS ForEach)",
"BitwiseAndMask": "Bitwise(MASK & MASK)",
"SubtractMask": "Bitwise(MASK - MASK)",
"AddMask": "Bitwise(MASK + MASK)",
"BitwiseAndMaskForEach": "Pixelwise(SEGS & SEGS)",
"SubtractMaskForEach": "Pixelwise(SEGS - SEGS)",
"ImpactSegsAndMask": "Pixelwise(SEGS & MASK)",
"ImpactSegsAndMaskForEach": "Pixelwise(SEGS & MASKS ForEach)",
"BitwiseAndMask": "Pixelwise(MASK & MASK)",
"SubtractMask": "Pixelwise(MASK - MASK)",
"AddMask": "Pixelwise(MASK + MASK)",
"MaskRectArea": "Mask Rect Area",
"MaskRectAreaAdvanced": "Mask Rect Area (Advanced)",
"ImpactFlattenMask": "Flatten Mask Batch",
"DetailerForEach": "Detailer (SEGS)",
"DetailerForEachPipe": "Detailer (SEGS/pipe)",
"DetailerForEachDebug": "DetailerDebug (SEGS)",
"DetailerForEachDebugPipe": "DetailerDebug (SEGS/pipe)",
"SEGSDetailerForAnimateDiff": "Detailer For AnimateDiff (SEGS/pipe)",
"SEGSDetailerForAnimateDiff": "SEGSDetailer For AnimateDiff (SEGS/pipe)",
"DetailerForEachPipeForAnimateDiff": "Detailer For AnimateDiff (SEGS/pipe)",
"SEGSUpscaler": "Upscaler (SEGS)",
"SEGSUpscalerPipe": "Upscaler (SEGS/pipe)",
"SAMDetectorCombined": "SAMDetector (combined)",
"SAMDetectorSegmented": "SAMDetector (segmented)",
"FaceDetailerPipe": "FaceDetailer (pipe)",
"MaskDetailerPipe": "MaskDetailer (Pipe)",
"MaskDetailerPipe": "MaskDetailer (pipe)",
"FromDetailerPipeSDXL": "FromDetailer (SDXL/pipe)",
"BasicPipeToDetailerPipeSDXL": "BasicPipe -> DetailerPipe (SDXL)",
@@ -323,9 +347,10 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"DetailerPipeToBasicPipe": "DetailerPipe -> BasicPipe",
"EditBasicPipe": "Edit BasicPipe",
"EditDetailerPipe": "Edit DetailerPipe",
"AnyPipeToBasic": "Any PIPE -> BasicPipe",
"LatentPixelScale": "Latent Scale (on Pixel Space)",
"IterativeLatentUpscale": "Iterative Upscale (Latent)",
"IterativeLatentUpscale": "Iterative Upscale (Latent/on Pixel Space)",
"IterativeImageUpscale": "Iterative Upscale (Image)",
"TwoSamplersForMaskUpscalerProvider": "TwoSamplersForMask Upscaler Provider",
@@ -336,41 +361,66 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"ImpactKSamplerBasicPipe": "KSampler (pipe)",
"ImpactKSamplerAdvancedBasicPipe": "KSampler (Advanced/pipe)",
"ImpactSEGSLabelAssign": "SEGS Assign (label)",
"ImpactSEGSLabelFilter": "SEGS Filter (label)",
"ImpactSEGSRangeFilter": "SEGS Filter (range)",
"ImpactSEGSOrderedFilter": "SEGS Filter (ordered)",
"ImpactSEGSIntersectionFilter": "SEGS Filter (intersection)",
"ImpactSEGSNMSFilter": "SEGS Filter (non max suppression)",
"ImpactSEGSConcat": "SEGS Concat",
"ImpactSEGSToMaskList": "SEGS to Mask List",
"ImpactSEGSToMaskBatch": "SEGS to Mask Batch",
"ImpactSEGSPicker": "Picker (SEGS)",
"ImpactMakeTileSEGS": "Make Tile SEGS",
"ImpactSEGSMerge": "SEGS Merge",
"ImpactDecomposeSEGS": "Decompose (SEGS)",
"ImpactAssembleSEGS": "Assemble (SEGS)",
"ImpactFrom_SEG_ELT": "From SEG_ELT",
"ImpactEdit_SEG_ELT": "Edit SEG_ELT",
"ImpactFrom_SEG_ELT_bbox": "From SEG_ELT bbox",
"ImpactFrom_SEG_ELT_crop_region": "From SEG_ELT crop_region",
"ImpactDilate_Mask_SEG_ELT": "Dilate Mask (SEG_ELT)",
"ImpactScaleBy_BBOX_SEG_ELT": "ScaleBy BBOX (SEG_ELT)",
"ImpactCount_Elts_in_SEGS": "Count Elts in SEGS",
"ImpactDilateMask": "Dilate Mask",
"ImpactGaussianBlurMask": "Gaussian Blur Mask",
"ImpactDilateMaskInSEGS": "Dilate Mask (SEGS)",
"ImpactGaussianBlurMaskInSEGS": "Gaussian Blur Mask (SEGS)",
"PreviewBridge": "Preview Bridge",
"PreviewBridge": "Preview Bridge (Image)",
"PreviewBridgeLatent": "Preview Bridge (Latent)",
"ImageSender": "Image Sender",
"ImageReceiver": "Image Receiver",
"ImageMaskSwitch": "Switch (images, mask)",
"ImpactSwitch": "Switch (Any)",
"ImpactInversedSwitch": "Inversed Switch (Any)",
"ImpactExecutionOrderController": "Execution Order Controller",
"ImpactListBridge": "List Bridge",
"MasksToMaskList": "Masks to Mask List",
"MaskListToMaskBatch": "Mask List to Masks",
"ImpactImageBatchToImageList": "Image batch to Image List",
"MasksToMaskList": "Mask Batch to Mask List",
"MaskListToMaskBatch": "Mask List to Mask Batch",
"ImpactImageBatchToImageList": "Image Batch to Image List",
"ImageListToImageBatch": "Image List to Image Batch",
"ImpactMakeImageList": "Make Image List",
"ImpactMakeImageBatch": "Make Image Batch",
"ImpactMakeMaskList": "Make Mask List",
"ImpactMakeMaskBatch": "Make Mask Batch",
"ImpactMakeAnyList": "Make List (Any)",
"ImpactSelectNthItemOfAnyList": "Select Nth Item (Any list)",
"ImpactStringSelector": "String Selector",
"StringListToString": "String List to String",
"WildcardPromptFromString": "Wildcard Prompt from String",
"ImpactIsNotEmptySEGS": "SEGS isn't Empty",
"SetDefaultImageForSEGS": "Set Default Image for SEGS",
"RemoveImageFromSEGS": "Remove Image from SEGS",
"RemoveNoiseMask": "Remove Noise Mask",
"ImpactCombineConditionings": "Combine Conditionings",
"ImpactConcatConditionings": "Concat Conditionings",
"ImpactQueueTrigger": "Queue Trigger",
"ImpactQueueTriggerCountdown": "Queue Trigger (Countdown)",
@@ -378,12 +428,20 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"ImpactNodeSetMuteState": "Set Mute State",
"ImpactControlBridge": "Control Bridge",
"ImpactSleep": "Sleep",
"ImpactRemoteBoolean": "Remote Boolean (on prompt)",
"ImpactRemoteInt": "Remote Int (on prompt)",
"ImpactHFTransformersClassifierProvider": "HF Transformers Classifier Provider",
"ImpactSEGSClassify": "SEGS Classify",
"LatentSwitch": "Switch (latent/legacy)",
"SEGSSwitch": "Switch (SEGS/legacy)"
"SEGSSwitch": "Switch (SEGS/legacy)",
"SEGSPreviewCNet": "SEGSPreview (CNET Image)",
"ImpactSchedulerAdapter": "Impact Scheduler Adapter",
"GITSSchedulerFuncProvider": "GITSScheduler Func Provider",
"ImpactNegativeConditioningPlaceholder": "Negative Cond Placeholder"
}
if not impact.config.get_config()['mmdet_skip']:
@@ -410,19 +468,23 @@ if not impact.config.get_config()['mmdet_skip']:
"SegmDetectorCombined": "SegmDetectorCombined (Legacy)",
})
try:
import impact.subpack_nodes
NODE_CLASS_MAPPINGS.update(impact.subpack_nodes.NODE_CLASS_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(impact.subpack_nodes.NODE_DISPLAY_NAME_MAPPINGS)
except Exception as e:
print("### ComfyUI-Impact-Pack: (IMPORT FAILED) Subpack\n")
print(" The module at the `custom_nodes/ComfyUI-Impact-Pack/impact_subpack` path appears to be incomplete.")
print(" Recommended to delete the path and restart ComfyUI.")
print(" If the issue persists, please report it to https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues.")
print("\n---------------------------------")
traceback.print_exc()
print("---------------------------------\n")
# NOTE: Inject directly into EXTENSION_WEB_DIRS instead of WEB_DIRECTORY
# Provide the js path fixed as ComfyUI-Impact-Pack instead of the path name, making it available for external use
# WEB_DIRECTORY = "js" -- deprecated method
nodes.EXTENSION_WEB_DIRS["ComfyUI-Impact-Pack"] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'js')
WEB_DIRECTORY = "js"
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
try:
import cm_global
cm_global.register_extension('ComfyUI-Impact-Pack',
{'version': config.version_code,
'name': 'Impact Pack',
'nodes': set(NODE_CLASS_MAPPINGS.keys()),
'description': 'This extension provides inpainting functionality based on the detector and detailer, along with convenient workflow features like wildcards and logics.', })
except:
pass
Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

+596
View File
@@ -0,0 +1,596 @@
{
"last_node_id": 5,
"last_link_id": 5,
"nodes": [
{
"id": 1,
"type": "LoadImage",
"pos": [
30,
210
],
"size": [
390,
320
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"shape": 3,
"links": [
1
]
},
{
"name": "MASK",
"type": "MASK",
"shape": 3,
"links": [
2
]
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"clipspace/clipspace-mask-609196.2000000011.png [input]",
"image"
]
},
{
"id": 5,
"type": "PreviewImage",
"pos": [
1230,
210
],
"size": [
210,
246
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 5
}
],
"outputs": [],
"properties": {
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 3,
"type": "workflow>Impact::MAKE_BASIC_PIPE",
"pos": [
20,
620
],
"size": [
400,
200
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"shape": 3,
"links": [
3
]
}
],
"properties": {
"Node name for S&R": "workflow/Impact::MAKE_BASIC_PIPE"
},
"widgets_values": [
"SD1.5/realcartoon3d_v13.safetensors",
"(best quality:1.4), fox girl",
"(worst quality:1.4), nsfw"
]
},
{
"id": 2,
"type": "MaskDetailerPipe",
"pos": [
530,
210
],
"size": [
569.4000244140625,
850
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 1
},
{
"name": "mask",
"type": "MASK",
"link": 2
},
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"link": 3,
"slot_index": 2
},
{
"name": "refiner_basic_pipe_opt",
"type": "BASIC_PIPE",
"shape": 7,
"link": null
},
{
"name": "detailer_hook",
"type": "DETAILER_HOOK",
"shape": 7,
"link": null
},
{
"name": "scheduler_func_opt",
"type": "SCHEDULER_FUNC",
"shape": 7,
"link": null
}
],
"outputs": [
{
"name": "image",
"type": "IMAGE",
"shape": 3,
"links": [
5
],
"slot_index": 0
},
{
"name": "cropped_refined",
"type": "IMAGE",
"shape": 6,
"links": null
},
{
"name": "cropped_enhanced_alpha",
"type": "IMAGE",
"shape": 6,
"links": [
4
],
"slot_index": 2
},
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"shape": 3,
"links": null
},
{
"name": "refiner_basic_pipe_opt",
"type": "BASIC_PIPE",
"shape": 3,
"links": null
}
],
"properties": {
"Node name for S&R": "MaskDetailerPipe"
},
"widgets_values": [
512,
true,
1024,
true,
1003,
"fixed",
20,
8,
"euler",
"normal",
0.75,
5,
3,
10,
0.2,
1,
1,
false,
20,
false,
false
],
"color": "#322",
"bgcolor": "#533"
},
{
"id": 4,
"type": "PreviewImage",
"pos": [
1230,
560
],
"size": [
210,
246
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 4
}
],
"outputs": [],
"properties": {
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
}
],
"links": [
[
1,
1,
0,
2,
0,
"IMAGE"
],
[
2,
1,
1,
2,
1,
"MASK"
],
[
3,
3,
0,
2,
2,
"BASIC_PIPE"
],
[
4,
2,
2,
4,
0,
"IMAGE"
],
[
5,
2,
0,
5,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1,
"offset": [
80,
-110
]
},
"groupNodes": {
"Impact::MAKE_BASIC_PIPE": {
"author": "Dr.Lt.Data",
"category": "",
"config": {
"1": {
"input": {
"text": {
"name": "Positive prompt"
}
}
},
"2": {
"input": {
"text": {
"name": "Negative prompt"
}
}
}
},
"datetime": 1708272471445,
"external": [],
"links": [
[
0,
1,
1,
0,
1,
"CLIP"
],
[
0,
1,
2,
0,
1,
"CLIP"
],
[
0,
0,
3,
0,
1,
"MODEL"
],
[
0,
1,
3,
1,
1,
"CLIP"
],
[
0,
2,
3,
2,
1,
"VAE"
],
[
1,
0,
3,
3,
3,
"CONDITIONING"
],
[
2,
0,
3,
4,
4,
"CONDITIONING"
]
],
"nodes": [
{
"flags": {},
"index": 0,
"mode": 0,
"order": 0,
"outputs": [
{
"links": [],
"name": "MODEL",
"shape": 3,
"slot_index": 0,
"type": "MODEL",
"localized_name": "MODEL"
},
{
"links": [],
"name": "CLIP",
"shape": 3,
"slot_index": 1,
"type": "CLIP",
"localized_name": "CLIP"
},
{
"links": [],
"name": "VAE",
"shape": 3,
"slot_index": 2,
"type": "VAE",
"localized_name": "VAE"
}
],
"pos": [
550,
360
],
"properties": {
"Node name for S&R": "CheckpointLoaderSimple"
},
"size": {
"0": 315,
"1": 98
},
"type": "CheckpointLoaderSimple",
"widgets_values": [
"SDXL/sd_xl_base_1.0_0.9vae.safetensors"
],
"inputs": []
},
{
"flags": {},
"index": 1,
"inputs": [
{
"link": null,
"name": "clip",
"type": "CLIP",
"localized_name": "clip"
}
],
"mode": 0,
"order": 1,
"outputs": [
{
"links": [],
"name": "CONDITIONING",
"shape": 3,
"slot_index": 0,
"type": "CONDITIONING",
"localized_name": "CONDITIONING"
}
],
"pos": [
940,
480
],
"properties": {
"Node name for S&R": "CLIPTextEncode"
},
"size": {
"0": 263,
"1": 99
},
"title": "Positive",
"type": "CLIPTextEncode",
"widgets_values": [
""
]
},
{
"flags": {},
"index": 2,
"inputs": [
{
"link": null,
"name": "clip",
"type": "CLIP",
"localized_name": "clip"
}
],
"mode": 0,
"order": 2,
"outputs": [
{
"links": [],
"name": "CONDITIONING",
"shape": 3,
"slot_index": 0,
"type": "CONDITIONING",
"localized_name": "CONDITIONING"
}
],
"pos": [
940,
640
],
"properties": {
"Node name for S&R": "CLIPTextEncode"
},
"size": {
"0": 263,
"1": 99
},
"title": "Negative",
"type": "CLIPTextEncode",
"widgets_values": [
""
]
},
{
"flags": {},
"index": 3,
"inputs": [
{
"link": null,
"name": "model",
"type": "MODEL",
"localized_name": "model"
},
{
"link": null,
"name": "clip",
"type": "CLIP",
"localized_name": "clip"
},
{
"link": null,
"name": "vae",
"type": "VAE",
"localized_name": "vae"
},
{
"link": null,
"name": "positive",
"type": "CONDITIONING",
"localized_name": "positive"
},
{
"link": null,
"name": "negative",
"type": "CONDITIONING",
"localized_name": "negative"
}
],
"mode": 0,
"order": 3,
"outputs": [
{
"links": null,
"name": "basic_pipe",
"shape": 3,
"slot_index": 0,
"type": "BASIC_PIPE",
"localized_name": "basic_pipe"
}
],
"pos": [
1320,
360
],
"properties": {
"Node name for S&R": "ToBasicPipe"
},
"size": {
"0": 241.79998779296875,
"1": 106
},
"type": "ToBasicPipe"
}
],
"packname": "Impact",
"version": "1.0"
}
},
"controller_panel": {
"controllers": {},
"hidden": true,
"highlight": true,
"version": 2,
"default_order": []
},
"node_versions": {
"comfy-core": "0.3.14",
"comfyui-impact-pack": "1ae7cae2df8cca06027edfa3a24512671239d6c4"
},
"ue_links": [],
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 526 KiB

File diff suppressed because it is too large Load Diff
+46 -206
View File
@@ -5,7 +5,6 @@ import subprocess
import threading
import locale
import traceback
import re
if sys.argv[0] == 'install.py':
@@ -13,10 +12,24 @@ if sys.argv[0] == 'install.py':
impact_path = os.path.join(os.path.dirname(__file__), "modules")
old_subpack_path = os.path.join(os.path.dirname(__file__), "subpack")
subpack_path = os.path.join(os.path.dirname(__file__), "impact_subpack")
subpack_repo = "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
comfy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
comfy_path = os.environ.get('COMFYUI_PATH')
if comfy_path is None:
print(f"\nWARN: The `COMFYUI_PATH` environment variable is not set. Assuming `{os.path.dirname(__file__)}/../../` as the ComfyUI path.", file=sys.stderr)
comfy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
model_path = os.environ.get('COMFYUI_MODEL_PATH')
if model_path is None:
try:
import folder_paths
model_path = folder_paths.models_dir
except:
pass
if model_path is None:
model_path = os.path.abspath(os.path.join(comfy_path, 'models'))
print(f"\nWARN: The `COMFYUI_MODEL_PATH` environment variable is not set. Assuming `{model_path}` as the ComfyUI path.", file=sys.stderr)
sys.path.append(impact_path)
@@ -34,9 +47,9 @@ def handle_stream(stream, is_stdout):
print(msg, end="", file=sys.stderr)
def process_wrap(cmd_str, cwd=None, handler=None):
def process_wrap(cmd_str, cwd=None, handler=None, env=None):
print(f"[Impact Pack] EXECUTE: {cmd_str} in '{cwd}'")
process = subprocess.Popen(cmd_str, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
process = subprocess.Popen(cmd_str, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, text=True, bufsize=1)
if handler is None:
handler = handle_stream
@@ -54,222 +67,39 @@ def process_wrap(cmd_str, cwd=None, handler=None):
# ---
pip_list = None
def get_installed_packages():
global pip_list
if pip_list is None:
try:
result = subprocess.check_output([sys.executable, '-m', 'pip', 'list'], universal_newlines=True)
pip_list = set([line.split()[0].lower() for line in result.split('\n') if line.strip()])
except subprocess.CalledProcessError as e:
print(f"[ComfyUI-Manager] Failed to retrieve the information of installed pip packages.")
return set()
return pip_list
def is_installed(name):
name = name.strip()
pattern = r'([^<>!=]+)([<>!=]=?)'
match = re.search(pattern, name)
if match:
name = match.group(1)
result = name.lower() in get_installed_packages()
return result
def is_requirements_installed(file_path):
print(f"req_path: {file_path}")
if os.path.exists(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
for line in lines:
if not is_installed(line):
return False
return True
try:
import platform
import folder_paths
from torchvision.datasets.utils import download_url
import impact.config
print("### ComfyUI-Impact-Pack: Check dependencies")
if "python_embeded" in sys.executable or "python_embedded" in sys.executable:
pip_install = [sys.executable, '-s', '-m', 'pip', 'install']
mim_install = [sys.executable, '-s', '-m', 'mim', 'install']
else:
pip_install = [sys.executable, '-m', 'pip', 'install']
mim_install = [sys.executable, '-m', 'mim', 'install']
def ensure_subpack():
import git
if os.path.exists(subpack_path):
try:
repo = git.Repo(subpack_path)
repo.remotes.origin.pull()
except:
traceback.print_exc()
if platform.system() == 'Windows':
print(f"[ComfyUI-Impact-Pack] Please turn off ComfyUI and remove '{subpack_path}' and restart ComfyUI.")
else:
shutil.rmtree(subpack_path)
git.Repo.clone_from(subpack_repo, subpack_path)
else:
git.Repo.clone_from(subpack_repo, subpack_path)
if os.path.exists(old_subpack_path):
shutil.rmtree(old_subpack_path)
def remove_olds():
global comfy_path
comfy_path = os.path.dirname(folder_paths.__file__)
custom_nodes_path = os.path.join(comfy_path, "custom_nodes")
old_ini_path = os.path.join(custom_nodes_path, "impact-pack.ini")
old_py_path = os.path.join(custom_nodes_path, "comfyui-impact-pack.py")
if os.path.exists(impact.config.old_config_path):
impact.config.get_config()['mmdet_skip'] = False
os.remove(impact.config.old_config_path)
if os.path.exists(old_ini_path):
print(f"Delete legacy file: {old_ini_path}")
os.remove(old_ini_path)
if os.path.exists(old_py_path):
print(f"Delete legacy file: {old_py_path}")
os.remove(old_py_path)
def ensure_pip_packages_first():
subpack_req = os.path.join(subpack_path, "requirements.txt")
if os.path.exists(subpack_req) and not is_requirements_installed(subpack_req):
process_wrap(pip_install + ['-r', 'requirements.txt'], cwd=subpack_path)
if not impact.config.get_config()['mmdet_skip']:
process_wrap(pip_install + ['openmim'])
try:
import pycocotools
except Exception:
if platform.system() not in ["Windows"] or platform.machine() not in ["AMD64", "x86_64"]:
print(f"Your system is {platform.system()}; !! You need to install 'libpython3-dev' for this step. !!")
process_wrap(pip_install + ['pycocotools'])
else:
pycocotools = {
(3, 8): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp38-cp38-win_amd64.whl",
(3, 9): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp39-cp39-win_amd64.whl",
(3, 10): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp310-cp310-win_amd64.whl",
(3, 11): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp311-cp311-win_amd64.whl",
}
version = sys.version_info[:2]
url = pycocotools[version]
process_wrap(pip_install + [url])
def ensure_pip_packages_last():
my_path = os.path.dirname(__file__)
requirements_path = os.path.join(my_path, "requirements.txt")
if not is_requirements_installed(requirements_path):
process_wrap(pip_install + ['-r', requirements_path])
# fallback
try:
import segment_anything
from skimage.measure import label, regionprops
import piexif
except Exception:
process_wrap(pip_install + ['-r', requirements_path])
# !! cv2 importing test must be very last !!
try:
import cv2
except Exception:
try:
if not is_installed('opencv-python'):
process_wrap(pip_install + ['opencv-python'])
if not is_installed('opencv-python-headless'):
process_wrap(pip_install + ['opencv-python-headless'])
except:
print(f"[ERROR] ComfyUI-Impact-Pack: failed to install 'opencv-python'. Please, install manually.")
try:
import git
except Exception:
if not is_installed('gitpython'):
process_wrap(pip_install + ['gitpython'])
def ensure_mmdet_package():
try:
import mmcv
import mmdet
from mmdet.evaluation import get_classes
except Exception:
process_wrap(pip_install + ['opendatalab==0.0.9'])
process_wrap(pip_install + ['-U', 'openmim'])
process_wrap(mim_install + ['mmcv>=2.0.0rc4, <2.1.0'])
process_wrap(mim_install + ['mmdet==3.0.0'])
process_wrap(mim_install + ['mmengine==0.7.4'])
def install():
remove_olds()
subpack_install_script = os.path.join(subpack_path, "install.py")
print(f"### ComfyUI-Impact-Pack: Updating subpack")
ensure_subpack() # The installation of the subpack must take place before ensure_pip. cv2 triggers a permission error.
if os.path.exists(subpack_install_script):
process_wrap([sys.executable, 'install.py'], cwd=subpack_path)
if not is_requirements_installed(os.path.join(subpack_path, 'requirements.txt')):
process_wrap(pip_install + ['-r', 'requirements.txt'], cwd=subpack_path)
else:
print(f"### ComfyUI-Impact-Pack: (Install Failed) Subpack\nFile not found: `{subpack_install_script}`")
ensure_pip_packages_first()
if not impact.config.get_config()['mmdet_skip']:
ensure_mmdet_package()
ensure_pip_packages_last()
new_env = os.environ.copy()
new_env["COMFYUI_PATH"] = comfy_path
new_env["COMFYUI_MODEL_PATH"] = model_path
# Download model
print("### ComfyUI-Impact-Pack: Check basic models")
model_path = folder_paths.models_dir
bbox_path = os.path.join(model_path, "mmdets", "bbox")
sam_path = os.path.join(model_path, "sams")
onnx_path = os.path.join(model_path, "onnx")
if not os.path.exists(os.path.join(os.path.dirname(__file__), '..', 'skip_download_model')):
if not os.path.exists(bbox_path):
os.makedirs(bbox_path)
try:
if not impact.config.get_config()['mmdet_skip']:
bbox_path = os.path.join(model_path, "mmdets", "bbox")
if not os.path.exists(bbox_path):
os.makedirs(bbox_path)
if not impact.config.get_config()['mmdet_skip']:
if not os.path.exists(os.path.join(bbox_path, "mmdet_anime-face_yolov3.pth")):
download_url("https://huggingface.co/dustysys/ddetailer/resolve/main/mmdet/bbox/mmdet_anime-face_yolov3.pth", bbox_path)
if not os.path.exists(os.path.join(bbox_path, "mmdet_anime-face_yolov3.pth")):
download_url("https://huggingface.co/dustysys/ddetailer/resolve/main/mmdet/bbox/mmdet_anime-face_yolov3.pth", bbox_path)
if not os.path.exists(os.path.join(bbox_path, "mmdet_anime-face_yolov3.py")):
download_url("https://raw.githubusercontent.com/Bing-su/dddetailer/master/config/mmdet_anime-face_yolov3.py", bbox_path)
if not os.path.exists(os.path.join(bbox_path, "mmdet_anime-face_yolov3.py")):
download_url("https://raw.githubusercontent.com/Bing-su/dddetailer/master/config/mmdet_anime-face_yolov3.py", bbox_path)
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)
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.")
if not os.path.exists(onnx_path):
print(f"### ComfyUI-Impact-Pack: onnx model directory created ({onnx_path})")
@@ -277,6 +107,16 @@ 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.")
install()
-31
View File
@@ -1,31 +0,0 @@
import { ComfyApp, app } from "../../scripts/app.js";
let conflict_check = undefined;
app.registerExtension({
name: "Comfy.impact.comboBoolMigration",
nodeCreated(node, app) {
for(let i in node.widgets) {
let widget = node.widgets[i];
if(conflict_check == undefined) {
conflict_check = !!app.extensions.find((ext) => ext.name === "Comfy.comboBoolMigration");
}
if(conflict_check)
return;
if(widget.type == "toggle") {
let value = widget.value;
Object.defineProperty(widget, "value", {
set: (value) => {
delete widget.value;
widget.value = value == true || value == widget.options.on;
},
get: () => { return value; }
});
}
}
}
});
+59
View File
@@ -3,6 +3,48 @@ import { app } from "../../scripts/app.js";
let original_show = app.ui.dialog.show;
export function customAlert(message) {
try {
app.extensionManager.toast.addAlert(message);
}
catch {
alert(message);
}
}
export function isBeforeFrontendVersion(compareVersion) {
try {
const frontendVersion = window['__COMFYUI_FRONTEND_VERSION__'];
if (typeof frontendVersion !== 'string') {
return false;
}
function parseVersion(versionString) {
const parts = versionString.split('.').map(Number);
return parts.length === 3 && parts.every(part => !isNaN(part)) ? parts : null;
}
const currentVersion = parseVersion(frontendVersion);
const comparisonVersion = parseVersion(compareVersion);
if (!currentVersion || !comparisonVersion) {
return false;
}
for (let i = 0; i < 3; i++) {
if (currentVersion[i] > comparisonVersion[i]) {
return false;
} else if (currentVersion[i] < comparisonVersion[i]) {
return true;
}
}
return false;
} catch {
return true;
}
}
function dialog_show_wrapper(html) {
if (typeof html === "string") {
if(html.includes("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE")) {
@@ -53,6 +95,7 @@ async function bridgeContinue(event) {
if(node) {
const mutes = new Set(event.detail.mutes);
const actives = new Set(event.detail.actives);
const bypasses = new Set(event.detail.bypasses);
for(let i in app.graph._nodes_by_id) {
let this_node = app.graph._nodes_by_id[i];
@@ -62,6 +105,9 @@ async function bridgeContinue(event) {
else if(actives.has(i)) {
this_node.mode = 0;
}
else if(bypasses.has(i)) {
this_node.mode = 4;
}
}
await app.queuePrompt(0, 1);
@@ -76,3 +122,16 @@ function addQueue(event) {
}
api.addEventListener("impact-add-queue", addQueue);
function refreshPreview(event) {
let node_id = event.detail.node_id;
let item = event.detail.item;
let img = new Image();
img.src = `/view?filename=${item.filename}&subfolder=${item.subfolder}&type=${item.type}&no-cache=${Date.now()}`;
let node = app.graph._nodes_by_id[node_id];
if(node)
node.imgs = [img];
}
api.addEventListener("impact-preview", refreshPreview);
+34 -29
View File
@@ -9,31 +9,31 @@ function load_image(str) {
function getFileItem(baseType, path) {
try {
let pathType = baseType;
let pathType = baseType;
if (path.endsWith("[output]")) {
pathType = "output";
path = path.slice(0, -9);
} else if (path.endsWith("[input]")) {
pathType = "input";
path = path.slice(0, -8);
} else if (path.endsWith("[temp]")) {
pathType = "temp";
path = path.slice(0, -7);
}
if (path.endsWith("[output]")) {
pathType = "output";
path = path.slice(0, -9);
} else if (path.endsWith("[input]")) {
pathType = "input";
path = path.slice(0, -8);
} else if (path.endsWith("[temp]")) {
pathType = "temp";
path = path.slice(0, -7);
}
const subfolder = path.substring(0, path.lastIndexOf('/'));
const filename = path.substring(path.lastIndexOf('/') + 1);
const subfolder = path.substring(0, path.lastIndexOf('/'));
const filename = path.substring(path.lastIndexOf('/') + 1);
return {
filename: filename,
subfolder: subfolder,
type: pathType
};
}
catch(exception) {
return null;
}
return {
filename: filename,
subfolder: subfolder,
type: pathType
};
}
catch(exception) {
return null;
}
}
async function loadImageFromUrl(image, node_id, v, need_to_load) {
@@ -46,7 +46,7 @@ async function loadImageFromUrl(image, node_id, v, need_to_load) {
if(res.status == 200) {
let pb_id = await res.text();
if(need_to_load) {;
image.src = `view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`;
image.src = api.apiURL(`/view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`);
}
return pb_id;
}
@@ -63,7 +63,7 @@ async function loadImageFromId(image, v) {
let res = await api.fetchApi('/impact/get/pb_id_image?id='+v, { cache: "no-store" });
if(res.status == 200) {
let item = await res.json();
image.src = `view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`;
image.src = api.apiURL(`/view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`);
return true;
}
@@ -74,13 +74,16 @@ app.registerExtension({
name: "Comfy.Impact.img",
nodeCreated(node, app) {
if(node.comfyClass == "PreviewBridge") {
if(node.comfyClass == "PreviewBridge" || node.comfyClass == "PreviewBridgeLatent") {
let w = node.widgets.find(obj => obj.name === 'image');
node._imgs = [new Image()];
node.imageIndex = 0;
Object.defineProperty(w, 'value', {
async set(v) {
if(w._lock)
return;
const stackTrace = new Error().stack;
if(stackTrace.includes('presetText.js'))
return;
@@ -101,7 +104,9 @@ app.registerExtension({
}
else {
// from clipspace
w._lock = true;
w._value = await loadImageFromUrl(image, node.id, v, false);
w._lock = false;
}
},
get() {
@@ -176,7 +181,7 @@ app.registerExtension({
Object.defineProperty(node, 'imgs', {
set(v) {
if (!v[0].complete) {
if (v && !v[0].complete) {
let orig_onload = v[0].onload;
v[0].onload = function(v2) {
if(orig_onload)
@@ -204,7 +209,7 @@ app.registerExtension({
let res = api.fetchApi('/view/validate'+params, { cache: "no-store" }).then(response => response);
if(res.status == 200) {
image.src = 'view'+params;
image.src = api.apiURL('/view'+params);
}
this._img = [new Image()]; // placeholder
@@ -220,5 +225,5 @@ app.registerExtension({
}
});
}
}
})
}
})
+518 -380
View File
File diff suppressed because it is too large Load Diff
+18 -13
View File
@@ -1,4 +1,5 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
import { ComfyDialog, $el } from "../../scripts/ui.js";
import { ComfyApp } from "../../scripts/app.js";
import { ClipspaceDialog } from "../../extensions/core/clipspace.js";
@@ -42,7 +43,7 @@ function loadedImageToBlob(image) {
}
async function uploadMask(filepath, formData) {
await fetch('/upload/mask', {
await api.fetchApi('/upload/mask', {
method: 'POST',
body: formData
}).then(response => {}).catch(error => {
@@ -261,7 +262,7 @@ class ImpactSamEditorDialog extends ComfyDialog {
const pointsCanvas = document.createElement('canvas');
imgCanvas.id = "imageCanvas";
maskCanvas.id = "maskCanvas";
maskCanvas.id = "samEditorMaskCanvas";
pointsCanvas.id = "pointsCanvas";
this.setlayout(imgCanvas, maskCanvas, pointsCanvas);
@@ -352,13 +353,16 @@ class ImpactSamEditorDialog extends ComfyDialog {
imgCtx.drawImage(orig_image, 0, 0, drawWidth, drawHeight);
// update mask
pointsCanvas.width = drawWidth;
pointsCanvas.height = drawHeight;
let w = (drawWidth * imgCanvas.clientWidth/imgCanvas.width) + "px";
let h = (drawHeight * imgCanvas.clientHeight/imgCanvas.height) + "px";
pointsCanvas.width = drawWidth * imgCanvas.clientWidth/imgCanvas.width;
pointsCanvas.height = drawHeight * imgCanvas.clientHeight/imgCanvas.height;
pointsCanvas.style.top = imgCanvas.offsetTop + "px";
pointsCanvas.style.left = imgCanvas.offsetLeft + "px";
maskCanvas.width = drawWidth;
maskCanvas.height = drawHeight;
maskCanvas.width = pointsCanvas.width;
maskCanvas.height = pointsCanvas.height;
maskCanvas.style.top = imgCanvas.offsetTop + "px";
maskCanvas.style.left = imgCanvas.offsetLeft + "px";
@@ -434,7 +438,7 @@ class ImpactSamEditorDialog extends ComfyDialog {
ctx.arc(scaledX, scaledY, 3, 0, 3 * Math.PI);
ctx.fill();
}
}줘
}
invalidateMaskCanvas(self) {
if(self.mask_image) {
@@ -458,7 +462,7 @@ class ImpactSamEditorDialog extends ComfyDialog {
subfolder: subfolder
};
fetch('/sam/prepare', {
api.fetchApi('/sam/prepare', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
@@ -472,8 +476,9 @@ class ImpactSamEditorDialog extends ComfyDialog {
for(const i in self.prompt_points) {
const [is_positive, x, y] = self.prompt_points[i];
const point = [x,y];
if(is_positive)
if(is_positive) {
positive_points.push(point);
}
else
negative_points.push(point);
}
@@ -484,7 +489,7 @@ class ImpactSamEditorDialog extends ComfyDialog {
threshold: self.confidence/100
};
const response = await fetch('/sam/detect', {
const response = await api.fetchApi('/sam/detect', {
method: 'POST',
headers: { 'Content-Type': 'image/png' },
body: JSON.stringify(data)
@@ -507,8 +512,8 @@ class ImpactSamEditorDialog extends ComfyDialog {
const x = event.offsetX || event.targetTouches[0].clientX - maskRect.left;
const y = event.offsetY || event.targetTouches[0].clientY - maskRect.top;
const originalX = x * self.image.width / self.pointsCanvas.width;
const originalY = y * self.image.height / self.pointsCanvas.height;
const originalX = x * self.image.width / self.pointsCanvas.clientWidth;
const originalY = y * self.image.height / self.pointsCanvas.clientHeight;
var point = null;
if (event.button == 0) {
@@ -617,7 +622,7 @@ app.registerExtension({
},
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.output.includes("MASK") && nodeData.output.includes("IMAGE")) {
if (Array.isArray(nodeData.output) && (nodeData.output.includes("MASK") || nodeData.output.includes("IMAGE"))) {
addMenuHandler(nodeType, function (_, options) {
options.unshift({
content: "Open in SAM Detector",
+381
View File
@@ -0,0 +1,381 @@
import { app } from "/scripts/app.js";
function showPreviewCanvas(node, app) {
const widget = {
type: "customCanvas",
name: "mask-rect-area-canvas",
get value() {
return this.canvas.value;
},
set value(x) {
this.canvas.value = x;
},
draw: function (ctx, node, widgetWidth, widgetY) {
// If we are initially offscreen when created we wont have received a resize event
// Calculate it here instead
if (!node.canvasHeight) {
computeCanvasSize(node, node.size);
}
const visible = true;
const t = ctx.getTransform();
const margin = 12;
const border = 2;
const widgetHeight = node.canvasHeight;
const width = Math.round(node.properties["width"]);
const height = Math.round(node.properties["height"]);
const scale = Math.min((widgetWidth - margin * 3) / width, (widgetHeight - margin * 3) / height);
const blurRadius = node.properties["blur_radius"] || 0;
const index = 0;
Object.assign(this.canvas.style, {
left: `${t.e}px`,
top: `${t.f + (widgetY * t.d)}px`,
width: `${widgetWidth * t.a}px`,
height: `${widgetHeight * t.d}px`,
position: "absolute",
zIndex: 1,
fontSize: `${t.d * 10.0}px`,
pointerEvents: "none"
});
this.canvas.hidden = !visible;
let backgroundWidth = width * scale;
let backgroundHeight = height * scale;
let xOffset = margin;
if (backgroundWidth < widgetWidth) {
xOffset += (widgetWidth - backgroundWidth) / 2 - margin;
}
let yOffset = (margin / 2);
if (backgroundHeight < widgetHeight) {
yOffset += (widgetHeight - backgroundHeight) / 2 - margin;
}
let widgetX = xOffset;
widgetY = widgetY + yOffset;
// Draw the background border
ctx.fillStyle = globalThis.LiteGraph.WIDGET_OUTLINE_COLOR;
ctx.fillRect(widgetX - border, widgetY - border, backgroundWidth + border * 2, backgroundHeight + border * 2)
// Draw the main background area
ctx.fillStyle = globalThis.LiteGraph.WIDGET_BGCOLOR;
ctx.fillRect(widgetX, widgetY, backgroundWidth, backgroundHeight);
// Draw the conditioning zone
let [x, y, w, h] = getDrawArea(node, backgroundWidth, backgroundHeight);
ctx.fillStyle = getDrawColor(0, "80");
ctx.fillRect(widgetX + x, widgetY + y, w, h);
ctx.beginPath();
ctx.lineWidth = 1;
// Draw grid lines
for (let x = 0; x <= width / 64; x += 1) {
ctx.moveTo(widgetX + x * 64 * scale, widgetY);
ctx.lineTo(widgetX + x * 64 * scale, widgetY + backgroundHeight);
}
for (let y = 0; y <= height / 64; y += 1) {
ctx.moveTo(widgetX, widgetY + y * 64 * scale);
ctx.lineTo(widgetX + backgroundWidth, widgetY + y * 64 * scale);
}
ctx.strokeStyle = "#66666650";
ctx.stroke();
ctx.closePath();
// Draw current zone
let [sx, sy, sw, sh] = getDrawArea(node, backgroundWidth, backgroundHeight);
ctx.fillStyle = getDrawColor(0, "80");
ctx.fillRect(widgetX + sx, widgetY + sy, sw, sh);
ctx.fillStyle = getDrawColor(0, "40");
ctx.fillRect(widgetX + sx + border, widgetY + sy + border, sw - border * 2, sh - border * 2);
// Draw white border around the current zone
ctx.strokeStyle = globalThis.LiteGraph.NODE_SELECTED_TITLE_COLOR;
ctx.lineWidth = 2;
ctx.strokeRect(widgetX + sx, widgetY + sy, sw, sh);
// Display
ctx.beginPath();
ctx.arc(LiteGraph.NODE_SLOT_HEIGHT * 0.5, LiteGraph.NODE_SLOT_HEIGHT * (index + 0.5) + 4, 4, 0, Math.PI * 2);
ctx.fill();
ctx.lineWidth = 1;
ctx.strokeStyle = "white";
ctx.stroke();
ctx.lineWidth = 1;
ctx.closePath();
// Draw progress bar canvas
if (backgroundWidth < widgetWidth) {
xOffset += (widgetWidth - backgroundWidth) / 2 - margin;
}
// Ajustar las coordenadas X e Y
const barHeight = 8;
let widgetYBar = widgetY + backgroundHeight + margin;
// Dibujar el borde negro alrededor de la barra
ctx.fillStyle = globalThis.LiteGraph.WIDGET_OUTLINE_COLOR;
ctx.fillRect(
widgetX - border,
widgetYBar - border,
backgroundWidth + border * 2,
barHeight + border * 2
);
// Dibujar el área principal de la barra (fondo)
ctx.fillStyle = globalThis.LiteGraph.WIDGET_BGCOLOR; // Mismo color de fondo que el canvas
ctx.fillRect(
widgetX,
widgetYBar,
backgroundWidth,
barHeight
);
// Draw progress bar grid
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = "#66666650";
// Calcular el número de líneas en función del tamaño de la barra
const numLines = Math.floor(backgroundWidth / 64);
// Dibujar líneas del grid
for (let x = 0; x <= width / 64; x += 1) {
ctx.moveTo(widgetX + x * 64 * scale, widgetYBar);
ctx.lineTo(widgetX + x * 64 * scale, widgetYBar + barHeight);
}
ctx.stroke();
ctx.closePath();
// Dibujar progreso (basado en blur_radius)
const progress = Math.min(blurRadius / 255, 1);
ctx.fillStyle = "rgba(0, 120, 255, 0.5)";
ctx.fillRect(
widgetX,
widgetYBar,
backgroundWidth * progress,
barHeight
);
}
};
widget.canvas = document.createElement("canvas");
widget.canvas.className = "mask-rect-area-canvas";
widget.parent = node;
document.body.appendChild(widget.canvas);
node.addCustomWidget(widget);
app.canvas.onDrawBackground = function () {
// Draw node isnt fired once the node is off the screen
// if it goes off screen quickly, the input may not be removed
// this shifts it off screen so it can be moved back if the node is visible.
for (let n in app.graph._nodes) {
n = app.graph._nodes[n];
for (let w in n.widgets) {
let wid = n.widgets[w];
if (Object.hasOwn(wid, "canvas")) {
wid.canvas.style.left = -8000 + "px";
wid.canvas.style.position = "absolute";
}
}
}
};
node.onResize = function (size) {
computeCanvasSize(node, size);
};
return {minWidth: 200, minHeight: 200, widget};
}
app.registerExtension({
name: 'drltdata.MaskRectAreaAdvanced',
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "MaskRectAreaAdvanced") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
this.setProperty("width", 512);
this.setProperty("height", 512);
this.setProperty("x", 0);
this.setProperty("y", 0);
this.setProperty("w", 256);
this.setProperty("h", 256);
this.setProperty("blur_radius", 0);
this.selected = false;
this.index = 3;
this.serialize_widgets = true;
CUSTOM_INT(this, "x", 0, function (v, _, node) {
const s = this.options.step / 10;
this.value = Math.round(v / s) * s;
node.properties["x"] = this.value;
});
CUSTOM_INT(this, "y", 0, function (v, _, node) {
const s = this.options.step / 10;
this.value = Math.round(v / s) * s;
node.properties["y"] = this.value;
});
CUSTOM_INT(this, "width", 256, function (v, _, node) {
const s = this.options.step / 10;
this.value = Math.round(v / s) * s;
node.properties["w"] = this.value;
});
CUSTOM_INT(this, "height", 256, function (v, _, node) {
const s = this.options.step / 10;
this.value = Math.round(v / s) * s;
node.properties["h"] = this.value;
});
CUSTOM_INT(this, "image_width", 512, function (v, _, node) {
const s = this.options.step / 10;
this.value = Math.round(v / s) * s;
node.properties["width"] = this.value;
});
CUSTOM_INT(this, "image_height", 512, function (v, _, node) {
const s = this.options.step / 10;
this.value = Math.round(v / s) * s;
node.properties["height"] = this.value;
});
CUSTOM_INT(this, "blur_radius", 0, function (v, _, node) {
this.value = Math.round(v) || 0;
node.properties["blur_radius"] = this.value;
},
{"min": 0, "max": 255, "step": 10}
);
showPreviewCanvas(this, app);
this.onSelected = function () {
this.selected = true;
};
this.onDeselected = function () {
this.selected = false;
};
return r;
};
}
}
});
// Calculate the drawing area using individual properties.
function getDrawArea(node, backgroundWidth, backgroundHeight) {
let x = node.properties["x"] * backgroundWidth / node.properties["width"];
let y = node.properties["y"] * backgroundHeight / node.properties["height"];
let w = node.properties["w"] * backgroundWidth / node.properties["width"];
let h = node.properties["h"] * backgroundHeight / node.properties["height"];
if (x > backgroundWidth) {
x = backgroundWidth;
}
if (y > backgroundHeight) {
y = backgroundHeight;
}
if (x + w > backgroundWidth) {
w = Math.max(0, backgroundWidth - x);
}
if (y + h > backgroundHeight) {
h = Math.max(0, backgroundHeight - y);
}
return [x, y, w, h];
}
function CUSTOM_INT(node, inputName, val, func, config = {}) {
return {
widget: node.addWidget(
"number",
inputName,
val,
func,
Object.assign({}, {min: 0, max: 4096, step: 640, precision: 0}, config)
)
};
}
function getDrawColor(percent, alpha) {
let h = 360 * percent;
let s = 50;
let l = 50;
l /= 100;
const a = s * Math.min(l, 1 - l) / 100;
const f = n => {
const k = (n + h / 30) % 12;
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
return Math.round(255 * color).toString(16).padStart(2, '0'); // convert to Hex and prefix "0" if needed
};
return `#${f(0)}${f(8)}${f(4)}${alpha}`;
}
function computeCanvasSize(node, size) {
if (node.widgets[0].last_y == null) {
return;
}
const MIN_HEIGHT = 220;
const MIN_WIDTH = 240;
let y = LiteGraph.NODE_WIDGET_HEIGHT * Math.max(node.inputs.length, node.outputs.length) + 5;
let freeSpace = size[1] - y;
// Compute the height of all non-customCanvas widgets
let widgetHeight = 0;
for (let i = 0; i < node.widgets.length; i++) {
const w = node.widgets[i];
if (w.type !== "customCanvas") {
if (w.computeSize) {
widgetHeight += w.computeSize()[1] + 4;
} else {
widgetHeight += LiteGraph.NODE_WIDGET_HEIGHT + 5;
}
}
}
// Ensure there is enough vertical space
freeSpace -= widgetHeight;
// Adjust the height of the node if needed
if (freeSpace < MIN_HEIGHT) {
freeSpace = MIN_HEIGHT;
node.size[1] = y + widgetHeight + freeSpace;
node.graph.setDirtyCanvas(true);
}
// Ensure the node width meets the minimum width requirement
if (node.size[0] < MIN_WIDTH) {
node.size[0] = MIN_WIDTH;
node.graph.setDirtyCanvas(true);
}
// Position each of the widgets
for (const w of node.widgets) {
w.y = y;
if (w.type === "customCanvas") {
y += freeSpace;
} else if (w.computeSize) {
y += w.computeSize()[1] + 4;
} else {
y += LiteGraph.NODE_WIDGET_HEIGHT + 4;
}
}
node.canvasHeight = freeSpace;
}
+366
View File
@@ -0,0 +1,366 @@
import { app } from "/scripts/app.js";
function showPreviewCanvas(node, app) {
const widget = {
type: "customCanvas",
name: "mask-rect-area-canvas",
get value() {
return this.canvas.value;
},
set value(x) {
this.canvas.value = x;
},
draw: function (ctx, node, widgetWidth, widgetY) {
// If we are initially offscreen when created we wont have received a resize event
// Calculate it here instead
if (!node.canvasHeight) {
computeCanvasSize(node, node.size);
}
const visible = true;
const t = ctx.getTransform();
const margin = 12;
const border = 2;
const widgetHeight = node.canvasHeight;
const width = 512;
const height = 512;
const scale = Math.min((widgetWidth - margin * 3) / width, (widgetHeight - margin * 3) / height);
const blurRadius = node.properties["blur_radius"] || 0;
const index = 0;
Object.assign(this.canvas.style, {
left: `${t.e}px`,
top: `${t.f + (widgetY * t.d)}px`,
width: `${widgetWidth * t.a}px`,
height: `${widgetHeight * t.d}px`,
position: "absolute",
zIndex: 1,
fontSize: `${t.d * 10.0}px`,
pointerEvents: "none"
});
this.canvas.hidden = !visible;
let backgroundWidth = width * scale;
let backgroundHeight = height * scale;
let xOffset = margin;
if (backgroundWidth < widgetWidth) {
xOffset += (widgetWidth - backgroundWidth) / 2 - margin;
}
let yOffset = (margin / 2);
if (backgroundHeight < widgetHeight) {
yOffset += (widgetHeight - backgroundHeight) / 2 - margin;
}
let widgetX = xOffset;
widgetY = widgetY + yOffset;
// Draw the background border
ctx.fillStyle = globalThis.LiteGraph.WIDGET_OUTLINE_COLOR;
ctx.fillRect(widgetX - border, widgetY - border, backgroundWidth + border * 2, backgroundHeight + border * 2);
// Draw the main background area
ctx.fillStyle = globalThis.LiteGraph.WIDGET_BGCOLOR;
ctx.fillRect(widgetX, widgetY, backgroundWidth, backgroundHeight);
// Draw the conditioning zone
let [x, y, w, h] = getDrawArea(node, backgroundWidth, backgroundHeight);
ctx.fillStyle = getDrawColor(0, "80");
ctx.fillRect(widgetX + x, widgetY + y, w, h);
ctx.beginPath();
ctx.lineWidth = 1;
// Draw grid lines
for (let x = 0; x <= width / 64; x += 1) {
ctx.moveTo(widgetX + x * 64 * scale, widgetY);
ctx.lineTo(widgetX + x * 64 * scale, widgetY + backgroundHeight);
}
for (let y = 0; y <= height / 64; y += 1) {
ctx.moveTo(widgetX, widgetY + y * 64 * scale);
ctx.lineTo(widgetX + backgroundWidth, widgetY + y * 64 * scale);
}
ctx.strokeStyle = "#66666650";
ctx.stroke();
ctx.closePath();
// Draw current zone
let [sx, sy, sw, sh] = getDrawArea(node, backgroundWidth, backgroundHeight);
ctx.fillStyle = getDrawColor(0, "80");
ctx.fillRect(widgetX + sx, widgetY + sy, sw, sh);
ctx.fillStyle = getDrawColor(0, "40");
ctx.fillRect(widgetX + sx + border, widgetY + sy + border, sw - border * 2, sh - border * 2);
// Draw white border around the current zone
ctx.strokeStyle = globalThis.LiteGraph.NODE_SELECTED_TITLE_COLOR;
ctx.lineWidth = 2;
ctx.strokeRect(widgetX + sx, widgetY + sy, sw, sh);
//ctx.strokeRect(finalSX, finalSY, finalSW, finalSH);
// Display
ctx.beginPath();
ctx.arc(LiteGraph.NODE_SLOT_HEIGHT * 0.5, LiteGraph.NODE_SLOT_HEIGHT * (index + 0.5) + 4, 4, 0, Math.PI * 2);
ctx.fill();
ctx.lineWidth = 1;
ctx.strokeStyle = "white";
ctx.stroke();
ctx.lineWidth = 1;
ctx.closePath();
// Draw progress bar canvas
if (backgroundWidth < widgetWidth) {
xOffset += (widgetWidth - backgroundWidth) / 2 - margin;
}
const barHeight = 8;
let widgetYBar = widgetY + backgroundHeight + margin;
// Draw progress bar border
ctx.fillStyle = globalThis.LiteGraph.WIDGET_OUTLINE_COLOR;
ctx.fillRect(
widgetX - border,
widgetYBar - border,
backgroundWidth + border * 2,
barHeight + border * 2
);
// Draw progress bar area
ctx.fillStyle = globalThis.LiteGraph.WIDGET_BGCOLOR; // Mismo color de fondo que el canvas
ctx.fillRect(
widgetX,
widgetYBar,
backgroundWidth,
barHeight
);
// Draw progress bar grid
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = "#66666650";
// Determine max lines
const numLines = Math.floor(backgroundWidth / 64);
// Draw progress bar grid
for (let x = 0; x <= width / 64; x += 1) {
ctx.moveTo(widgetX + x * 64 * scale, widgetYBar);
ctx.lineTo(widgetX + x * 64 * scale, widgetYBar + barHeight);
}
ctx.stroke();
ctx.closePath();
// Draw progress bar
const progress = Math.min(blurRadius / 255, 1);
ctx.fillStyle = "rgba(0, 120, 255, 0.5)";
ctx.fillRect(
widgetX,
widgetYBar,
backgroundWidth * progress,
barHeight
);
}
};
widget.canvas = document.createElement("canvas");
widget.canvas.className = "mask-rect-area-canvas";
widget.parent = node;
document.body.appendChild(widget.canvas);
node.addCustomWidget(widget);
app.canvas.onDrawBackground = function () {
// Draw node isnt fired once the node is off the screen
// if it goes off screen quickly, the input may not be removed
// this shifts it off screen so it can be moved back if the node is visible.
for (let n in app.graph._nodes) {
n = app.graph._nodes[n];
for (let w in n.widgets) {
let wid = n.widgets[w];
if (Object.hasOwn(wid, "canvas")) {
wid.canvas.style.left = -8000 + "px";
wid.canvas.style.position = "absolute";
}
}
}
};
node.onResize = function (size) {
computeCanvasSize(node, size);
};
return {minWidth: 200, minHeight: 200, widget};
}
app.registerExtension({
name: 'drltdata.MaskRectArea',
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "MaskRectArea") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
this.setProperty("width", 512);
this.setProperty("height", 512);
this.setProperty("x", 0);
this.setProperty("y", 0);
this.setProperty("w", 50);
this.setProperty("h", 50);
this.setProperty("blur_radius", 0);
this.selected = false;
this.index = 3;
this.serialize_widgets = true;
CUSTOM_INT(this, "x", 0, function (v, _, node) {
this.value = Math.max(0, Math.min(100, Math.round(v))); // Limitar entre 0 y 100
node.properties["x"] = this.value;
});
CUSTOM_INT(this, "y", 0, function (v, _, node) {
this.value = Math.max(0, Math.min(100, Math.round(v)));
node.properties["y"] = this.value;
});
CUSTOM_INT(this, "w", 50, function (v, _, node) {
this.value = Math.max(0, Math.min(100, Math.round(v)));
node.properties["w"] = this.value;
});
CUSTOM_INT(this, "h", 50, function (v, _, node) {
this.value = Math.max(0, Math.min(100, Math.round(v)));
node.properties["h"] = this.value;
});
CUSTOM_INT(this, "blur_radius", 0, function (v, _, node) {
this.value = Math.round(v) || 0;
node.properties["blur_radius"] = this.value;
},
{"min": 0, "max": 255, "step": 10}
);
showPreviewCanvas(this, app);
this.onSelected = function () {
this.selected = true;
};
this.onDeselected = function () {
this.selected = false;
};
return r;
};
}
}
});
// Calculate the drawing area using percentage-based properties.
function getDrawArea(node, backgroundWidth, backgroundHeight) {
// Convert percentages to actual pixel values based on the background dimensions
let x = (node.properties["x"] / 100) * backgroundWidth;
let y = (node.properties["y"] / 100) * backgroundHeight;
let w = (node.properties["w"] / 100) * backgroundWidth;
let h = (node.properties["h"] / 100) * backgroundHeight;
// Ensure the values do not exceed the background boundaries
if (x > backgroundWidth) {
x = backgroundWidth;
}
if (y > backgroundHeight) {
y = backgroundHeight;
}
// Adjust width and height to fit within the background dimensions
if (x + w > backgroundWidth) {
w = Math.max(0, backgroundWidth - x);
}
if (y + h > backgroundHeight) {
h = Math.max(0, backgroundHeight - y);
}
return [x, y, w, h];
}
function CUSTOM_INT(node, inputName, val, func, config = {}) {
return {
widget: node.addWidget(
"number",
inputName,
val,
func,
Object.assign({}, {min: 0, max: 100, step: 10, precision: 0}, config)
)
};
}
function getDrawColor(percent, alpha) {
let h = 360 * percent;
let s = 50;
let l = 50;
l /= 100;
const a = s * Math.min(l, 1 - l) / 100;
const f = n => {
const k = (n + h / 30) % 12;
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
return Math.round(255 * color).toString(16).padStart(2, '0'); // convert to Hex and prefix "0" if needed
};
return `#${f(0)}${f(8)}${f(4)}${alpha}`;
}
function computeCanvasSize(node, size) {
if (node.widgets[0].last_y == null) {
return;
}
const MIN_HEIGHT = 200;
const MIN_WIDTH = 200;
let y = LiteGraph.NODE_WIDGET_HEIGHT * Math.max(node.inputs.length, node.outputs.length) + 5;
let freeSpace = size[1] - y;
// Compute the height of all non-customCanvas widgets
let widgetHeight = 0;
for (let i = 0; i < node.widgets.length; i++) {
const w = node.widgets[i];
if (w.type !== "customCanvas") {
if (w.computeSize) {
widgetHeight += w.computeSize()[1] + 4;
} else {
widgetHeight += LiteGraph.NODE_WIDGET_HEIGHT + 5;
}
}
}
// Ensure there is enough vertical space
freeSpace -= widgetHeight;
// Adjust the height of the node if needed
if (freeSpace < MIN_HEIGHT) {
freeSpace = MIN_HEIGHT;
node.size[1] = y + widgetHeight + freeSpace;
node.graph.setDirtyCanvas(true);
}
// Ensure the node width meets the minimum width requirement
if (node.size[0] < MIN_WIDTH) {
node.size[0] = MIN_WIDTH;
node.graph.setDirtyCanvas(true);
}
// Position each of the widgets
for (const w of node.widgets) {
w.y = y;
if (w.type === "customCanvas") {
y += freeSpace;
} else if (w.computeSize) {
y += w.computeSize()[1] + 4;
} else {
y += LiteGraph.NODE_WIDGET_HEIGHT + 4;
}
}
node.canvasHeight = freeSpace;
}
File diff suppressed because it is too large Load Diff
+197
View File
@@ -0,0 +1,197 @@
from nodes import MAX_RESOLUTION
from impact.utils import *
import impact.core as core
from impact.core import SEG
from impact.segs_nodes import SEGSPaste
try:
from comfy_extras import nodes_differential_diffusion
except Exception:
print(f"\n#############################################\n[Impact Pack] ComfyUI is an outdated version.\n#############################################\n")
raise Exception("[Impact Pack] ComfyUI is an outdated version.")
class SEGSDetailerForAnimateDiff:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"image_frames": ("IMAGE", ),
"segs": ("SEGS", ),
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": MAX_RESOLUTION, "step": 8}),
"guide_size_for": ("BOOLEAN", {"default": True, "label_on": "bbox", "label_off": "crop_region"}),
"max_size": ("FLOAT", {"default": 768, "min": 64, "max": MAX_RESOLUTION, "step": 8}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
"scheduler": (core.SCHEDULERS,),
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
"basic_pipe": ("BASIC_PIPE", {"tooltip": "If the `ImpactDummyInput` is connected to the model in the basic_pipe, the inference stage is skipped."}),
"refiner_ratio": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0}),
},
"optional": {
"refiner_basic_pipe_opt": ("BASIC_PIPE",),
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
"scheduler_func_opt": ("SCHEDULER_FUNC",),
}
}
RETURN_TYPES = ("SEGS", "IMAGE")
RETURN_NAMES = ("segs", "cnet_images")
OUTPUT_IS_LIST = (False, True)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detailer"
DESCRIPTION = "This node enhances details by inpainting each region within the detected area bundle (SEGS) after enlarging them based on the guide size.\nThis node is applied specifically to SEGS rather than the entire image. To apply it to the entire image, use the 'SEGS Paste' node.\nAs a specialized detailer node for improving video details, such as in AnimateDiff, this node can handle cases where the masks contained in SEGS serve as batch masks spanning multiple frames."
@staticmethod
def do_detail(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
denoise, basic_pipe, refiner_ratio=None, refiner_basic_pipe_opt=None, noise_mask_feather=0, scheduler_func_opt=None):
model, clip, vae, positive, negative = basic_pipe
if refiner_basic_pipe_opt is None:
refiner_model, refiner_clip, refiner_positive, refiner_negative = None, None, None, None
else:
refiner_model, refiner_clip, _, refiner_positive, refiner_negative = refiner_basic_pipe_opt
segs = core.segs_scale_match(segs, image_frames.shape)
new_segs = []
cnet_image_list = []
if not (isinstance(model, str) and model == "DUMMY") and noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
for seg in segs[1]:
cropped_image_frames = None
for image in image_frames:
image = image.unsqueeze(0)
cropped_image = seg.cropped_image if seg.cropped_image is not None else crop_tensor4(image, seg.crop_region)
cropped_image = to_tensor(cropped_image)
if cropped_image_frames is None:
cropped_image_frames = cropped_image
else:
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
]
if not (isinstance(model, str) and model == "DUMMY"):
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,
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,
noise_mask_feather=noise_mask_feather, scheduler_func=scheduler_func_opt)
else:
enhanced_image_tensor = cropped_image_frames
cnet_images = None
if cnet_images is not None:
cnet_image_list.extend(cnet_images)
if enhanced_image_tensor is None:
new_cropped_image = cropped_image_frames
else:
new_cropped_image = enhanced_image_tensor.cpu().numpy()
new_seg = SEG(new_cropped_image, seg.cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, None)
new_segs.append(new_seg)
return (segs[0], new_segs), cnet_image_list
def doit(self, image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
denoise, basic_pipe, refiner_ratio=None, refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
segs, cnet_images = SEGSDetailerForAnimateDiff.do_detail(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name,
scheduler, denoise, basic_pipe, refiner_ratio, refiner_basic_pipe_opt,
noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
if len(cnet_images) == 0:
cnet_images = [empty_pil_tensor()]
return (segs, cnet_images)
class DetailerForEachPipeForAnimateDiff:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"image_frames": ("IMAGE", ),
"segs": ("SEGS", ),
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
"guide_size_for": ("BOOLEAN", {"default": True, "label_on": "bbox", "label_off": "crop_region"}),
"max_size": ("FLOAT", {"default": 1024, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
"scheduler": (core.SCHEDULERS,),
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
"feather": ("INT", {"default": 5, "min": 0, "max": 100, "step": 1}),
"basic_pipe": ("BASIC_PIPE", {"tooltip": "If the `ImpactDummyInput` is connected to the model in the basic_pipe, the inference stage is skipped."}),
"refiner_ratio": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0}),
},
"optional": {
"detailer_hook": ("DETAILER_HOOK",),
"refiner_basic_pipe_opt": ("BASIC_PIPE",),
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
"scheduler_func_opt": ("SCHEDULER_FUNC",),
}
}
RETURN_TYPES = ("IMAGE", "SEGS", "BASIC_PIPE", "IMAGE")
RETURN_NAMES = ("image", "segs", "basic_pipe", "cnet_images")
OUTPUT_IS_LIST = (False, False, False, True)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detailer"
DESCRIPTION = "This node enhances details by inpainting each region within the detected area bundle (SEGS) after enlarging them based on the guide size.\nThis node is a specialized detailer node for enhancing video details, such as in AnimateDiff. It can handle cases where the masks contained in SEGS serve as batch masks spanning multiple frames."
@staticmethod
def doit(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
denoise, feather, basic_pipe, refiner_ratio=None, detailer_hook=None, refiner_basic_pipe_opt=None,
noise_mask_feather=0, scheduler_func_opt=None):
enhanced_segs = []
cnet_image_list = []
for sub_seg in segs[1]:
single_seg = segs[0], [sub_seg]
enhanced_seg, cnet_images = SEGSDetailerForAnimateDiff().do_detail(image_frames, single_seg, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
denoise, basic_pipe, refiner_ratio, refiner_basic_pipe_opt, noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
image_frames = SEGSPaste.doit(image_frames, enhanced_seg, feather, alpha=255)[0]
if cnet_images is not None:
cnet_image_list.extend(cnet_images)
if detailer_hook is not None:
image_frames = detailer_hook.post_paste(image_frames)
enhanced_segs += enhanced_seg[1]
new_segs = segs[0], enhanced_segs
return image_frames, new_segs, basic_pipe, cnet_image_list
+390
View File
@@ -0,0 +1,390 @@
import os
from PIL import ImageOps
from impact.utils import *
import latent_preview
# NOTE: this should not be `from . import core`.
# I don't know why but... 'from .' and 'from impact' refer to different core modules.
# This separates global variables of the core module and breaks the preview bridge.
from impact import core
# <--
import random
class PreviewBridge:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"images": ("IMAGE",),
"image": ("STRING", {"default": ""}),
},
"optional": {
"block": ("BOOLEAN", {"default": False, "label_on": "if_empty_mask", "label_off": "never", "tooltip": "is_empty_mask: If the mask is empty, the execution is stopped.\nnever: The execution is never stopped."}),
"restore_mask": (["never", "always", "if_same_size"], {"tooltip": "if_same_size: If the changed input image is the same size as the previous image, restore using the last saved mask\nalways: Whenever the input image changes, always restore using the last saved mask\nnever: Do not restore the mask.\n`restore_mask` has higher priority than `block`"}),
},
"hidden": {"unique_id": "UNIQUE_ID", "extra_pnginfo": "EXTRA_PNGINFO"},
}
RETURN_TYPES = ("IMAGE", "MASK", )
FUNCTION = "doit"
OUTPUT_NODE = True
CATEGORY = "ImpactPack/Util"
DESCRIPTION = "This is a feature that allows you to edit and send a Mask over a image.\nIf the block is set to 'is_empty_mask', the execution is stopped when the mask is empty."
def __init__(self):
super().__init__()
self.output_dir = folder_paths.get_temp_directory()
self.type = "temp"
self.prev_hash = None
@staticmethod
def load_image(pb_id):
is_fail = False
if pb_id not in core.preview_bridge_image_id_map:
is_fail = True
image_path, ui_item = core.preview_bridge_image_id_map[pb_id]
if not os.path.isfile(image_path):
is_fail = True
if not is_fail:
i = Image.open(image_path)
i = ImageOps.exif_transpose(i)
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
if 'A' in i.getbands():
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
mask = 1. - torch.from_numpy(mask)
else:
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
else:
image = empty_pil_tensor()
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
ui_item = {
"filename": 'empty.png',
"subfolder": '',
"type": 'temp'
}
return image, mask.unsqueeze(0), ui_item
def doit(self, images, image, unique_id, block=False, restore_mask="never", prompt=None, extra_pnginfo=None):
need_refresh = False
if unique_id not in core.preview_bridge_cache:
need_refresh = True
elif core.preview_bridge_cache[unique_id][0] is not images:
need_refresh = True
if not need_refresh:
pixels, mask, path_item = PreviewBridge.load_image(image)
image = [path_item]
else:
if restore_mask != "never":
mask = core.preview_bridge_last_mask_cache.get(unique_id)
if mask is None or (restore_mask != "always" and mask.shape[1:] != images.shape[1:3]):
mask = None
else:
mask = None
if mask is None:
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
res = nodes.PreviewImage().save_images(images, filename_prefix="PreviewBridge/PB-", prompt=prompt, extra_pnginfo=extra_pnginfo)
else:
masked_images = tensor_convert_rgba(images)
resized_mask = resize_mask(mask, (images.shape[1], images.shape[2])).unsqueeze(3)
resized_mask = 1 - resized_mask
tensor_putalpha(masked_images, resized_mask)
res = nodes.PreviewImage().save_images(masked_images, filename_prefix="PreviewBridge/PB-", prompt=prompt, extra_pnginfo=extra_pnginfo)
image2 = res['ui']['images']
pixels = images
path = os.path.join(folder_paths.get_temp_directory(), 'PreviewBridge', image2[0]['filename'])
core.set_previewbridge_image(unique_id, path, image2[0])
core.preview_bridge_image_id_map[image] = (path, image2[0])
core.preview_bridge_image_name_map[unique_id, path] = (image, image2[0])
core.preview_bridge_cache[unique_id] = (images, image2)
image = image2
is_empty_mask = torch.all(mask == 0)
if block and is_empty_mask and core.is_execution_model_version_supported():
from comfy_execution.graph import ExecutionBlocker
result = ExecutionBlocker(None), ExecutionBlocker(None)
elif block and is_empty_mask:
print(f"[Impact Pack] PreviewBridge: ComfyUI is outdated - blocking feature is disabled.")
result = pixels, mask
else:
result = pixels, mask
if not is_empty_mask:
core.preview_bridge_last_mask_cache[unique_id] = mask
return {
"ui": {"images": image},
"result": result,
}
def decode_latent(latent, preview_method, vae_opt=None):
if vae_opt is not None:
image = nodes.VAEDecode().decode(vae_opt, latent)[0]
return image
from comfy.cli_args import LatentPreviewMethod
import comfy.latent_formats as latent_formats
if preview_method.startswith("TAE"):
decoder_name = None
if preview_method == "TAESD15":
decoder_name = "taesd"
elif preview_method == 'TAESDXL':
decoder_name = "taesdxl"
elif preview_method == 'TAESD3':
decoder_name = "taesd3"
elif preview_method == 'TAEF1':
decoder_name = "taef1"
if decoder_name:
vae = nodes.VAELoader().load_vae(decoder_name)[0]
image = nodes.VAEDecode().decode(vae, latent)[0]
return image
if preview_method == "Latent2RGB-SD15":
latent_format = latent_formats.SD15()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "Latent2RGB-SDXL":
latent_format = latent_formats.SDXL()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "Latent2RGB-SD3":
latent_format = latent_formats.SD3()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "Latent2RGB-SD-X4":
latent_format = latent_formats.SD_X4()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "Latent2RGB-Playground-2.5":
latent_format = latent_formats.SDXL_Playground_2_5()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "Latent2RGB-SC-Prior":
latent_format = latent_formats.SC_Prior()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "Latent2RGB-SC-B":
latent_format = latent_formats.SC_B()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "Latent2RGB-FLUX.1":
latent_format = latent_formats.Flux()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "Latent2RGB-LTXV":
latent_format = latent_formats.LTXV()
method = LatentPreviewMethod.Latent2RGB
else:
print(f"[Impact Pack] PreviewBridgeLatent: '{preview_method}' is unsupported preview method.")
latent_format = latent_formats.SD15()
method = LatentPreviewMethod.Latent2RGB
previewer = core.get_previewer("cpu", latent_format=latent_format, force=True, method=method)
samples = latent_format.process_in(latent['samples'])
pil_image = previewer.decode_latent_to_preview(samples)
pixels_size = pil_image.size[0]*8, pil_image.size[1]*8
resized_image = pil_image.resize(pixels_size, resample=LANCZOS)
return to_tensor(resized_image).unsqueeze(0)
class PreviewBridgeLatent:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"latent": ("LATENT",),
"image": ("STRING", {"default": ""}),
"preview_method": (["Latent2RGB-FLUX.1",
"Latent2RGB-SDXL", "Latent2RGB-SD15", "Latent2RGB-SD3",
"Latent2RGB-SD-X4", "Latent2RGB-Playground-2.5",
"Latent2RGB-SC-Prior", "Latent2RGB-SC-B",
"Latent2RGB-LTXV",
"TAEF1", "TAESDXL", "TAESD15", "TAESD3"],),
},
"optional": {
"vae_opt": ("VAE", ),
"block": ("BOOLEAN", {"default": False, "label_on": "if_empty_mask", "label_off": "never", "tooltip": "is_empty_mask: If the mask is empty, the execution is stopped.\nnever: The execution is never stopped. Instead, it returns a white mask."}),
"restore_mask": (["never", "always", "if_same_size"], {"tooltip": "if_same_size: If the changed input latent is the same size as the previous latent, restore using the last saved mask\nalways: Whenever the input latent changes, always restore using the last saved mask\nnever: Do not restore the mask.\n`restore_mask` has higher priority than `block`\nIf the input latent already has a mask, do not restore mask."}),
},
"hidden": {"unique_id": "UNIQUE_ID", "prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
RETURN_TYPES = ("LATENT", "MASK", )
FUNCTION = "doit"
OUTPUT_NODE = True
CATEGORY = "ImpactPack/Util"
DESCRIPTION = "This is a feature that allows you to edit and send a Mask over a latent image.\nIf the block is set to 'is_empty_mask', the execution is stopped when the mask is empty."
def __init__(self):
super().__init__()
self.output_dir = folder_paths.get_temp_directory()
self.type = "temp"
self.prev_hash = None
self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5))
@staticmethod
def load_image(pb_id):
is_fail = False
if pb_id not in core.preview_bridge_image_id_map:
is_fail = True
image_path, ui_item = core.preview_bridge_image_id_map[pb_id]
if not os.path.isfile(image_path):
is_fail = True
if not is_fail:
i = Image.open(image_path)
i = ImageOps.exif_transpose(i)
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
if 'A' in i.getbands():
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
mask = 1. - torch.from_numpy(mask)
else:
mask = None
else:
image = empty_pil_tensor()
mask = None
ui_item = {
"filename": 'empty.png',
"subfolder": '',
"type": 'temp'
}
return image, mask, ui_item
def doit(self, latent, image, preview_method, vae_opt=None, block=False, unique_id=None, restore_mask='never', prompt=None, extra_pnginfo=None):
latent_channels = latent['samples'].shape[1]
if 'SD3' in preview_method or 'SC-Prior' in preview_method or 'FLUX.1' in preview_method or 'TAEF1' == preview_method:
preview_method_channels = 16
elif 'LTXV' in preview_method:
preview_method_channels = 128
else:
preview_method_channels = 4
if vae_opt is None and latent_channels != preview_method_channels:
print(f"[PreviewBridgeLatent] The version of latent is not compatible with preview_method.\nSD3, SD1/SD2, SDXL, SC-Prior, SC-B and FLUX.1 are not compatible with each other.")
raise Exception("The version of latent is not compatible with preview_method.<BR>SD3, SD1/SD2, SDXL, SC-Prior, SC-B and FLUX.1 are not compatible with each other.")
need_refresh = False
if unique_id not in core.preview_bridge_cache:
need_refresh = True
elif (core.preview_bridge_cache[unique_id][0] is not latent
or (vae_opt is None and core.preview_bridge_cache[unique_id][2] is not None)
or (vae_opt is None and core.preview_bridge_cache[unique_id][1] != preview_method)
or (vae_opt is not None and core.preview_bridge_cache[unique_id][2] is not vae_opt)):
need_refresh = True
if not need_refresh:
pixels, mask, path_item = PreviewBridge.load_image(image)
if mask is None:
mask = torch.ones(latent['samples'].shape[2:], dtype=torch.float32, device="cpu").unsqueeze(0)
if 'noise_mask' in latent:
res_latent = latent.copy()
del res_latent['noise_mask']
else:
res_latent = latent
is_empty_mask = True
else:
res_latent = latent.copy()
res_latent['noise_mask'] = mask
is_empty_mask = torch.all(mask == 1)
res_image = [path_item]
else:
decoded_image = decode_latent(latent, preview_method, vae_opt)
if 'noise_mask' in latent:
mask = latent['noise_mask'].squeeze(0) # 4D mask -> 3D mask
decoded_pil = to_pil(decoded_image)
inverted_mask = 1 - mask # invert
resized_mask = resize_mask(inverted_mask, (decoded_image.shape[1], decoded_image.shape[2]))
result_pil = apply_mask_alpha_to_pil(decoded_pil, resized_mask)
full_output_folder, filename, counter, _, _ = folder_paths.get_save_image_path("PreviewBridge/PBL-"+self.prefix_append, folder_paths.get_temp_directory(), result_pil.size[0], result_pil.size[1])
file = f"{filename}_{counter}.png"
result_pil.save(os.path.join(full_output_folder, file), compress_level=4)
res_image = [{
'filename': file,
'subfolder': 'PreviewBridge',
'type': 'temp',
}]
is_empty_mask = False
else:
if restore_mask != "never":
mask = core.preview_bridge_last_mask_cache.get(unique_id)
if mask is None or (restore_mask != "always" and mask.shape[1:] != decoded_image.shape[1:3]):
mask = None
else:
mask = None
if mask is None:
mask = torch.ones(latent['samples'].shape[2:], dtype=torch.float32, device="cpu").unsqueeze(0)
res = nodes.PreviewImage().save_images(decoded_image, filename_prefix="PreviewBridge/PBL-", prompt=prompt, extra_pnginfo=extra_pnginfo)
else:
masked_images = tensor_convert_rgba(decoded_image)
resized_mask = resize_mask(mask, (decoded_image.shape[1], decoded_image.shape[2])).unsqueeze(3)
resized_mask = 1 - resized_mask
tensor_putalpha(masked_images, resized_mask)
res = nodes.PreviewImage().save_images(masked_images, filename_prefix="PreviewBridge/PBL-", prompt=prompt, extra_pnginfo=extra_pnginfo)
res_image = res['ui']['images']
is_empty_mask = torch.all(mask == 1)
path = os.path.join(folder_paths.get_temp_directory(), 'PreviewBridge', res_image[0]['filename'])
core.set_previewbridge_image(unique_id, path, res_image[0])
core.preview_bridge_image_id_map[image] = (path, res_image[0])
core.preview_bridge_image_name_map[unique_id, path] = (image, res_image[0])
core.preview_bridge_cache[unique_id] = (latent, preview_method, vae_opt, res_image)
res_latent = latent
if block and is_empty_mask and core.is_execution_model_version_supported():
from comfy_execution.graph import ExecutionBlocker
result = ExecutionBlocker(None), ExecutionBlocker(None)
elif block and is_empty_mask:
print(f"[Impact Pack] PreviewBridgeLatent: ComfyUI is outdated - blocking feature is disabled.")
result = res_latent, mask
else:
result = res_latent, mask
if not is_empty_mask:
core.preview_bridge_last_mask_cache[unique_id] = mask
return {
"ui": {"images": res_image},
"result": result,
}
+8 -6
View File
@@ -1,18 +1,16 @@
import configparser
import os
version_code = [8, 14, 1]
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
version = "V4.38.2"
dependency_version = 19
dependency_version = 24
my_path = os.path.dirname(__file__)
old_config_path = os.path.join(my_path, "impact-pack.ini")
config_path = os.path.join(my_path, "..", "..", "impact-pack.ini")
latent_letter_path = os.path.join(my_path, "..", "..", "latent.png")
MAX_RESOLUTION = 8192
def write_config():
config = configparser.ConfigParser()
@@ -34,11 +32,15 @@ def read_config():
config.read(config_path)
default_conf = config['default']
if not os.path.exists(default_conf['custom_wildcards']):
print(f"[WARN] ComfyUI-Impact-Pack: custom_wildcards path not found: {default_conf['custom_wildcards']}. Using default path.")
default_conf['custom_wildcards'] = os.path.join(my_path, "..", "..", "custom_wildcards")
return {
'dependency_version': int(default_conf['dependency_version']),
'mmdet_skip': default_conf['mmdet_skip'].lower() == 'true' if 'mmdet_skip' in default_conf else True,
'sam_editor_cpu': default_conf['sam_editor_cpu'].lower() == 'true' if 'sam_editor_cpu' in default_conf else False,
'sam_editor_model': 'sam_vit_b_01ec64.pth',
'sam_editor_model': default_conf['sam_editor_model'].lower() if 'sam_editor_model' else 'sam_vit_b_01ec64.pth',
'custom_wildcards': default_conf['custom_wildcards'] if 'custom_wildcards' in default_conf else os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "custom_wildcards")),
'disable_gpu_opencv': default_conf['disable_gpu_opencv'].lower() == 'true' if 'disable_gpu_opencv' in default_conf else True
}
+859 -550
View File
File diff suppressed because it is too large Load Diff
+17
View File
@@ -0,0 +1,17 @@
detection_labels = [
'hand', 'face', 'mouth', 'eyes', 'eyebrows', 'pupils',
'left_eyebrow', 'left_eye', 'left_pupil', 'right_eyebrow', 'right_eye', 'right_pupil',
'short_sleeved_shirt', 'long_sleeved_shirt', 'short_sleeved_outwear', 'long_sleeved_outwear',
'vest', 'sling', 'shorts', 'trousers', 'skirt', 'short_sleeved_dress', 'long_sleeved_dress', 'vest_dress', 'sling_dress',
"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat",
"traffic light", "fire hydrant", "stop sign", "parking meter", "bench",
"bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe",
"backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard",
"sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
"tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl",
"banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza",
"donut", "cake", "chair", "couch", "potted plant", "bed", "dining table", "toilet",
"tv", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven",
"toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear",
"hair drier", "toothbrush"
]
+197 -61
View File
@@ -1,23 +1,35 @@
import impact.core as core
from impact.config import MAX_RESOLUTION
from nodes import MAX_RESOLUTION
import impact.segs_nodes as segs_nodes
import numpy as np
import impact.utils as utils
import torch
from impact.core import SEG
SAM_MODEL_TOOLTIP = {"tooltip": "Segment Anything Model for Silhouette Detection.\nBe sure to use the SAM_MODEL loaded through the SAMLoader (Impact) node as input."}
SAM_MODEL_TOOLTIP_OPTIONAL = {"tooltip": "[OPTIONAL]\nSegment Anything Model for Silhouette Detection.\nBe sure to use the SAM_MODEL loaded through the SAMLoader (Impact) node as input.\nGiven this input, it refines the rectangular areas detected by BBOX_DETECTOR into silhouette shapes through SAM.\nsam_model_opt takes priority over segm_detector_opt."}
MASK_HINT_THRESHOLD_TOOLTIP = "When detection_hint is mask-area, the mask of SEGS is used as a point hint for SAM (Segment Anything).\nIn this case, only the areas of the mask with brightness values equal to or greater than mask_hint_threshold are used as hints."
MASK_HINT_USE_NEGATIVE_TOOLTIP = "When detecting with SAM (Segment Anything), negative hints are applied as follows:\nSmall: When the SEGS is smaller than 10 pixels in size\nOuter: Sampling the image area outside the SEGS region at regular intervals"
DILATION_TOOLTIP = "Set the value to dilate the result mask. If the value is negative, it erodes the mask."
DETECTION_HINT_TOOLTIP = {"tooltip": "It is recommended to use only center-1.\nWhen refining the mask of SEGS with the SAM (Segment Anything) model, center-1 uses only the rectangular area of SEGS and a single point at the exact center as hints.\nOther options were added during the experimental stage and do not work well."}
BBOX_EXPANSION_TOOLTIP = "When performing SAM (Segment Anything) detection within the SEGS area, the rectangular area of SEGS is expanded and used as a hint."
class SAMDetectorCombined:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"sam_model": ("SAM_MODEL", ),
"segs": ("SEGS", ),
"image": ("IMAGE", ),
"sam_model": ("SAM_MODEL", SAM_MODEL_TOOLTIP),
"segs": ("SEGS", {"tooltip": "This is the segment information detected by the detector.\nIt refines the Mask through the SAM (Segment Anything) detector for all areas pointed to by SEGS, and combines all Masks to return as a single Mask."}),
"image": ("IMAGE", {"tooltip": "It is assumed that segs contains only the information about the detected areas, and does not include the image. SAM (Segment Anything) operates by referencing this image."}),
"detection_hint": (["center-1", "horizontal-2", "vertical-2", "rect-4", "diamond-4", "mask-area",
"mask-points", "mask-point-bbox", "none"],),
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"threshold": ("FLOAT", {"default": 0.93, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
"mask_hint_use_negative": (["False", "Small", "Outter"], )
"mask-points", "mask-point-bbox", "none"], DETECTION_HINT_TOOLTIP),
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1, "tooltip": DILATION_TOOLTIP}),
"threshold": ("FLOAT", {"default": 0.93, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Set the sensitivity threshold for the mask detected by SAM (Segment Anything). A higher value generates a more specific mask with a narrower range. For example, when pointing to a person's area, it might detect clothes, which is a narrower range, instead of the entire person."}),
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1, "tooltip": BBOX_EXPANSION_TOOLTIP}),
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": MASK_HINT_THRESHOLD_TOOLTIP}),
"mask_hint_use_negative": (["False", "Small", "Outter"], {"tooltip": MASK_HINT_USE_NEGATIVE_TOOLTIP})
}
}
@@ -36,16 +48,16 @@ class SAMDetectorSegmented:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"sam_model": ("SAM_MODEL", ),
"segs": ("SEGS", ),
"image": ("IMAGE", ),
"sam_model": ("SAM_MODEL", SAM_MODEL_TOOLTIP),
"segs": ("SEGS", {"tooltip": "This is the segment information detected by the detector.\nFor the SEGS region, the masks detected by SAM (Segment Anything) are created as a unified mask and a batch of individual masks."}),
"image": ("IMAGE", {"tooltip": "It is assumed that segs contains only the information about the detected areas, and does not include the image. SAM (Segment Anything) operates by referencing this image."}),
"detection_hint": (["center-1", "horizontal-2", "vertical-2", "rect-4", "diamond-4", "mask-area",
"mask-points", "mask-point-bbox", "none"],),
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"mask-points", "mask-point-bbox", "none"], DETECTION_HINT_TOOLTIP),
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1, "tooltip": DILATION_TOOLTIP}),
"threshold": ("FLOAT", {"default": 0.93, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
"mask_hint_use_negative": (["False", "Small", "Outter"], )
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1, "tooltip": BBOX_EXPANSION_TOOLTIP}),
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": MASK_HINT_THRESHOLD_TOOLTIP}),
"mask_hint_use_negative": (["False", "Small", "Outter"], {"tooltip": MASK_HINT_USE_NEGATIVE_TOOLTIP})
}
}
@@ -84,6 +96,9 @@ class BboxDetectorForEach:
CATEGORY = "ImpactPack/Detector"
def doit(self, bbox_detector, image, threshold, dilation, crop_factor, drop_size, labels=None, detailer_hook=None):
if len(image) > 1:
raise Exception('[Impact Pack] ERROR: BboxDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
segs = bbox_detector.detect(image, threshold, dilation, crop_factor, drop_size, detailer_hook)
if labels is not None and labels != '':
@@ -115,6 +130,9 @@ class SegmDetectorForEach:
CATEGORY = "ImpactPack/Detector"
def doit(self, segm_detector, image, threshold, dilation, crop_factor, drop_size, labels=None, detailer_hook=None):
if len(image) > 1:
raise Exception('[Impact Pack] ERROR: SegmDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
segs = segm_detector.detect(image, threshold, dilation, crop_factor, drop_size, detailer_hook)
if labels is not None and labels != '':
@@ -143,7 +161,11 @@ class SegmDetectorCombined:
def doit(self, segm_detector, image, threshold, dilation):
mask = segm_detector.detect_combined(image, threshold, dilation)
return (mask,)
if mask is None:
mask = torch.zeros((image.shape[2], image.shape[1]), dtype=torch.float32, device="cpu")
return (mask.unsqueeze(0),)
class BboxDetectorCombined(SegmDetectorCombined):
@@ -159,7 +181,11 @@ class BboxDetectorCombined(SegmDetectorCombined):
def doit(self, bbox_detector, image, threshold, dilation):
mask = bbox_detector.detect_combined(image, threshold, dilation)
return (mask,)
if mask is None:
mask = torch.zeros((image.shape[2], image.shape[1]), dtype=torch.float32, device="cpu")
return (mask.unsqueeze(0),)
class SimpleDetectorForEach:
@@ -170,21 +196,22 @@ class SimpleDetectorForEach:
"image": ("IMAGE", ),
"bbox_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_dilation": ("INT", {"default": 0, "min": -255, "max": 255, "step": 1}),
"bbox_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
"sub_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"sub_dilation": ("INT", {"default": 0, "min": -255, "max": 255, "step": 1}),
"sub_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"sub_bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"optional": {
"sam_model_opt": ("SAM_MODEL", ),
"post_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"sam_model_opt": ("SAM_MODEL", SAM_MODEL_TOOLTIP_OPTIONAL),
"segm_detector_opt": ("SEGM_DETECTOR", ),
}
}
}
RETURN_TYPES = ("SEGS",)
@@ -194,29 +221,39 @@ class SimpleDetectorForEach:
@staticmethod
def detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, sam_model_opt=None, segm_detector_opt=None):
segs = bbox_detector.detect(image, bbox_threshold, bbox_dilation, crop_factor, drop_size)
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, post_dilation=0, sam_model_opt=None, segm_detector_opt=None,
detailer_hook=None):
if len(image) > 1:
raise Exception('[Impact Pack] ERROR: SimpleDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
if sam_model_opt is not None:
mask = core.make_sam_mask(sam_model_opt, segs, image, "center-1", sub_dilation,
sub_threshold, sub_bbox_expansion, sam_mask_hint_threshold, False)
segs = core.segs_bitwise_and_mask(segs, mask)
elif segm_detector_opt is not None:
segm_segs = segm_detector_opt.detect(image, sub_threshold, sub_dilation, crop_factor, drop_size)
mask = core.segs_to_combined_mask(segm_segs)
segs = core.segs_bitwise_and_mask(segs, mask)
if segm_detector_opt is not None and hasattr(segm_detector_opt, 'bbox_detector') and segm_detector_opt.bbox_detector == bbox_detector:
# Better segm support for YOLO-World detector
segs = segm_detector_opt.detect(image, sub_threshold, sub_dilation, crop_factor, drop_size, detailer_hook=detailer_hook)
else:
segs = bbox_detector.detect(image, bbox_threshold, bbox_dilation, crop_factor, drop_size, detailer_hook=detailer_hook)
if sam_model_opt is not None:
mask = core.make_sam_mask(sam_model_opt, segs, image, "center-1", sub_dilation,
sub_threshold, sub_bbox_expansion, sam_mask_hint_threshold, False)
segs = core.segs_bitwise_and_mask(segs, mask)
elif segm_detector_opt is not None:
segm_segs = segm_detector_opt.detect(image, sub_threshold, sub_dilation, crop_factor, drop_size, detailer_hook=detailer_hook)
mask = core.segs_to_combined_mask(segm_segs)
segs = core.segs_bitwise_and_mask(segs, mask)
segs = core.dilate_segs(segs, post_dilation)
return (segs,)
def doit(self, bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, sam_model_opt=None, segm_detector_opt=None):
sam_mask_hint_threshold, post_dilation=0, sam_model_opt=None, segm_detector_opt=None):
return SimpleDetectorForEach.detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, sam_model_opt, segm_detector_opt)
sam_mask_hint_threshold, post_dilation=post_dilation,
sam_model_opt=sam_model_opt, segm_detector_opt=segm_detector_opt)
class SimpleDetectorForEachPipe:
@@ -227,17 +264,20 @@ class SimpleDetectorForEachPipe:
"image": ("IMAGE", ),
"bbox_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_dilation": ("INT", {"default": 0, "min": 0, "max": 255, "step": 1}),
"bbox_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
"sub_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"sub_dilation": ("INT", {"default": 0, "min": 0, "max": 255, "step": 1}),
"sub_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"sub_bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"optional": {
"post_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
}
}
RETURN_TYPES = ("SEGS",)
@@ -246,13 +286,17 @@ class SimpleDetectorForEachPipe:
CATEGORY = "ImpactPack/Detector"
def doit(self, detailer_pipe, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold):
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold, post_dilation=0):
if len(image) > 1:
raise Exception('[Impact Pack] ERROR: SimpleDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
model, clip, vae, positive, negative, wildcard, bbox_detector, segm_detector_opt, sam_model_opt, detailer_hook, refiner_model, refiner_clip, refiner_positive, refiner_negative = detailer_pipe
return SimpleDetectorForEach.detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, sam_model_opt, segm_detector_opt)
sam_mask_hint_threshold, post_dilation=post_dilation, sam_model_opt=sam_model_opt, segm_detector_opt=segm_detector_opt,
detailer_hook=detailer_hook)
class SimpleDetectorForAnimateDiff:
@@ -275,7 +319,9 @@ class SimpleDetectorForAnimateDiff:
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"optional": {
"sam_model_opt": ("SAM_MODEL", ),
"masking_mode": (["Pivot SEGS", "Combine neighboring frames", "Don't combine"],),
"segs_pivot": (["Combined mask", "1st frame mask"],),
"sam_model_opt": ("SAM_MODEL", SAM_MODEL_TOOLTIP_OPTIONAL),
"segm_detector_opt": ("SEGM_DETECTOR", ),
}
}
@@ -287,11 +333,14 @@ class SimpleDetectorForAnimateDiff:
@staticmethod
def detect(bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, sam_model_opt=None, segm_detector_opt=None):
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
masking_mode="Pivot SEGS", segs_pivot="Combined mask", sam_model_opt=None, segm_detector_opt=None):
h = image_frames.shape[1]
w = image_frames.shape[2]
# gather segs for all frames
all_segs = []
segs_by_frames = []
for image in image_frames:
image = image.unsqueeze(0)
segs = bbox_detector.detect(image, bbox_threshold, bbox_dilation, crop_factor, drop_size)
@@ -305,25 +354,112 @@ class SimpleDetectorForAnimateDiff:
mask = core.segs_to_combined_mask(segm_segs)
segs = core.segs_bitwise_and_mask(segs, mask)
all_segs.append(segs)
segs_by_frames.append(segs)
# create merged masks
all_masks = []
for segs in all_segs:
all_masks += segs_nodes.SEGSToMaskList().doit(segs)[0]
def get_masked_frames():
masks_by_frame = []
for i, segs in enumerate(segs_by_frames):
masks_in_frame = segs_nodes.SEGSToMaskList().doit(segs)[0]
current_frame_mask = (masks_in_frame[0] * 255).to(torch.uint8)
result_mask = all_masks[0]
for mask in all_masks[1:]:
result_mask += mask
for mask in masks_in_frame[1:]:
current_frame_mask |= (mask * 255).to(torch.uint8)
result_mask = utils.to_binary_mask(result_mask, 0.1)
current_frame_mask = (current_frame_mask/255.0).to(torch.float32)
current_frame_mask = utils.to_binary_mask(current_frame_mask, 0.1)[0]
return segs_nodes.MaskToSEGS().doit(result_mask, False, crop_factor, False, drop_size)
masks_by_frame.append(current_frame_mask)
return masks_by_frame
def get_empty_mask():
return torch.zeros((h, w), dtype=torch.float32, device="cpu")
def get_neighboring_mask_at(i, masks_by_frame):
prv = masks_by_frame[i-1] if i > 1 else get_empty_mask()
cur = masks_by_frame[i]
nxt = masks_by_frame[i-1] if i > 1 else get_empty_mask()
prv = prv if prv is not None else get_empty_mask()
cur = cur.clone() if cur is not None else get_empty_mask()
nxt = nxt if nxt is not None else get_empty_mask()
return prv, cur, nxt
def get_merged_neighboring_mask(masks_by_frame):
if len(masks_by_frame) <= 1:
return masks_by_frame
result = []
for i in range(0, len(masks_by_frame)):
prv, cur, nxt = get_neighboring_mask_at(i, masks_by_frame)
cur = (cur * 255).to(torch.uint8)
cur |= (prv * 255).to(torch.uint8)
cur |= (nxt * 255).to(torch.uint8)
cur = (cur / 255.0).to(torch.float32)
cur = utils.to_binary_mask(cur, 0.1)[0]
result.append(cur)
return result
def get_whole_merged_mask():
all_masks = []
for segs in segs_by_frames:
all_masks += segs_nodes.SEGSToMaskList().doit(segs)[0]
merged_mask = (all_masks[0] * 255).to(torch.uint8)
for mask in all_masks[1:]:
merged_mask |= (mask * 255).to(torch.uint8)
merged_mask = (merged_mask / 255.0).to(torch.float32)
merged_mask = utils.to_binary_mask(merged_mask, 0.1)[0]
return merged_mask
def get_pivot_segs():
if segs_pivot == "1st frame mask":
return segs_by_frames[0][1]
else:
merged_mask = get_whole_merged_mask()
return segs_nodes.MaskToSEGS.doit(merged_mask, False, crop_factor, False, drop_size, contour_fill=True)[0]
def get_segs(merged_neighboring=False):
pivot_segs = get_pivot_segs()
masks_by_frame = get_masked_frames()
if merged_neighboring:
masks_by_frame = get_merged_neighboring_mask(masks_by_frame)
new_segs = []
for seg in pivot_segs[1]:
cropped_mask = torch.zeros(seg.cropped_mask.shape, dtype=torch.float32, device="cpu").unsqueeze(0)
pivot_mask = torch.from_numpy(seg.cropped_mask)
x1, y1, x2, y2 = seg.crop_region
for mask in masks_by_frame:
cropped_mask_at_frame = (mask[y1:y2, x1:x2] * pivot_mask).unsqueeze(0)
cropped_mask = torch.cat((cropped_mask, cropped_mask_at_frame), dim=0)
if len(cropped_mask) > 1:
cropped_mask = cropped_mask[1:]
new_seg = SEG(seg.cropped_image, cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, seg.control_net_wrapper)
new_segs.append(new_seg)
return pivot_segs[0], new_segs
# create result mask
if masking_mode == "Pivot SEGS":
return (get_pivot_segs(), )
elif masking_mode == "Combine neighboring frames":
return (get_segs(merged_neighboring=True), )
else: # elif masking_mode == "Don't combine":
return (get_segs(merged_neighboring=False), )
def doit(self, bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, sam_model_opt=None, segm_detector_opt=None):
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
masking_mode="Pivot SEGS", segs_pivot="Combined mask", sam_model_opt=None, segm_detector_opt=None):
return SimpleDetectorForAnimateDiff.detect(bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, sam_model_opt, segm_detector_opt)
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
masking_mode, segs_pivot, sam_model_opt, segm_detector_opt)
+13 -7
View File
@@ -1,4 +1,3 @@
from transformers import pipeline
import comfy
import re
from impact.utils import *
@@ -31,6 +30,8 @@ class HF_TransformersClassifierProvider:
CATEGORY = "ImpactPack/HuggingFace"
def doit(self, preset_repo_id, manual_repo_id, device_mode):
from transformers import pipeline
if preset_repo_id == 'Manual repo id':
url = manual_repo_id
else:
@@ -41,7 +42,7 @@ class HF_TransformersClassifierProvider:
else:
device = "cpu"
classifier = pipeline(model=url, device=device)
classifier = pipeline('image-classification', model=url, device=device)
return (classifier,)
@@ -82,8 +83,9 @@ class SEGS_Classify:
}
}
RETURN_TYPES = ("SEGS", "SEGS",)
RETURN_NAMES = ("filtered_SEGS", "remained_SEGS",)
RETURN_TYPES = ("SEGS", "SEGS", "STRING")
RETURN_NAMES = ("filtered_SEGS", "remained_SEGS", "detected_labels")
OUTPUT_IS_LIST = (False, False, True)
FUNCTION = "doit"
@@ -116,7 +118,7 @@ class SEGS_Classify:
match = re.match(classify_expr_pattern, expr_str)
if match is None:
return ((segs[0], []), segs)
return (segs[0], []), segs, []
a = match.group(1)
op = match.group(2)
@@ -127,6 +129,7 @@ class SEGS_Classify:
classified = []
remained_SEGS = []
provided_labels = set()
for seg in segs[1]:
cropped_image = None
@@ -138,9 +141,12 @@ class SEGS_Classify:
cropped_image = crop_image(ref_image_opt, seg.crop_region)
if cropped_image is not None:
cropped_image = Image.fromarray(np.clip(255. * cropped_image.squeeze(), 0, 255).astype(np.uint8))
cropped_image = to_pil(cropped_image)
res = classifier(cropped_image)
classified.append((seg, res))
for x in res:
provided_labels.add(x['label'])
else:
remained_SEGS.append(seg)
@@ -179,4 +185,4 @@ class SEGS_Classify:
else:
remained_SEGS.append(seg)
return ((segs[0], filtered_SEGS), (segs[0], remained_SEGS))
return (segs[0], filtered_SEGS), (segs[0], remained_SEGS), list(provided_labels)
+85
View File
@@ -0,0 +1,85 @@
import sys
from . import hooks
from . import defs
class SEGSOrderedFilterDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"target": (["area(=w*h)", "width", "height", "x1", "y1", "x2", "y2"],),
"order": ("BOOLEAN", {"default": True, "label_on": "descending", "label_off": "ascending"}),
"take_start": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
"take_count": ("INT", {"default": 1, "min": 0, "max": sys.maxsize, "step": 1}),
},
}
RETURN_TYPES = ("DETAILER_HOOK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, target, order, take_start, take_count):
hook = hooks.SEGSOrderedFilterDetailerHook(target, order, take_start, take_count)
return (hook, )
class SEGSRangeFilterDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"target": (["area(=w*h)", "width", "height", "x1", "y1", "x2", "y2", "length_percent"],),
"mode": ("BOOLEAN", {"default": True, "label_on": "inside", "label_off": "outside"}),
"min_value": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
"max_value": ("INT", {"default": 67108864, "min": 0, "max": sys.maxsize, "step": 1}),
},
}
RETURN_TYPES = ("DETAILER_HOOK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, target, mode, min_value, max_value):
hook = hooks.SEGSRangeFilterDetailerHook(target, mode, min_value, max_value)
return (hook, )
class SEGSLabelFilterDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"segs": ("SEGS", ),
"preset": (['all'] + defs.detection_labels,),
"labels": ("STRING", {"multiline": True, "placeholder": "List the types of segments to be allowed, separated by commas"}),
},
}
RETURN_TYPES = ("DETAILER_HOOK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, preset, labels):
hook = hooks.SEGSLabelFilterDetailerHook(labels)
return (hook, )
class PreviewDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {
"required": {"quality": ("INT", {"default": 95, "min": 20, "max": 100})},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ("DETAILER_HOOK", "UPSCALER_HOOK")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
NOT_IDEMPOTENT = True
def doit(self, quality, unique_id):
hook = hooks.PreviewDetailerHook(unique_id, quality)
return hook, hook
+518
View File
@@ -0,0 +1,518 @@
import copy
import torch
import nodes
from impact import utils
from . import segs_nodes
from thirdparty import noise_nodes
from server import PromptServer
import asyncio
import folder_paths
import os
from comfy_extras import nodes_custom_sampler
import math
class PixelKSampleHook:
cur_step = 0
total_step = 0
def __init__(self):
pass
def set_steps(self, info):
self.cur_step, self.total_step = info
def post_decode(self, pixels):
return pixels
def post_upscale(self, pixels):
return pixels
def post_encode(self, samples):
return samples
def pre_decode(self, samples):
return samples
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent,
denoise):
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise
def post_crop_region(self, w, h, item_bbox, crop_region):
return crop_region
def touch_scaled_size(self, w, h):
return w, h
class PixelKSampleHookCombine(PixelKSampleHook):
hook1 = None
hook2 = None
def __init__(self, hook1, hook2):
super().__init__()
self.hook1 = hook1
self.hook2 = hook2
def set_steps(self, info):
self.hook1.set_steps(info)
self.hook2.set_steps(info)
def pre_decode(self, samples):
return self.hook2.pre_decode(self.hook1.pre_decode(samples))
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_encode(self, samples):
return self.hook2.post_encode(self.hook1.post_encode(samples))
def post_crop_region(self, w, h, item_bbox, crop_region):
crop_region = self.hook1.post_crop_region(w, h, item_bbox, crop_region)
return self.hook2.post_crop_region(w, h, item_bbox, crop_region)
def touch_scaled_size(self, w, h):
w, h = self.hook1.touch_scaled_size(w, h)
return self.hook2.touch_scaled_size(w, h)
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent,
denoise):
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
self.hook1.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
upscaled_latent, denoise)
return self.hook2.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
upscaled_latent, denoise)
class DetailerHookCombine(PixelKSampleHookCombine):
def cycle_latent(self, latent):
latent = self.hook1.cycle_latent(latent)
latent = self.hook2.cycle_latent(latent)
return latent
def post_detection(self, segs):
segs = self.hook1.post_detection(segs)
segs = self.hook2.post_detection(segs)
return segs
def post_paste(self, image):
image = self.hook1.post_paste(image)
image = self.hook2.post_paste(image)
return image
def get_custom_noise(self, seed, noise, is_touched):
noise_1st, is_touched = self.hook1.get_custom_noise(seed, noise, is_touched)
noise_2nd, is_touched = self.hook2.get_custom_noise(seed, noise, is_touched)
return noise, is_touched
class SimpleCfgScheduleHook(PixelKSampleHook):
target_cfg = 0
def __init__(self, target_cfg):
super().__init__()
self.target_cfg = target_cfg
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise):
if self.total_step > 1:
progress = self.cur_step / (self.total_step - 1)
gap = self.target_cfg - cfg
current_cfg = int(cfg + gap * progress)
else:
current_cfg = self.target_cfg
return model, seed, steps, current_cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise
class SimpleDenoiseScheduleHook(PixelKSampleHook):
def __init__(self, target_denoise):
super().__init__()
self.target_denoise = target_denoise
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise):
if self.total_step > 1:
progress = self.cur_step / (self.total_step - 1)
gap = self.target_denoise - denoise
current_denoise = denoise + gap * progress
else:
current_denoise = self.target_denoise
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, current_denoise
class SimpleStepsScheduleHook(PixelKSampleHook):
def __init__(self, target_steps):
super().__init__()
self.target_steps = target_steps
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise):
if self.total_step > 1:
progress = self.cur_step / (self.total_step - 1)
gap = self.target_steps - steps
current_steps = int(steps + gap * progress)
else:
current_steps = self.target_steps
return model, seed, current_steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise
class DetailerHook(PixelKSampleHook):
def cycle_latent(self, latent):
return latent
def post_detection(self, segs):
return segs
def post_paste(self, image):
return image
def get_custom_noise(self, seed, noise, is_touched):
return noise, is_touched
# class CustomNoiseDetailerHookProvider(DetailerHook):
# def __init__(self, noise):
# super().__init__()
# self.noise = noise
#
# def get_custom_noise(self, seed, noise, is_start):
# return self.noise
class VariationNoiseDetailerHookProvider(DetailerHook):
def __init__(self, variation_seed, variation_strength):
super().__init__()
self.variation_seed = variation_seed
self.variation_strength = variation_strength
def get_custom_noise(self, seed, noise, is_touched):
empty_noise = {'samples': torch.zeros(noise.size())}
if not is_touched:
noise = nodes_custom_sampler.Noise_RandomNoise(seed).generate_noise(empty_noise)
noise_2nd = nodes_custom_sampler.Noise_RandomNoise(self.variation_seed).generate_noise(empty_noise)
mixed_noise = ((1 - self.variation_strength) * noise + self.variation_strength * noise_2nd)
# NOTE: Since the variance of the Gaussian noise in mixed_noise has changed, it must be corrected through scaling.
scale_factor = math.sqrt((1 - self.variation_strength) ** 2 + self.variation_strength ** 2)
corrected_noise = mixed_noise / scale_factor # Scale the noise to maintain variance of 1
return corrected_noise, True
class SimpleDetailerDenoiseSchedulerHook(DetailerHook):
def __init__(self, target_denoise):
super().__init__()
self.target_denoise = target_denoise
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, denoise):
if self.total_step > 1:
progress = self.cur_step / (self.total_step - 1)
gap = self.target_denoise - denoise
current_denoise = denoise + gap * progress
else:
# ignore hook if total cycle <= 1
current_denoise = denoise
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, current_denoise
class CoreMLHook(DetailerHook):
def __init__(self, mode):
super().__init__()
resolution = mode.split('x')
self.w = int(resolution[0])
self.h = int(resolution[1])
self.override_bbox_by_segm = False
def pre_decode(self, samples):
new_samples = copy.deepcopy(samples)
new_samples['samples'] = samples['samples'][0].unsqueeze(0)
return new_samples
def post_encode(self, samples):
new_samples = copy.deepcopy(samples)
new_samples['samples'] = samples['samples'].repeat(2, 1, 1, 1)
return new_samples
def post_crop_region(self, w, h, item_bbox, crop_region):
x1, y1, x2, y2 = crop_region
bx1, by1, bx2, by2 = item_bbox
crop_w = x2-x1
crop_h = y2-y1
crop_ratio = crop_w/crop_h
target_ratio = self.w/self.h
if crop_ratio < target_ratio:
# shrink height
top_gap = by1 - y1
bottom_gap = y2 - by2
gap_ratio = top_gap / bottom_gap
target_height = 1/target_ratio*crop_w
delta_height = crop_h - target_height
new_y1 = int(y1 + delta_height*gap_ratio)
new_y2 = int(new_y1 + target_height)
crop_region = x1, new_y1, x2, new_y2
elif crop_ratio > target_ratio:
# shrink width
left_gap = bx1 - x1
right_gap = x2 - bx2
gap_ratio = left_gap / right_gap
target_width = target_ratio*crop_h
delta_width = crop_w - target_width
new_x1 = int(x1 + delta_width*gap_ratio)
new_x2 = int(new_x1 + target_width)
crop_region = new_x1, y1, new_x2, y2
return crop_region
def touch_scaled_size(self, w, h):
return self.w, self.h
# REQUIREMENTS: BlenderNeko/ComfyUI Noise
class InjectNoiseHook(PixelKSampleHook):
def __init__(self, source, seed, start_strength, end_strength):
super().__init__()
self.source = source
self.seed = seed
self.start_strength = start_strength
self.end_strength = end_strength
def post_encode(self, samples):
cur_step = self.cur_step
size = samples['samples'].shape
seed = cur_step + self.seed + cur_step
if "BNK_NoisyLatentImage" in nodes.NODE_CLASS_MAPPINGS and "BNK_InjectNoise" in nodes.NODE_CLASS_MAPPINGS:
NoisyLatentImage = nodes.NODE_CLASS_MAPPINGS["BNK_NoisyLatentImage"]
InjectNoise = nodes.NODE_CLASS_MAPPINGS["BNK_InjectNoise"]
else:
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_Noise',
"To use 'NoiseInjectionHookProvider', 'ComfyUI Noise' extension is required.")
raise Exception("'BNK_NoisyLatentImage', 'BNK_InjectNoise' nodes are not installed.")
noise = NoisyLatentImage().create_noisy_latents(self.source, seed, size[3] * 8, size[2] * 8, size[0])[0]
# inj noise
mask = None
if 'noise_mask' in samples:
mask = samples['noise_mask']
strength = self.start_strength + (self.end_strength - self.start_strength) * cur_step / self.total_step
samples = InjectNoise().inject_noise(samples, strength, noise, mask)[0]
print(f"[Impact Pack] InjectNoiseHook: strength = {strength}")
if mask is not None:
samples['noise_mask'] = mask
return samples
class UnsamplerHook(PixelKSampleHook):
def __init__(self, model, steps, start_end_at_step, end_end_at_step, cfg, sampler_name,
scheduler, normalize, positive, negative):
super().__init__()
self.model = model
self.cfg = cfg
self.sampler_name = sampler_name
self.steps = steps
self.start_end_at_step = start_end_at_step
self.end_end_at_step = end_end_at_step
self.scheduler = scheduler
self.normalize = normalize
self.positive = positive
self.negative = negative
def post_encode(self, samples):
cur_step = self.cur_step
Unsampler = noise_nodes.Unsampler
end_at_step = self.start_end_at_step + (self.end_end_at_step - self.start_end_at_step) * cur_step / self.total_step
end_at_step = int(end_at_step)
print(f"[Impact Pack] UnsamplerHook: end_at_step = {end_at_step}")
# inj noise
mask = None
if 'noise_mask' in samples:
mask = samples['noise_mask']
samples = Unsampler().unsampler(self.model, self.cfg, self.sampler_name, self.steps, end_at_step,
self.scheduler, self.normalize, self.positive, self.negative, samples)[0]
if mask is not None:
samples['noise_mask'] = mask
return samples
class InjectNoiseHookForDetailer(DetailerHook):
def __init__(self, source, seed, start_strength, end_strength, from_start=False):
super().__init__()
self.source = source
self.seed = seed
self.start_strength = start_strength
self.end_strength = end_strength
self.from_start = from_start
def inject_noise(self, samples):
cur_step = self.cur_step if self.from_start else self.cur_step - 1
total_step = self.total_step if self.from_start else self.total_step - 1
size = samples['samples'].shape
seed = cur_step + self.seed + cur_step
if "BNK_NoisyLatentImage" in nodes.NODE_CLASS_MAPPINGS and "BNK_InjectNoise" in nodes.NODE_CLASS_MAPPINGS:
NoisyLatentImage = nodes.NODE_CLASS_MAPPINGS["BNK_NoisyLatentImage"]
InjectNoise = nodes.NODE_CLASS_MAPPINGS["BNK_InjectNoise"]
else:
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_Noise',
"To use 'NoiseInjectionDetailerHookProvider', 'ComfyUI Noise' extension is required.")
raise Exception("'BNK_NoisyLatentImage', 'BNK_InjectNoise' nodes are not installed.")
noise = NoisyLatentImage().create_noisy_latents(self.source, seed, size[3] * 8, size[2] * 8, size[0])[0]
# inj noise
mask = None
if 'noise_mask' in samples:
mask = samples['noise_mask']
strength = self.start_strength + (self.end_strength - self.start_strength) * cur_step / total_step
samples = InjectNoise().inject_noise(samples, strength, noise, mask)[0]
if mask is not None:
samples['noise_mask'] = mask
return samples
def cycle_latent(self, latent):
if self.cur_step == 0 and not self.from_start:
return latent
else:
return self.inject_noise(latent)
class UnsamplerDetailerHook(DetailerHook):
def __init__(self, model, steps, start_end_at_step, end_end_at_step, cfg, sampler_name,
scheduler, normalize, positive, negative, from_start=False):
super().__init__()
self.model = model
self.cfg = cfg
self.sampler_name = sampler_name
self.steps = steps
self.start_end_at_step = start_end_at_step
self.end_end_at_step = end_end_at_step
self.scheduler = scheduler
self.normalize = normalize
self.positive = positive
self.negative = negative
self.from_start = from_start
def unsample(self, samples):
cur_step = self.cur_step if self.from_start else self.cur_step - 1
total_step = self.total_step if self.from_start else self.total_step - 1
Unsampler = noise_nodes.Unsampler
end_at_step = self.start_end_at_step + (self.end_end_at_step - self.start_end_at_step) * cur_step / total_step
end_at_step = int(end_at_step)
# inj noise
mask = None
if 'noise_mask' in samples:
mask = samples['noise_mask']
samples = Unsampler().unsampler(self.model, self.cfg, self.sampler_name, self.steps, end_at_step,
self.scheduler, self.normalize, self.positive, self.negative, samples)[0]
if mask is not None:
samples['noise_mask'] = mask
return samples
def cycle_latent(self, latent):
if self.cur_step == 0 and not self.from_start:
return latent
else:
return self.unsample(latent)
class SEGSOrderedFilterDetailerHook(DetailerHook):
def __init__(self, target, order, take_start, take_count):
super().__init__()
self.target = target
self.order = order
self.take_start = take_start
self.take_count = take_count
def post_detection(self, segs):
return segs_nodes.SEGSOrderedFilter().doit(segs, self.target, self.order, self.take_start, self.take_count)[0]
class SEGSRangeFilterDetailerHook(DetailerHook):
def __init__(self, target, mode, min_value, max_value):
super().__init__()
self.target = target
self.mode = mode
self.min_value = min_value
self.max_value = max_value
def post_detection(self, segs):
return segs_nodes.SEGSRangeFilter().doit(segs, self.target, self.mode, self.min_value, self.max_value)[0]
class SEGSLabelFilterDetailerHook(DetailerHook):
def __init__(self, labels):
super().__init__()
self.labels = labels
def post_detection(self, segs):
return segs_nodes.SEGSLabelFilter().doit(segs, "", self.labels)[0]
class PreviewDetailerHook(DetailerHook):
def __init__(self, node_id, quality):
super().__init__()
self.node_id = node_id
self.quality = quality
async def send(self, image):
if len(image) > 0:
image = image[0].unsqueeze(0)
img = utils.tensor2pil(image)
temp_path = os.path.join(folder_paths.get_temp_directory(), 'pvhook')
if not os.path.exists(temp_path):
os.makedirs(temp_path)
fullpath = os.path.join(temp_path, f"{self.node_id}.webp")
img.save(fullpath, quality=self.quality)
item = {
"filename": f"{self.node_id}.webp",
"subfolder": 'pvhook',
"type": 'temp'
}
PromptServer.instance.send_sync("impact-preview", {'node_id': self.node_id, 'item': item})
def post_paste(self, image):
asyncio.run(self.send(image))
return image
File diff suppressed because it is too large Load Diff
+321
View File
@@ -0,0 +1,321 @@
import nodes
from comfy.k_diffusion import sampling as k_diffusion_sampling
from comfy import samplers
from comfy_extras import nodes_custom_sampler
import latent_preview
import comfy
import torch
import math
import comfy.model_management as mm
try:
from comfy_extras.nodes_custom_sampler import Noise_EmptyNoise, Noise_RandomNoise
import node_helpers
except:
print(f"\n#############################################\n[Impact Pack] ComfyUI is an outdated version.\n#############################################\n")
raise Exception("[Impact Pack] ComfyUI is an outdated version.")
def calculate_sigmas(model, sampler, scheduler, steps):
discard_penultimate_sigma = False
if sampler in ['dpm_2', 'dpm_2_ancestral', 'uni_pc', 'uni_pc_bh2']:
steps += 1
discard_penultimate_sigma = True
if scheduler.startswith('AYS'):
sigmas = nodes.NODE_CLASS_MAPPINGS['AlignYourStepsScheduler']().get_sigmas(scheduler[4:], steps, denoise=1.0)[0]
elif scheduler.startswith('GITS[coeff='):
sigmas = nodes.NODE_CLASS_MAPPINGS['GITSScheduler']().get_sigmas(float(scheduler[11:-1]), steps, denoise=1.0)[0]
elif scheduler == 'LTXV[default]':
sigmas = nodes.NODE_CLASS_MAPPINGS['LTXVScheduler']().get_sigmas(20, 2.05, 0.95, True, 0.1)[0]
elif scheduler.startswith('OSS'):
sigmas = nodes.NODE_CLASS_MAPPINGS['OptimalStepsScheduler']().get_sigmas(scheduler[4:], steps, denoise=1.0)[0]
else:
sigmas = samplers.calculate_sigmas(model.get_model_object("model_sampling"), scheduler, steps)
if discard_penultimate_sigma:
sigmas = torch.cat([sigmas[:-2], sigmas[-1:]])
return sigmas
def get_noise_sampler(x, cpu, total_sigmas, **kwargs):
if 'extra_args' in kwargs and 'seed' in kwargs['extra_args']:
sigma_min, sigma_max = total_sigmas[total_sigmas > 0].min(), total_sigmas.max()
seed = kwargs['extra_args'].get("seed", None)
return k_diffusion_sampling.BrownianTreeNoiseSampler(x, sigma_min, sigma_max, seed=seed, cpu=cpu)
return None
def ksampler(sampler_name, total_sigmas, extra_options={}, inpaint_options={}):
if sampler_name in ["dpmpp_sde", "dpmpp_sde_gpu", "dpmpp_2m_sde", "dpmpp_2m_sde_gpu", "dpmpp_3m_sde", "dpmpp_3m_sde_gpu"]:
if sampler_name == "dpmpp_sde":
orig_sampler_function = k_diffusion_sampling.sample_dpmpp_sde
elif sampler_name == "dpmpp_sde_gpu":
orig_sampler_function = k_diffusion_sampling.sample_dpmpp_sde_gpu
elif sampler_name == "dpmpp_2m_sde":
orig_sampler_function = k_diffusion_sampling.sample_dpmpp_2m_sde
elif sampler_name == "dpmpp_2m_sde_gpu":
orig_sampler_function = k_diffusion_sampling.sample_dpmpp_2m_sde_gpu
elif sampler_name == "dpmpp_3m_sde":
orig_sampler_function = k_diffusion_sampling.sample_dpmpp_3m_sde
elif sampler_name == "dpmpp_3m_sde_gpu":
orig_sampler_function = k_diffusion_sampling.sample_dpmpp_3m_sde_gpu
def sampler_function_wrapper(model, x, sigmas, **kwargs):
if 'noise_sampler' not in kwargs:
kwargs['noise_sampler'] = get_noise_sampler(x, 'gpu' not in sampler_name, total_sigmas, **kwargs)
return orig_sampler_function(model, x, sigmas, **kwargs)
sampler_function = sampler_function_wrapper
else:
return comfy.samplers.sampler_object(sampler_name)
return samplers.KSAMPLER(sampler_function, extra_options, inpaint_options)
# modified version of SamplerCustom.sample
def sample_with_custom_noise(model, add_noise, noise_seed, cfg, positive, negative, sampler, sigmas, latent_image, noise=None, callback=None):
latent = latent_image
latent_image = latent["samples"]
if hasattr(comfy.sample, 'fix_empty_latent_channels'):
latent_image = comfy.sample.fix_empty_latent_channels(model, latent_image)
out = latent.copy()
out['samples'] = latent_image
if noise is None:
if not add_noise:
noise = Noise_EmptyNoise().generate_noise(out)
else:
noise = Noise_RandomNoise(noise_seed).generate_noise(out)
noise_mask = None
if "noise_mask" in latent:
noise_mask = latent["noise_mask"]
x0_output = {}
preview_callback = latent_preview.prepare_callback(model, sigmas.shape[-1] - 1, x0_output)
if callback is not None:
def touched_callback(step, x0, x, total_steps):
callback(step, x0, x, total_steps)
preview_callback(step, x0, x, total_steps)
else:
touched_callback = preview_callback
disable_pbar = not comfy.utils.PROGRESS_BAR_ENABLED
device = mm.get_torch_device()
noise = noise.to(device)
latent_image = latent_image.to(device)
if noise_mask is not None:
noise_mask = noise_mask.to(device)
if negative != 'NegativePlaceholder':
# This way is incompatible with Advanced ControlNet, yet.
# guider = comfy.samplers.CFGGuider(model)
# guider.set_conds(positive, negative)
# guider.set_cfg(cfg)
samples = comfy.sample.sample_custom(model, noise, cfg, sampler, sigmas, positive, negative, latent_image,
noise_mask=noise_mask, callback=touched_callback,
disable_pbar=disable_pbar, seed=noise_seed)
else:
guider = nodes_custom_sampler.Guider_Basic(model)
positive = node_helpers.conditioning_set_values(positive, {"guidance": cfg})
guider.set_conds(positive)
samples = guider.sample(noise, latent_image, sampler, sigmas, denoise_mask=noise_mask, callback=touched_callback, disable_pbar=disable_pbar, seed=noise_seed)
samples = samples.to(comfy.model_management.intermediate_device())
out["samples"] = samples
if "x0" in x0_output:
out_denoised = latent.copy()
out_denoised["samples"] = model.model.process_latent_out(x0_output["x0"].cpu())
else:
out_denoised = out
return out, out_denoised
# When sampling one step at a time, it mitigates the problem. (especially for _sde series samplers)
def separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler, positive, negative,
latent_image, start_at_step, end_at_step, return_with_leftover_noise, sigma_ratio=1.0, sampler_opt=None, noise=None, callback=None, scheduler_func=None):
if scheduler_func is not None:
total_sigmas = scheduler_func(model, sampler_name, steps)
else:
if sampler_opt is None:
total_sigmas = calculate_sigmas(model, sampler_name, scheduler, steps)
else:
total_sigmas = calculate_sigmas(model, "", scheduler, steps)
sigmas = total_sigmas
if end_at_step is not None and end_at_step < (len(total_sigmas) - 1):
sigmas = total_sigmas[:end_at_step + 1]
if not return_with_leftover_noise:
sigmas[-1] = 0
if start_at_step is not None:
if start_at_step < (len(sigmas) - 1):
sigmas = sigmas[start_at_step:] * sigma_ratio
else:
if latent_image is not None:
return latent_image
else:
return {'samples': torch.zeros_like(noise)}
if sampler_opt is None:
impact_sampler = ksampler(sampler_name, total_sigmas)
else:
impact_sampler = sampler_opt
if len(sigmas) == 0 or (len(sigmas) == 1 and sigmas[0] == 0):
return latent_image
res = sample_with_custom_noise(model, add_noise, seed, cfg, positive, negative, impact_sampler, sigmas, latent_image, noise=noise, callback=callback)
if return_with_leftover_noise:
return res[0]
else:
return res[1]
def impact_sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=1.0, sigma_ratio=1.0, sampler_opt=None, noise=None, scheduler_func=None):
advanced_steps = math.floor(steps / denoise)
start_at_step = advanced_steps - steps
end_at_step = start_at_step + steps
return separated_sample(model, True, seed, advanced_steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
start_at_step, end_at_step, False, scheduler_func=scheduler_func)
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):
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`
# refined_latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise * sigma_factor)[0]
advanced_steps = math.floor(steps / denoise)
start_at_step = advanced_steps - steps
end_at_step = start_at_step + steps
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)
else:
advanced_steps = math.floor(steps / denoise)
start_at_step = advanced_steps - steps
end_at_step = start_at_step + math.floor(steps * (1.0 - refiner_ratio))
# 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)
if 'noise_mask' in latent_image:
# noise_latent = \
# impact_sampling.separated_sample(refiner_model, "enable", seed, advanced_steps, cfg, sampler_name,
# scheduler, refiner_positive, refiner_negative, latent_image, end_at_step,
# end_at_step, "enable")
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
temp_latent = latent_compositor.composite(latent_image, temp_latent, 0, 0, False, latent_image['noise_mask'])[0]
# 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)
return refined_latent
class KSamplerAdvancedWrapper:
params = None
def __init__(self, model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=None, sigma_factor=1.0, scheduler_func=None):
self.params = model, cfg, sampler_name, scheduler, positive, negative, sigma_factor
self.sampler_opt = sampler_opt
self.scheduler_func = scheduler_func
def clone_with_conditionings(self, positive, negative):
model, cfg, sampler_name, scheduler, _, _, _ = self.params
return KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, self.sampler_opt)
def sample_advanced(self, add_noise, seed, steps, latent_image, start_at_step, end_at_step, return_with_leftover_noise, hook=None,
recovery_mode="ratio additional", recovery_sampler="AUTO", recovery_sigma_ratio=1.0, noise=None):
model, cfg, sampler_name, scheduler, positive, negative, sigma_factor = self.params
# steps, start_at_step, end_at_step = self.compensate_denoise(steps, start_at_step, end_at_step)
if hook is not None:
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent = hook.pre_ksample_advanced(model, add_noise, seed, steps, cfg, sampler_name, scheduler,
positive, negative, latent_image, start_at_step, end_at_step,
return_with_leftover_noise)
if recovery_mode != 'DISABLE' and sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu']:
base_image = latent_image.copy()
if recovery_mode == "ratio between":
sigma_ratio = 1.0 - recovery_sigma_ratio
else:
sigma_ratio = 1.0
else:
base_image = None
sigma_ratio = 1.0
try:
if sigma_ratio > 0:
latent_image = separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler,
positive, negative, latent_image, start_at_step, end_at_step,
return_with_leftover_noise, sigma_ratio=sigma_ratio * sigma_factor,
sampler_opt=self.sampler_opt, noise=noise, scheduler_func=self.scheduler_func)
except ValueError as e:
if str(e) == 'sigma_min and sigma_max must not be 0':
print(f"\nWARN: sampling skipped - sigma_min and sigma_max are 0")
return latent_image
if (recovery_sigma_ratio > 0 and recovery_mode != 'DISABLE' and
sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu']):
compensate = 0 if sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu'] else 2
if recovery_sampler == "AUTO":
recovery_sampler = 'dpm_fast' if sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu'] else 'dpmpp_2m'
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
noise_mask = latent_image['noise_mask']
if len(noise_mask.shape) == 4:
noise_mask = noise_mask.squeeze(0).squeeze(0)
latent_image = latent_compositor.composite(base_image, latent_image, 0, 0, False, noise_mask)[0]
try:
latent_image = separated_sample(model, add_noise, seed, steps, cfg, recovery_sampler, scheduler,
positive, negative, latent_image, start_at_step-compensate, end_at_step, return_with_leftover_noise,
sigma_ratio=recovery_sigma_ratio * sigma_factor, sampler_opt=self.sampler_opt, scheduler_func=self.scheduler_func)
except ValueError as e:
if str(e) == 'sigma_min and sigma_max must not be 0':
print(f"\nWARN: sampling skipped - sigma_min and sigma_max are 0")
return latent_image
class KSamplerWrapper:
params = None
def __init__(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, scheduler_func=None):
self.params = model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise
self.scheduler_func = scheduler_func
def sample(self, latent_image, hook=None):
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise = self.params
if hook is not None:
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
hook.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)
return impact_sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise, scheduler_func=self.scheduler_func)
+215 -91
View File
@@ -1,54 +1,27 @@
import os
import threading
import traceback
from aiohttp import web
import impact
import server
import folder_paths
import torchvision
import impact.core as core
import impact.impact_pack as impact_pack
from impact.utils import to_tensor
from segment_anything import SamPredictor, sam_model_registry
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
@server.PromptServer.instance.routes.post("/upload/temp")
async def upload_image(request):
upload_dir = folder_paths.get_temp_directory()
if not os.path.exists(upload_dir):
os.makedirs(upload_dir)
post = await request.post()
image = post.get("image")
if image and image.file:
filename = image.filename
if not filename:
return web.Response(status=400)
split = os.path.splitext(filename)
i = 1
while os.path.exists(os.path.join(upload_dir, filename)):
filename = f"{split[0]} ({i}){split[1]}"
i += 1
filepath = os.path.join(upload_dir, filename)
with open(filepath, "wb") as f:
f.write(image.file.read())
return web.json_response({"name": filename})
else:
return web.Response(status=400)
from server import PromptServer
import logging
sam_predictor = None
@@ -87,7 +60,7 @@ def async_prepare_sam(image_dir, model_name, filename):
sam_predictor.model.cpu()
@server.PromptServer.instance.routes.post("/sam/prepare")
@PromptServer.instance.routes.post("/sam/prepare")
async def sam_prepare(request):
global sam_predictor
global last_prepare_data
@@ -104,9 +77,13 @@ async def sam_prepare(request):
if data['sam_model_name'] == 'auto':
model_name = impact.config.get_config()['sam_editor_model']
model_name = os.path.join(impact_pack.model_path, "sams", model_name)
model_path = folder_paths.get_full_path("sams", model_name)
print(f"[INFO] ComfyUI-Impact-Pack: Loading SAM model '{impact_pack.model_path}'")
if model_path is None:
logging.error(f"[Impact Pack] The '{model_name}' model file cannot be found in any sams model path.")
return web.Response(status=400)
logging.info(f"[Impact Pack] Loading SAM model '{model_path}'")
filename, image_dir = folder_paths.annotated_filepath(data["filename"])
@@ -119,13 +96,14 @@ async def sam_prepare(request):
if image_dir is None:
return web.Response(status=400)
thread = threading.Thread(target=async_prepare_sam, args=(image_dir, model_name, filename,))
thread = threading.Thread(target=async_prepare_sam, args=(image_dir, model_path, filename,))
thread.start()
print(f"[INFO] ComfyUI-Impact-Pack: SAM model loaded. ")
logging.info("[Impact Pack] SAM model loaded. ")
return web.Response(status=200)
@server.PromptServer.instance.routes.post("/sam/release")
@PromptServer.instance.routes.post("/sam/release")
async def release_sam(request):
global sam_predictor
@@ -133,10 +111,10 @@ async def release_sam(request):
del sam_predictor
sam_predictor = None
print(f"[INFO] ComfyUI-Impact-Pack: unloading SAM model")
logging.info("[Impact Pack]: unloading SAM model")
@server.PromptServer.instance.routes.post("/sam/detect")
@PromptServer.instance.routes.post("/sam/detect")
async def sam_detect(request):
global sam_predictor
with sam_lock:
@@ -189,22 +167,28 @@ async def sam_detect(request):
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/wildcards/list")
@PromptServer.instance.routes.get("/impact/wildcards/refresh")
async def wildcards_refresh(request):
impact.wildcards.wildcard_load()
return web.Response(status=200)
@PromptServer.instance.routes.get("/impact/wildcards/list")
async def wildcards_list(request):
data = {'data': impact.wildcards.get_wildcard_list()}
return web.json_response(data)
@server.PromptServer.instance.routes.post("/impact/wildcards")
@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})
segs_picker_map = {}
@server.PromptServer.instance.routes.get("/impact/segs/picker/count")
@PromptServer.instance.routes.get("/impact/segs/picker/count")
async def segs_picker_count(request):
node_id = request.rel_url.query.get('id', '')
@@ -215,24 +199,24 @@ async def segs_picker_count(request):
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/segs/picker/view")
@PromptServer.instance.routes.get("/impact/segs/picker/view")
async def segs_picker(request):
node_id = request.rel_url.query.get('id', '')
idx = int(request.rel_url.query.get('idx', ''))
if node_id in segs_picker_map and idx < len(segs_picker_map[node_id]):
pil = segs_picker_map[node_id][idx]
img = to_tensor(segs_picker_map[node_id][idx]).permute(0, 3, 1, 2).squeeze(0)
pil = torchvision.transforms.ToPILImage('RGB')(img)
image_bytes = BytesIO()
pil.save(image_bytes, format="PNG")
image_bytes.seek(0)
return web.Response(status=200, body=image_bytes, content_type='image/png', headers={"Content-Disposition": f"filename={node_id}{idx}.png"})
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/view/validate")
@PromptServer.instance.routes.get("/view/validate")
async def view_validate(request):
if "filename" in request.rel_url.query:
filename = request.rel_url.query["filename"]
@@ -253,7 +237,7 @@ async def view_validate(request):
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/validate/pb_id_image")
@PromptServer.instance.routes.get("/impact/validate/pb_id_image")
async def view_validate(request):
if "id" in request.rel_url.query:
pb_id = request.rel_url.query["id"]
@@ -268,40 +252,43 @@ async def view_validate(request):
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/set/pb_id_image")
@PromptServer.instance.routes.get("/impact/set/pb_id_image")
async def set_previewbridge_image(request):
if "filename" in request.rel_url.query:
node_id = request.rel_url.query["node_id"]
filename = request.rel_url.query["filename"]
path_type = request.rel_url.query["type"]
subfolder = request.rel_url.query["subfolder"]
filename, output_dir = folder_paths.annotated_filepath(filename)
try:
if "filename" in request.rel_url.query:
node_id = request.rel_url.query["node_id"]
filename = request.rel_url.query["filename"]
path_type = request.rel_url.query["type"]
subfolder = request.rel_url.query["subfolder"]
filename, output_dir = folder_paths.annotated_filepath(filename)
if filename == '' or filename[0] == '/' or '..' in filename:
return web.Response(status=400)
if filename == '' or filename[0] == '/' or '..' in filename:
return web.Response(status=400)
if output_dir is None:
if path_type == 'input':
output_dir = folder_paths.get_input_directory()
elif path_type == 'output':
output_dir = folder_paths.get_output_directory()
else:
output_dir = folder_paths.get_temp_directory()
if output_dir is None:
if path_type == 'input':
output_dir = folder_paths.get_input_directory()
elif path_type == 'output':
output_dir = folder_paths.get_output_directory()
else:
output_dir = folder_paths.get_temp_directory()
file = os.path.join(output_dir, subfolder, filename)
item = {
'filename': filename,
'type': path_type,
'subfolder': subfolder,
}
pb_id = core.set_previewbridge_image(node_id, file, item)
file = os.path.join(output_dir, subfolder, filename)
item = {
'filename': filename,
'type': path_type,
'subfolder': subfolder,
}
pb_id = core.set_previewbridge_image(node_id, file, item)
return web.Response(status=200, text=pb_id)
return web.Response(status=200, text=pb_id)
except Exception:
traceback.print_exc()
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/get/pb_id_image")
@PromptServer.instance.routes.get("/impact/get/pb_id_image")
async def get_previewbridge_image(request):
if "id" in request.rel_url.query:
pb_id = request.rel_url.query["id"]
@@ -313,7 +300,7 @@ async def get_previewbridge_image(request):
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/view/pb_id_image")
@PromptServer.instance.routes.get("/impact/view/pb_id_image")
async def view_previewbridge_image(request):
if "id" in request.rel_url.query:
pb_id = request.rel_url.query["id"]
@@ -331,6 +318,9 @@ async def view_previewbridge_image(request):
def onprompt_for_switch(json_data):
inversed_switch_info = {}
onprompt_switch_info = {}
onprompt_cond_branch_info = {}
disabled_switch = set()
for k, v in json_data['prompt'].items():
if 'class_type' not in v:
@@ -338,17 +328,24 @@ def onprompt_for_switch(json_data):
cls = v['class_type']
if cls == 'ImpactInversedSwitch':
select_input = v['inputs']['select']
if isinstance(select_input, list) and len(select_input) == 2:
input_node = json_data['prompt'][select_input[0]]
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
inversed_switch_info[k] = input_node['inputs']['value']
else:
inversed_switch_info[k] = select_input
# if 'sel_mode' is 'select_on_prompt'
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'select' in v['inputs']:
select_input = v['inputs']['select']
# if 'select' is converted input
if isinstance(select_input, list) and len(select_input) == 2:
input_node = json_data['prompt'][select_input[0]]
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
inversed_switch_info[k] = input_node['inputs']['value']
else:
logging.warning(f"\n##### ##### #####\n[Impact Pack] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactInversedSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs if 'select_on_prompt' is selected.\n##### ##### #####\n")
else:
inversed_switch_info[k] = select_input
elif cls in ['ImpactSwitch', 'LatentSwitch', 'SEGSSwitch', 'ImpactMakeImageList']:
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode']:
# if 'sel_mode' is 'select_on_prompt'
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'select' in v['inputs']:
select_input = v['inputs']['select']
# if 'select' is converted input
if isinstance(select_input, list) and len(select_input) == 2:
input_node = json_data['prompt'][select_input[0]]
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
@@ -357,10 +354,29 @@ def onprompt_for_switch(json_data):
if isinstance(input_node['inputs']['select'], int):
onprompt_switch_info[k] = input_node['inputs']['select']
else:
print(f"\n##### ##### #####\n[WARN] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs.\n##### ##### #####\n")
logging.warning(f"\n##### ##### #####\n[Impact Pack] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs if 'select_on_prompt' is selected.\n##### ##### #####\n")
else:
onprompt_switch_info[k] = select_input
if k in onprompt_switch_info and f'input{onprompt_switch_info[k]}' not in v['inputs']:
# disconnect output
disabled_switch.add(k)
elif cls == 'ImpactConditionalBranchSelMode':
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'cond' in v['inputs']:
cond_input = v['inputs']['cond']
if isinstance(cond_input, list) and len(cond_input) == 2:
input_node = json_data['prompt'][cond_input[0]]
if (input_node['class_type'] == 'ImpactValueReceiver' and 'inputs' in input_node
and 'value' in input_node['inputs'] and 'typ' in input_node['inputs']):
if 'BOOLEAN' == input_node['inputs']['typ']:
try:
onprompt_cond_branch_info[k] = input_node['inputs']['value'].lower() == "true"
except:
pass
else:
onprompt_cond_branch_info[k] = cond_input
for k, v in json_data['prompt'].items():
disable_targets = set()
@@ -369,6 +385,11 @@ def onprompt_for_switch(json_data):
if vv[0] in inversed_switch_info:
if vv[1] + 1 != inversed_switch_info[vv[0]]:
disable_targets.add(kk)
else:
del inversed_switch_info[k]
if vv[0] in disabled_switch:
disable_targets.add(kk)
if k in onprompt_switch_info:
selected_slot_name = f"input{onprompt_switch_info[k]}"
@@ -376,10 +397,18 @@ def onprompt_for_switch(json_data):
if kk != selected_slot_name and kk.startswith('input'):
disable_targets.add(kk)
if k in onprompt_cond_branch_info:
selected_slot_name = "tt_value" if onprompt_cond_branch_info[k] else "ff_value"
for kk, vv in v['inputs'].items():
if kk in ['tt_value', 'ff_value'] and kk != selected_slot_name:
disable_targets.add(kk)
for kk in disable_targets:
del v['inputs'][kk]
return json_data
# inversed_switch - select out of range
for target in inversed_switch_info.keys():
del json_data['prompt'][target]['inputs']['input']
def onprompt_for_pickers(json_data):
@@ -404,9 +433,14 @@ def gc_preview_bridge_cache(json_data):
for key in list(core.preview_bridge_cache.keys()):
if key not in prompt_keys:
print(f"key deleted: {key}")
# print(f"key deleted [PB]: {key}")
del core.preview_bridge_cache[key]
for key in list(core.preview_bridge_last_mask_cache.keys()):
if key not in prompt_keys:
# print(f"key deleted [PB_last_mask]: {key}")
del core.preview_bridge_last_mask_cache[key]
def workflow_imagereceiver_update(json_data):
prompt = json_data['prompt']
@@ -437,20 +471,110 @@ def regional_sampler_seed_update(json_data):
new_seed = random.randint(0, 1125899906842624)
if new_seed is not None:
server.PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "seed_2nd", "type": "INT", "value": new_seed})
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "seed_2nd", "type": "INT", "value": new_seed})
def onprompt_populate_wildcards(json_data):
prompt = json_data['prompt']
updated_widget_values = {}
for k, v in prompt.items():
if 'class_type' in v and (v['class_type'] == 'ImpactWildcardEncode' or v['class_type'] == 'ImpactWildcardProcessor'):
inputs = v['inputs']
# legacy adapter
if isinstance(inputs['mode'], bool):
if inputs['mode']:
new_mode = 'populate'
else:
new_mode = 'fixed'
inputs['mode'] = new_mode
if inputs['mode'] == 'populate' and isinstance(inputs['populated_text'], str):
if isinstance(inputs['seed'], list):
try:
input_node = prompt[inputs['seed'][0]]
if input_node['class_type'] == 'ImpactInt':
input_seed = int(input_node['inputs']['value'])
if not isinstance(input_seed, int):
continue
if input_node['class_type'] == 'Seed (rgthree)':
input_seed = int(input_node['inputs']['seed'])
if not isinstance(input_seed, int):
continue
else:
logging.info(f"[Impact Pack] Only `ImpactInt`, `Seed (rgthree)` and `Primitive` Node are allowed as the seed for '{v['class_type']}'. It will be ignored. ")
continue
except:
continue
else:
input_seed = int(inputs['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']})
updated_widget_values[k] = inputs['populated_text']
if inputs['mode'] == 'reproduce':
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "mode", "type": "STRING", "value": 'populate'})
if 'extra_data' in json_data and 'extra_pnginfo' in json_data['extra_data']:
for node in json_data['extra_data']['extra_pnginfo']['workflow']['nodes']:
key = str(node['id'])
if key in updated_widget_values:
node['widgets_values'][1] = updated_widget_values[key]
node['widgets_values'][2] = 'reproduce'
def onprompt_for_remote(json_data):
prompt = json_data['prompt']
for v in prompt.values():
if 'class_type' in v:
cls = v['class_type']
if cls == 'ImpactRemoteBoolean' or cls == 'ImpactRemoteInt':
inputs = v['inputs']
node_id = str(inputs['node_id'])
if node_id not in prompt:
continue
target_inputs = prompt[node_id]['inputs']
widget_name = inputs['widget_name']
if widget_name in target_inputs:
widget_type = None
if cls == 'ImpactRemoteBoolean' and isinstance(target_inputs[widget_name], bool):
widget_type = 'BOOLEAN'
elif cls == 'ImpactRemoteInt' and (isinstance(target_inputs[widget_name], int) or isinstance(target_inputs[widget_name], float)):
widget_type = 'INT'
if widget_type is None:
break
target_inputs[widget_name] = inputs['value']
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": node_id, "widget_name": widget_name, "type": widget_type, "value": inputs['value']})
def onprompt(json_data):
try:
json_data = onprompt_for_switch(json_data)
onprompt_for_remote(json_data) # NOTE: top priority
onprompt_for_switch(json_data)
onprompt_for_pickers(json_data)
onprompt_populate_wildcards(json_data)
gc_preview_bridge_cache(json_data)
workflow_imagereceiver_update(json_data)
regional_sampler_seed_update(json_data)
core.current_prompt = json_data
except Exception as e:
print(f"[WARN] ComfyUI-Impact-Pack: Error on prompt - several features will not work.\n{e}")
logging.warning(f"[Impact Pack] ComfyUI-Impact-Pack: Error on prompt - several features will not work.\n{e}")
return json_data
server.PromptServer.instance.add_on_prompt_handler(onprompt)
PromptServer.instance.add_on_prompt_handler(onprompt)
+12
View File
@@ -25,6 +25,8 @@ class MMDetLoader:
CATEGORY = "ImpactPack/Legacy"
DEPRECATED = True
def load_mmdet(self, model_name):
mmdet_path = folder_paths.get_full_path("mmdets", model_name)
model = mmdet_nodes.load_mmdet(mmdet_path)
@@ -52,6 +54,8 @@ class BboxDetectorForEach:
CATEGORY = "ImpactPack/Legacy"
DEPRECATED = True
@staticmethod
def detect(bbox_model, image, threshold, dilation, crop_factor, drop_size=1, detailer_hook=None):
mmdet_results = mmdet_nodes.inference_bbox(bbox_model, image, threshold)
@@ -102,6 +106,8 @@ class SegmDetectorCombined:
CATEGORY = "ImpactPack/Legacy"
DEPRECATED = True
def doit(self, segm_model, image, threshold, dilation):
mmdet_results = mmdet_nodes.inference_segm(image, segm_model, threshold)
segmasks = core.create_segmasks(mmdet_results)
@@ -150,6 +156,8 @@ class SegmDetectorForEach:
CATEGORY = "ImpactPack/Legacy"
DEPRECATED = True
def doit(self, segm_model, image, threshold, dilation, crop_factor):
mmdet_results = mmdet_nodes.inference_segm(image, segm_model, threshold)
segmasks = core.create_segmasks(mmdet_results)
@@ -190,6 +198,8 @@ class SegsMaskCombine:
CATEGORY = "ImpactPack/Legacy"
DEPRECATED = True
@staticmethod
def combine(segs, image):
h = image.shape[1]
@@ -226,6 +236,8 @@ class MaskPainter(nodes.PreviewImage):
CATEGORY = "ImpactPack/Legacy"
DEPRECATED = True
def save_painted_images(self, images, filename_prefix="impact-mask",
prompt=None, extra_pnginfo=None, mask_image=None, image=None):
if image == "#placeholder" or image['image_hash'] != id(images):
+343 -58
View File
@@ -2,11 +2,12 @@ import sys
import time
import execution
import folder_paths
import impact.impact_server
from server import PromptServer
from impact.utils import any_typ
import impact.core as core
import re
import nodes
class ImpactCompare:
@@ -63,7 +64,46 @@ class ImpactConditionalBranch:
def INPUT_TYPES(cls):
return {
"required": {
"cond": ("BOOLEAN", {"forceInput": True}),
"cond": ("BOOLEAN",),
"tt_value": (any_typ,{"lazy": True}),
"ff_value": (any_typ,{"lazy": True}),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = (any_typ, )
def check_lazy_status(self, cond, tt_value=None, ff_value=None):
if cond and tt_value is None:
return ["tt_value"]
if not cond and ff_value is None:
return ["ff_value"]
def doit(self, cond, tt_value=None, ff_value=None):
if cond:
return (tt_value,)
else:
return (ff_value,)
class ImpactConditionalBranchSelMode:
@classmethod
def INPUT_TYPES(cls):
if not core.is_execution_model_version_supported():
required_inputs = {
"cond": ("BOOLEAN",),
"sel_mode": ("BOOLEAN", {"default": True, "label_on": "select_on_prompt", "label_off": "select_on_execution"}),
}
else:
required_inputs = {
"cond": ("BOOLEAN",),
}
return {
"required": required_inputs,
"optional": {
"tt_value": (any_typ,),
"ff_value": (any_typ,),
},
@@ -74,13 +114,92 @@ class ImpactConditionalBranch:
RETURN_TYPES = (any_typ, )
def doit(self, cond, tt_value, ff_value):
def doit(self, cond, tt_value=None, ff_value=None, **kwargs):
print(f'tt={tt_value is None}\nff={ff_value is None}')
if cond:
return (tt_value,)
else:
return (ff_value,)
class ImpactConvertDataType:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {"required": {"value": (any_typ,)}}
RETURN_TYPES = ("STRING", "FLOAT", "INT", "BOOLEAN")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
@staticmethod
def is_number(string):
pattern = re.compile(r'^[-+]?[0-9]*\.?[0-9]+$')
return bool(pattern.match(string))
def doit(self, value):
if self.is_number(str(value)):
num = value
else:
if str.lower(str(value)) != "false":
num = 1
else:
num = 0
return (str(value), float(num), int(float(num)), bool(float(num)), )
class ImpactIfNone:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {},
"optional": {"signal": (any_typ,), "any_input": (any_typ,), }
}
RETURN_TYPES = (any_typ, "BOOLEAN")
RETURN_NAMES = ("signal_opt", "bool")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
def doit(self, signal=None, any_input=None):
if any_input is None:
return (signal, False, )
else:
return (signal, True, )
class ImpactLogicalOperators:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"operator": (['and', 'or', 'xor'],),
"bool_a": ("BOOLEAN", {"forceInput": True}),
"bool_b": ("BOOLEAN", {"forceInput": True}),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ("BOOLEAN", )
def doit(self, operator, bool_a, bool_b):
if operator == "and":
return (bool_a and bool_b, )
elif operator == "or":
return (bool_a or bool_b, )
else:
return (bool_a != bool_b, )
class ImpactConditionalStopIteration:
@classmethod
def INPUT_TYPES(cls):
@@ -153,6 +272,24 @@ class ImpactFloat:
return (value, )
class ImpactBoolean:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"value": ("BOOLEAN", {"default": False}),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ("BOOLEAN", )
def doit(self, value):
return (value, )
class ImpactValueSender:
@classmethod
def INPUT_TYPES(cls):
@@ -224,7 +361,7 @@ class ImpactValueReceiver:
elif typ == "FLOAT":
return (float(value), )
elif typ == "BOOLEAN":
return (bool(value), )
return (value.lower() == "true", )
else:
return (value, )
@@ -248,6 +385,26 @@ class ImpactImageInfo:
return (value.shape[0], value.shape[1], value.shape[2], value.shape[3])
class ImpactLatentInfo:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"value": ("LATENT", ),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = ("INT", "INT", "INT", "INT")
RETURN_NAMES = ("batch", "height", "width", "channel")
def doit(self, value):
shape = value['samples'].shape
return (shape[0], shape[2] * 8, shape[3] * 8, shape[1])
class ImpactMinMax:
@classmethod
def INPUT_TYPES(cls):
@@ -298,26 +455,33 @@ class ImpactQueueTriggerCountdown:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"signal": (any_typ,),
"count": ("INT", {"default": 10, "min": 0, "max": 0xffffffffffffffff})
"count": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"total": ("INT", {"default": 10, "min": 1, "max": 0xffffffffffffffff}),
"mode": ("BOOLEAN", {"default": True, "label_on": "Trigger", "label_off": "Don't trigger"}),
},
"optional": {"signal": (any_typ,),},
"hidden": {"unique_id": "UNIQUE_ID"}
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = (any_typ, "INT")
RETURN_NAMES = ("signal_opt", "count")
RETURN_TYPES = (any_typ, "INT", "INT")
RETURN_NAMES = ("signal_opt", "count", "total")
OUTPUT_NODE = True
def doit(self, signal, count, unique_id):
if count > 0:
PromptServer.instance.send_sync("impact-node-feedback",
{"node_id": unique_id, "widget_name": "count", "type": "int", "value": count-1})
PromptServer.instance.send_sync("impact-add-queue", {})
def doit(self, count, total, mode, unique_id, signal=None):
if (mode):
if count < total - 1:
PromptServer.instance.send_sync("impact-node-feedback",
{"node_id": unique_id, "widget_name": "count", "type": "int", "value": count+1})
PromptServer.instance.send_sync("impact-add-queue", {})
if count >= total - 1:
PromptServer.instance.send_sync("impact-node-feedback",
{"node_id": unique_id, "widget_name": "count", "type": "int", "value": 0})
return (signal, count, total)
return (signal, count)
class ImpactSetWidgetValue:
@@ -410,27 +574,6 @@ class ImpactSleep:
return (signal,)
error_skip_flag = False
try:
import sys
def filter_message(str):
global error_skip_flag
if "IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE" in str:
return True
elif error_skip_flag and "ERROR:root:!!! Exception during processing !!!\n" == str:
error_skip_flag = False
return True
else:
return False
sys.__comfyui_manager_register_message_collapse(filter_message)
except Exception as e:
print(f"[WARN] ComfyUI-Impact-Pack: `ComfyUI` or `ComfyUI-Manager` is an outdated version.")
pass
def workflow_to_map(workflow):
nodes = {}
links = {}
@@ -442,53 +585,195 @@ def workflow_to_map(workflow):
return nodes, links
class ImpactRemoteBoolean:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"node_id": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"widget_name": ("STRING", {"multiline": False}),
"value": ("BOOLEAN", {"default": True, "label_on": "True", "label_off": "False"}),
}}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = ()
OUTPUT_NODE = True
def doit(self, **kwargs):
return {}
class ImpactRemoteInt:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"node_id": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"widget_name": ("STRING", {"multiline": False}),
"value": ("INT", {"default": 0, "min": -0xffffffffffffffff, "max": 0xffffffffffffffff}),
}}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = ()
OUTPUT_NODE = True
def doit(self, **kwargs):
return {}
class ImpactControlBridge:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"value": (any_typ,),
"mode": ("BOOLEAN", {"default": True, "label_on": "pass", "label_off": "block"}),
"mode": ("BOOLEAN", {"default": True, "label_on": "Active", "label_off": "Stop/Mute/Bypass"}),
"behavior": (["Stop", "Mute", "Bypass"], ),
},
"hidden": {"unique_id": "UNIQUE_ID", "prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = (any_typ,)
RETURN_NAMES = ("value",)
OUTPUT_NODE = True
def doit(self, value, mode, unique_id, prompt, extra_pnginfo):
DESCRIPTION = ("When behavior is Stop and mode is active, the input value is passed directly to the output.\n"
"When behavior is Mute/Bypass and mode is active, the node connected to the output is changed to active state.\n"
"When behavior is Stop and mode is Stop/Mute/Bypass, the workflow execution of the current node is halted.\n"
"When behavior is Mute/Bypass and mode is Stop/Mute/Bypass, the node connected to the output is changed to Mute/Bypass state.")
@classmethod
def IS_CHANGED(self, value, mode, behavior="Stop", unique_id=None, prompt=None, extra_pnginfo=None):
if behavior == "Stop":
return value, mode, behavior
else:
# NOTE: extra_pnginfo is not populated for IS_CHANGED.
# so extra_pnginfo is useless in here
try:
workflow = core.current_prompt['extra_data']['extra_pnginfo']['workflow']
except:
print(f"[Impact Pack] core.current_prompt['extra_data']['extra_pnginfo']['workflow']")
return 0
nodes, links = workflow_to_map(workflow)
next_nodes = []
for link in nodes[unique_id]['outputs'][0]['links']:
node_id = str(links[link][2])
impact.utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)
return next_nodes
def doit(self, value, mode, behavior="Stop", unique_id=None, prompt=None, extra_pnginfo=None):
global error_skip_flag
nodes, links = workflow_to_map(extra_pnginfo['workflow'])
outputs = [str(links[link][2]) for link in nodes[unique_id]['outputs'][0]['links']]
prompt_set = set(prompt.keys())
output_set = set(outputs)
if mode:
should_active_but_muted = output_set - prompt_set
if len(should_active_but_muted) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'actives': list(should_active_but_muted)})
error_skip_flag = True
raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")
if core.is_execution_model_version_supported():
from comfy_execution.graph import ExecutionBlocker
else:
should_muted_but_active = prompt_set.intersection(output_set)
if len(should_muted_but_active) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'mutes': list(should_muted_but_active)})
error_skip_flag = True
raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")
print("[Impact Pack] ImpactControlBridge: ComfyUI is outdated. The 'Stop' behavior cannot function properly.")
return (value, )
if behavior == "Stop":
if mode:
return (value, )
else:
return (ExecutionBlocker(None), )
elif extra_pnginfo is None:
logging.warn(f"[Impact Pack] limitation: '{behavior}' behavior cannot be used in API execution.")
return (value,)
else:
workflow_nodes, links = workflow_to_map(extra_pnginfo['workflow'])
active_nodes = []
mute_nodes = []
bypass_nodes = []
for link in workflow_nodes[unique_id]['outputs'][0]['links']:
node_id = str(links[link][2])
next_nodes = []
impact.utils.collect_non_reroute_nodes(workflow_nodes, links, next_nodes, node_id)
for next_node_id in next_nodes:
node_mode = workflow_nodes[next_node_id]['mode']
if node_mode == 0:
active_nodes.append(next_node_id)
elif node_mode == 2:
mute_nodes.append(next_node_id)
elif node_mode == 4:
bypass_nodes.append(next_node_id)
if mode:
# active
should_be_active_nodes = mute_nodes + bypass_nodes
if len(should_be_active_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'actives': list(should_be_active_nodes)})
nodes.interrupt_processing()
elif behavior == "Mute" or behavior == True:
# mute
should_be_mute_nodes = active_nodes + bypass_nodes
if len(should_be_mute_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'mutes': list(should_be_mute_nodes)})
nodes.interrupt_processing()
else:
# bypass
should_be_bypass_nodes = active_nodes + mute_nodes
if len(should_be_bypass_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'bypasses': list(should_be_bypass_nodes)})
nodes.interrupt_processing()
return (value, )
class ImpactExecutionOrderController:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"signal": (any_typ,),
"value": (any_typ,),
}}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
RETURN_TYPES = (any_typ, any_typ)
RETURN_NAMES = ("signal", "value")
def doit(self, signal, value):
return signal, value
class ImpactListBridge:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"list_input": (any_typ,),
}}
FUNCTION = "doit"
DESCRIPTION = "When passing the list output through this node, it collects and organizes the data before forwarding it, which ensures that the previous stage's sub-workflow has been completed."
CATEGORY = "ImpactPack/Util"
RETURN_TYPES = (any_typ, )
RETURN_NAMES = ("list_output", )
INPUT_IS_LIST = True
OUTPUT_IS_LIST = (True, )
@staticmethod
def doit(list_input):
return (list_input,)
original_handle_execution = execution.PromptExecutor.handle_execution_error
def handle_execution_error(**kwargs):
print(f" handled")
execution.PromptExecutor.handle_execution_error(**kwargs)
+7 -1
View File
@@ -1,5 +1,6 @@
import folder_paths
from impact.core import *
import os
import mmcv
from mmdet.apis import (inference_detector, init_detector)
@@ -178,7 +179,12 @@ class SegmDetector(BBoxDetector):
item = SEG(cropped_image, cropped_mask, confidence, crop_region, item_bbox, None, None)
items.append(item)
return image.shape, items
segs = image.shape, items
if detailer_hook is not None and hasattr(detailer_hook, "post_detection"):
segs = detailer_hook.post_detection(segs)
return segs
def detect_combined(self, image, threshold, dilation):
mmdet_results = inference_bbox(self.bbox_model, image, threshold)
+25 -6
View File
@@ -1,5 +1,7 @@
import folder_paths
import impact.wildcards
from impact.utils import any_typ
class ToDetailerPipe:
@classmethod
@@ -13,7 +15,7 @@ class ToDetailerPipe:
"bbox_detector": ("BBOX_DETECTOR", ),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"], ),
},
"optional": {
"sam_model_opt": ("SAM_MODEL",),
@@ -51,7 +53,7 @@ class ToDetailerPipeSDXL(ToDetailerPipe):
"bbox_detector": ("BBOX_DETECTOR", ),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"sam_model_opt": ("SAM_MODEL",),
@@ -108,6 +110,23 @@ class FromDetailerPipe_SDXL:
return detailer_pipe, model, clip, vae, positive, negative, bbox_detector, sam_model_opt, segm_detector_opt, detailer_hook, refiner_model, refiner_clip, refiner_positive, refiner_negative
class AnyPipeToBasic:
@classmethod
def INPUT_TYPES(s):
return {
"required": {"any_pipe": (any_typ,)},
}
RETURN_TYPES = ("BASIC_PIPE", )
RETURN_NAMES = ("basic_pipe", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, any_pipe):
return (any_pipe[:5], )
class ToBasicPipe:
@classmethod
def INPUT_TYPES(s):
@@ -170,7 +189,7 @@ class BasicPipeToDetailerPipe:
"bbox_detector": ("BBOX_DETECTOR", ),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"sam_model_opt": ("SAM_MODEL", ),
@@ -206,7 +225,7 @@ class BasicPipeToDetailerPipeSDXL:
"bbox_detector": ("BBOX_DETECTOR", ),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"sam_model_opt": ("SAM_MODEL", ),
@@ -305,7 +324,7 @@ class EditDetailerPipe:
"detailer_pipe": ("DETAILER_PIPE",),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"model": ("MODEL",),
@@ -402,7 +421,7 @@ class EditDetailerPipeSDXL(EditDetailerPipe):
"detailer_pipe": ("DETAILER_PIPE",),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"model": ("MODEL",),
-25
View File
@@ -1,25 +0,0 @@
import comfy.sample
import traceback
original_sample = comfy.sample.sample
def informative_sample(*args, **kwargs):
try:
return original_sample(*args, **kwargs) # This code helps interpret error messages that occur within exceptions but does not have any impact on other operations.
except RuntimeError as e:
is_model_mix_issue = False
try:
if 'mat1 and mat2 shapes cannot be multiplied' in e.args[0]:
if 'torch.nn.functional.linear' in traceback.format_exc().strip().split('\n')[-3]:
is_model_mix_issue = True
except:
pass
if is_model_mix_issue:
raise RuntimeError("\n\n#### It seems that models and clips are mixed and interconnected between SDXL Base, SDXL Refiner, SD1.x, and SD2.x. Please verify. ####\n\n")
else:
raise e
comfy.sample.sample = informative_sample
+1160 -240
View File
File diff suppressed because it is too large Load Diff
+137
View File
@@ -0,0 +1,137 @@
from impact.utils import *
from impact import impact_sampling
from comfy import model_management
from comfy.cli_args import args
import nodes
try:
from comfy_extras import nodes_differential_diffusion
except Exception:
print(f"[Impact Pack] ComfyUI is an outdated version. The DifferentialDiffusion feature will be disabled.")
# Implementation based on `https://github.com/lingondricka2/Upscaler-Detailer`
# code from comfyroll --->
# https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/blob/main/nodes/functions_upscale.py
def upscale_with_model(upscale_model, image):
device = model_management.get_torch_device()
upscale_model.to(device)
in_img = image.movedim(-1, -3).to(device)
free_memory = model_management.get_free_memory(device)
tile = 512
overlap = 32
oom = True
while oom:
try:
steps = in_img.shape[0] * comfy.utils.get_tiled_scale_steps(in_img.shape[3], in_img.shape[2], tile_x=tile, tile_y=tile, overlap=overlap)
pbar = comfy.utils.ProgressBar(steps)
s = comfy.utils.tiled_scale(in_img, lambda a: upscale_model(a), tile_x=tile, tile_y=tile, overlap=overlap, upscale_amount=upscale_model.scale, pbar=pbar)
oom = False
except model_management.OOM_EXCEPTION as e:
tile //= 2
if tile < 128:
raise e
s = torch.clamp(s.movedim(-3, -1), min=0, max=1.0)
return s
def apply_resize_image(image: Image.Image, original_width, original_height, rounding_modulus, mode='scale', supersample='true', factor: int = 2, width: int = 1024, height: int = 1024,
resample='bicubic'):
# Calculate the new width and height based on the given mode and parameters
if mode == 'rescale':
new_width, new_height = int(original_width * factor), int(original_height * factor)
else:
m = rounding_modulus
original_ratio = original_height / original_width
height = int(width * original_ratio)
new_width = width if width % m == 0 else width + (m - width % m)
new_height = height if height % m == 0 else height + (m - height % m)
# Define a dictionary of resampling filters
resample_filters = {'nearest': 0, 'bilinear': 2, 'bicubic': 3, 'lanczos': 1}
# Apply supersample
if supersample == 'true':
image = image.resize((new_width * 8, new_height * 8), resample=Image.Resampling(resample_filters[resample]))
# Resize the image using the given resampling filter
resized_image = image.resize((new_width, new_height), resample=Image.Resampling(resample_filters[resample]))
return resized_image
def upscaler(image, upscale_model, rescale_factor, resampling_method, supersample, rounding_modulus):
if upscale_model is not None:
up_image = upscale_with_model(upscale_model, image)
else:
up_image = image
pil_img = tensor2pil(image)
original_width, original_height = pil_img.size
scaled_image = pil2tensor(apply_resize_image(tensor2pil(up_image), original_width, original_height, rounding_modulus, 'rescale',
supersample, rescale_factor, 1024, resampling_method))
return scaled_image
# <---
def img2img_segs(image, model, clip, vae, seed, steps, cfg, sampler_name, scheduler,
positive, negative, denoise, noise_mask, control_net_wrapper=None,
inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
original_image_size = image.shape[1:3]
# Match to original image size
if original_image_size[0] % 8 > 0 or original_image_size[1] % 8 > 0:
scale = 8/min(original_image_size[0], original_image_size[1]) + 1
w = int(original_image_size[1] * scale)
h = int(original_image_size[0] * scale)
image = tensor_resize(image, w, h)
if noise_mask is not None:
noise_mask = tensor_gaussian_blur_mask(noise_mask, noise_mask_feather)
noise_mask = noise_mask.squeeze(3)
if noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
if control_net_wrapper is not None:
positive, negative, _ = control_net_wrapper.apply(positive, negative, image, noise_mask)
# 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, 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, image, vae, noise_mask)
else:
latent_image = to_latent_image(image, vae)
if noise_mask is not None:
latent_image['noise_mask'] = noise_mask
refined_latent = latent_image
# ksampler
refined_latent = impact_sampling.ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, refined_latent, denoise, scheduler_func=scheduler_func_opt)
# non-latent downscale - latent downscale cause bad quality
refined_image = vae.decode(refined_latent['samples'])
# prevent mixing of device
refined_image = refined_image.cpu()
# Match to original image size
if refined_image.shape[1:3] != original_image_size:
refined_image = tensor_resize(refined_image, original_image_size[1], original_image_size[0])
# don't convert to latent - latent break image
# preserving pil is much better
return refined_image
+307 -172
View File
@@ -1,34 +1,37 @@
import time
import comfy
import math
import impact.core as core
from comfy_extras.nodes_custom_sampler import Noise_RandomNoise
from impact.utils import *
from nodes import MAX_RESOLUTION
import nodes
from impact.impact_sampling import KSamplerWrapper, KSamplerAdvancedWrapper, separated_sample, impact_sample
import comfy
class TiledKSamplerProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"tile_width": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64}),
"tile_height": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64}),
"tiling_strategy": (["random", "padded", 'simple'], ),
"basic_pipe": ("BASIC_PIPE", )
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "tooltip": "classifier free guidance value"}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "sampler"}),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, {"tooltip": "noise schedule"}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
"tile_width": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64, "tooltip": "Sets the width of the tile to be used in TiledKSampler."}),
"tile_height": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64, "tooltip": "Sets the height of the tile to be used in TiledKSampler."}),
"tiling_strategy": (["random", "padded", 'simple'], {"tooltip": "Sets the tiling strategy for TiledKSampler."} ),
"basic_pipe": ("BASIC_PIPE", {"tooltip": "basic_pipe input for sampling"})
}}
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
RETURN_TYPES = ("KSAMPLER",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
def doit(self, seed, steps, cfg, sampler_name, scheduler, denoise,
@staticmethod
def doit(seed, steps, cfg, sampler_name, scheduler, denoise,
tile_width, tile_height, tiling_strategy, basic_pipe):
model, _, _, positive, negative = basic_pipe
sampler = core.TiledKSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise,
@@ -40,24 +43,30 @@ class KSamplerProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"basic_pipe": ("BASIC_PIPE", )
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "tooltip": "classifier free guidance value"}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "sampler"}),
"scheduler": (core.SCHEDULERS, {"tooltip": "noise schedule"}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
"basic_pipe": ("BASIC_PIPE", {"tooltip": "basic_pipe input for sampling"})
},
"optional": {
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
}
}
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)",)
RETURN_TYPES = ("KSAMPLER",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
def doit(self, seed, steps, cfg, sampler_name, scheduler, denoise, basic_pipe):
@staticmethod
def doit(seed, steps, cfg, sampler_name, scheduler, denoise, basic_pipe, scheduler_func_opt=None):
model, _, _, positive, negative = basic_pipe
sampler = core.KSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise)
sampler = KSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, scheduler_func=scheduler_func_opt)
return (sampler, )
@@ -65,21 +74,29 @@ class KSamplerAdvancedProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"basic_pipe": ("BASIC_PIPE", )
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "toolip": "classifier free guidance value"}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"toolip": "sampler"}),
"scheduler": (core.SCHEDULERS, {"toolip": "noise schedule"}),
"sigma_factor": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01, "toolip": "Multiplier of noise schedule"}),
"basic_pipe": ("BASIC_PIPE", {"toolip": "basic_pipe input for sampling"})
},
"optional": {
"sampler_opt": ("SAMPLER", {"toolip": "[OPTIONAL] Uses the passed sampler instead of internal impact_sampler."}),
"scheduler_func_opt": ("SCHEDULER_FUNC", {"toolip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
}
}
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
RETURN_TYPES = ("KSAMPLER_ADVANCED",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
def doit(self, cfg, sampler_name, scheduler, basic_pipe):
@staticmethod
def doit(cfg, sampler_name, scheduler, basic_pipe, sigma_factor=1.0, sampler_opt=None, scheduler_func_opt=None):
model, _, _, positive, negative = basic_pipe
sampler = core.KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative)
sampler = KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=sampler_opt, sigma_factor=sigma_factor, scheduler_func=scheduler_func_opt)
return (sampler, )
@@ -87,19 +104,22 @@ class TwoSamplersForMask:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"latent_image": ("LATENT", ),
"base_sampler": ("KSAMPLER", ),
"mask_sampler": ("KSAMPLER", ),
"mask": ("MASK", )
"latent_image": ("LATENT", {"tooltip": "input latent image"}),
"base_sampler": ("KSAMPLER", {"tooltip": "Sampler to apply to the region outside the mask."}),
"mask_sampler": ("KSAMPLER", {"tooltip": "Sampler to apply to the masked region."}),
"mask": ("MASK", {"tooltip": "region mask"})
},
}
OUTPUT_TOOLTIPS = ("result latent", )
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
def doit(self, latent_image, base_sampler, mask_sampler, mask):
@staticmethod
def doit(latent_image, base_sampler, mask_sampler, mask):
inv_mask = torch.where(mask != 1.0, torch.tensor(1.0), torch.tensor(0.0))
latent_image['noise_mask'] = inv_mask
@@ -117,82 +137,59 @@ class TwoAdvancedSamplersForMask:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"samples": ("LATENT", ),
"base_sampler": ("KSAMPLER_ADVANCED", ),
"mask_sampler": ("KSAMPLER_ADVANCED", ),
"mask": ("MASK", ),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000})
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
"samples": ("LATENT", {"tooltip": "input latent image"}),
"base_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "Sampler to apply to the region outside the mask."}),
"mask_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "Sampler to apply to the masked region."}),
"mask": ("MASK", {"tooltip": "region mask"}),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000, "tooltip": "To smooth the seams of the region boundaries, expand the mask by the overlap_factor amount to overlap with other regions."})
},
}
OUTPUT_TOOLTIPS = ("result latent", )
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
@staticmethod
def mask_erosion(samples, mask, grow_mask_by):
mask = mask.clone()
def doit(seed, steps, denoise, samples, base_sampler, mask_sampler, mask, overlap_factor):
regional_prompts = RegionalPrompt().doit(mask=mask, advanced_sampler=mask_sampler)[0]
w = samples['samples'].shape[3]
h = samples['samples'].shape[2]
mask2 = torch.nn.functional.interpolate(mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])), size=(w, h), mode="bilinear")
if grow_mask_by == 0:
mask_erosion = mask2
else:
kernel_tensor = torch.ones((1, 1, grow_mask_by, grow_mask_by))
padding = math.ceil((grow_mask_by - 1) / 2)
mask_erosion = torch.clamp(torch.nn.functional.conv2d(mask2.round(), kernel_tensor, padding=padding), 0, 1)
return mask_erosion[:, :, :w, :h].round()
def doit(self, seed, steps, denoise, samples, base_sampler, mask_sampler, mask, overlap_factor):
inv_mask = torch.where(mask != 1.0, torch.tensor(1.0), torch.tensor(0.0))
adv_steps = int(steps / denoise)
start_at_step = adv_steps - steps
new_latent_image = samples.copy()
mask_erosion = TwoAdvancedSamplersForMask.mask_erosion(samples, mask, overlap_factor)
for i in range(start_at_step, adv_steps):
add_noise = "enable" if i == start_at_step else "disable"
return_with_leftover_noise = "enable" if i+1 != adv_steps else "disable"
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image, i, i + 1, "enable", recover_special_sampler=True)
new_latent_image['noise_mask'] = mask_erosion
new_latent_image = mask_sampler.sample_advanced("disable", seed, adv_steps, new_latent_image, i, i + 1, return_with_leftover_noise, recover_special_sampler=True)
del new_latent_image['noise_mask']
return (new_latent_image, )
return RegionalSampler().doit(seed=seed, seed_2nd=0, seed_2nd_mode="ignore", steps=steps, base_only_steps=1,
denoise=denoise, samples=samples, base_sampler=base_sampler,
regional_prompts=regional_prompts, overlap_factor=overlap_factor,
restore_latent=True, additional_mode="ratio between",
additional_sampler="AUTO", additional_sigma_ratio=0.3)
class RegionalPrompt:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"mask": ("MASK", ),
"advanced_sampler": ("KSAMPLER_ADVANCED", ),
},
"mask": ("MASK", {"tooltip": "region mask"}),
"advanced_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "sampler for specified region"}),
},
"optional": {
"variation_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Sets the extra seed to be used for noise variation."}),
"variation_strength": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Sets the strength of the noise variation."}),
"variation_method": (["linear", "slerp"], {"tooltip": "Sets how the original noise and extra noise are blended together."}),
}
}
OUTPUT_TOOLTIPS = ("regional prompts. (Can be used in the RegionalSampler.)", )
RETURN_TYPES = ("REGIONAL_PROMPTS", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Regional"
def doit(self, mask, advanced_sampler):
regional_prompt = core.REGIONAL_PROMPT(mask, advanced_sampler)
@staticmethod
def doit(mask, advanced_sampler, variation_seed=0, variation_strength=0.0, variation_method="linear"):
regional_prompt = core.REGIONAL_PROMPT(mask, advanced_sampler, variation_seed=variation_seed, variation_strength=variation_strength, variation_method=variation_method)
return ([regional_prompt], )
@@ -200,16 +197,19 @@ class CombineRegionalPrompts:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"regional_prompts1": ("REGIONAL_PROMPTS", ),
"regional_prompts1": ("REGIONAL_PROMPTS", {"tooltip": "input regional_prompts. (Connecting to the input slot increases the number of additional slots.)"}),
},
}
OUTPUT_TOOLTIPS = ("Combined REGIONAL_PROMPTS", )
RETURN_TYPES = ("REGIONAL_PROMPTS", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Regional"
def doit(self, **kwargs):
@staticmethod
def doit(**kwargs):
res = []
for k, v in kwargs.items():
res += v
@@ -221,47 +221,96 @@ class CombineConditionings:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"conditioning1": ("CONDITIONING", ),
"conditioning1": ("CONDITIONING", { "tooltip": "input conditionings. (Connecting to the input slot increases the number of additional slots.)" }),
},
}
OUTPUT_TOOLTIPS = ("Combined conditioning", )
RETURN_TYPES = ("CONDITIONING", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
@staticmethod
def doit(**kwargs):
res = []
for k, v in kwargs.items():
res += v
return (res, )
class ConcatConditionings:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"conditioning1": ("CONDITIONING", { "tooltip": "input conditionings. (Connecting to the input slot increases the number of additional slots.)" }),
},
}
OUTPUT_TOOLTIPS = ("Concatenated conditioning", )
RETURN_TYPES = ("CONDITIONING", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
@staticmethod
def doit(**kwargs):
conditioning_to = list(kwargs.values())[0]
for k, conditioning_from in list(kwargs.items())[1:]:
out = []
if len(conditioning_from) > 1:
print("Warning: ConcatConditionings {k} contains more than 1 cond, only the first one will actually be applied to conditioning1.")
cond_from = conditioning_from[0][0]
for i in range(len(conditioning_to)):
t1 = conditioning_to[i][0]
tw = torch.cat((t1, cond_from), 1)
n = [tw, conditioning_to[i][1].copy()]
out.append(n)
conditioning_to = out
return (out, )
class RegionalSampler:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"seed_2nd": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"seed_2nd_mode": (["ignore", "fixed", "seed+seed_2nd", "seed-seed_2nd", "increment", "decrement", "randomize"], ),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"base_only_steps": ("INT", {"default": 2, "min": 0, "max": 10000}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"samples": ("LATENT", ),
"base_sampler": ("KSAMPLER_ADVANCED", ),
"regional_prompts": ("REGIONAL_PROMPTS", ),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000}),
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
"seed_2nd": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Additional noise seed. The behavior is determined by seed_2nd_mode."}),
"seed_2nd_mode": (["ignore", "fixed", "seed+seed_2nd", "seed-seed_2nd", "increment", "decrement", "randomize"], {"tooltip": "application method of seed_2nd. 1) ignore: Do not use seed_2nd. In the base only sampling stage, the seed is applied as a noise seed, and in the regional sampling stage, denoising is performed as it is without additional noise. 2) Others: In the base only sampling stage, the seed is applied as a noise seed, and once it is closed so that there is no leftover noise, new noise is added with seed_2nd and the regional samping stage is performed. a) fixed: Use seed_2nd as it is as an additional noise seed. b) seed+seed_2nd: Apply the value of seed+seed_2nd as an additional noise seed. c) seed-seed_2nd: Apply the value of seed-seed_2nd as an additional noise seed. d) increment: Not implemented yet. Same with fixed. e) decrement: Not implemented yet. Same with fixed. f) randomize: Not implemented yet. Same with fixed."}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
"base_only_steps": ("INT", {"default": 2, "min": 0, "max": 10000, "tooltip": "total sampling steps"}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
"samples": ("LATENT", {"tooltip": "input latent image"}),
"base_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "The sampler applied outside the area set by the regional_prompt."}),
"regional_prompts": ("REGIONAL_PROMPTS", {"tooltip": "The prompt applied to each region"}),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000, "tooltip": "To smooth the seams of the region boundaries, expand the mask set in regional_prompts by the overlap_factor amount to overlap with other regions."}),
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled", "tooltip": "At each step, restore the noise outside the mask area to its original state, as per the principle of inpainting. This option is provided for backward compatibility, and it is recommended to always set it to true."}),
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between", "tooltip": "..._sde or uni_pc and other special samplers are used, the region is not properly denoised, and it causes a phenomenon that destroys the overall harmony. To compensate for this, a recovery operation is performed using another sampler. This requires a longer time for sampling because a second sampling is performed at each step in each region using a special sampler. 1) DISABLE: Disable this feature. 2) ratio additional: After performing the denoise amount to be performed in the step with the sampler set in the region, the recovery sampler is additionally applied by the additional_sigma_ratio. If you use this option, the total denoise amount increases by additional_sigma_ratio. 3) ratio between: The denoise amount to be performed in the step with the sampler set in the region and the denoise amount to be applied to the recovery sampler are divided by additional_sigma_ratio, and denoise is performed for each denoise amount. If you use this option, the total denoise amount does not change."}),
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"], {"tooltip": "1) AUTO: Automatically set the recovery sampler. If the sampler is uni_pc, uni_pc_bh2, dpmpp_sde, dpmpp_sde_gpu, the dpm_fast sampler is selected If the sampler is dpmpp_2m_sde, dpmpp_2m_sde_gpu, dpmpp_3m_sde, dpmpp_3m_sde_gpu, the dpmpp_2m sampler is selected. 2) Others: Manually set the recovery sampler."}),
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Multiplier of noise schedule to be applied according to additional_mode."}),
},
"hidden": {"unique_id": "UNIQUE_ID"},
"hidden": {"unique_id": "UNIQUE_ID"},
}
OUTPUT_TOOLTIPS = ("result latent", )
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Regional"
@staticmethod
def separated_sample(*args, **kwargs):
return separated_sample(*args, **kwargs)
@staticmethod
def mask_erosion(samples, mask, grow_mask_by):
mask = mask.clone()
@@ -280,7 +329,13 @@ class RegionalSampler:
return mask_erosion[:, :, :w, :h].round()
def doit(self, seed, seed_2nd, seed_2nd_mode, steps, base_only_steps, denoise, samples, base_sampler, regional_prompts, overlap_factor, restore_latent, unique_id=None):
@staticmethod
def doit(seed, seed_2nd, seed_2nd_mode, steps, base_only_steps, denoise, samples, base_sampler, regional_prompts, overlap_factor, restore_latent,
additional_mode, additional_sampler, additional_sigma_ratio, unique_id=None):
samples = samples.copy()
samples['samples'] = comfy.sample.fix_empty_latent_channels(base_sampler.params[0], samples['samples'])
if restore_latent:
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
else:
@@ -298,12 +353,17 @@ class RegionalSampler:
region_len = len(regional_prompts)
total = steps*region_len
leftover_noise = 'disable'
leftover_noise = False
if base_only_steps > 0:
if seed_2nd_mode == 'ignore':
leftover_noise = 'enable'
leftover_noise = True
samples = base_sampler.sample_advanced("enable", seed, adv_steps, samples, start_at_step, start_at_step + base_only_steps, leftover_noise, recover_special_sampler=False)
noise = Noise_RandomNoise(seed).generate_noise(samples)
for rp in regional_prompts:
noise = rp.touch_noise(noise)
samples = base_sampler.sample_advanced(True, seed, adv_steps, samples, start_at_step, start_at_step + base_only_steps, leftover_noise, recovery_mode="DISABLE", noise=noise)
if seed_2nd_mode == "seed+seed_2nd":
seed += seed_2nd
@@ -319,16 +379,23 @@ class RegionalSampler:
new_latent_image = samples.copy()
base_latent_image = None
if leftover_noise != 'enable':
add_noise = "enable"
if not leftover_noise:
add_noise = True
noise = Noise_RandomNoise(seed).generate_noise(samples)
for rp in regional_prompts:
noise = rp.touch_noise(noise)
else:
add_noise = "disable"
add_noise = False
noise = None
for i in range(start_at_step+base_only_steps, adv_steps):
core.update_node_status(unique_id, f"{i}/{steps} steps | ", ((i-start_at_step)*region_len)/total)
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image, i, i + 1, "enable", recover_special_sampler=True)
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image,
start_at_step=i, end_at_step=i + 1, return_with_leftover_noise=True,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio, noise=noise)
if restore_latent:
if 'noise_mask' in new_latent_image:
@@ -345,8 +412,8 @@ class RegionalSampler:
region_mask = regional_prompt.get_mask_erosion(overlap_factor).squeeze(0).squeeze(0)
new_latent_image['noise_mask'] = region_mask
new_latent_image = regional_prompt.sampler.sample_advanced("disable", seed, adv_steps, new_latent_image,
i, i + 1, "enable", recover_special_sampler=True)
new_latent_image = regional_prompt.sampler.sample_advanced(False, seed, adv_steps, new_latent_image, i, i + 1, True,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
if restore_latent:
del new_latent_image['noise_mask']
@@ -355,7 +422,7 @@ class RegionalSampler:
j += 1
add_noise = 'disable'
add_noise = False
# finalize
core.update_node_status(unique_id, f"finalize")
@@ -365,7 +432,8 @@ class RegionalSampler:
base_latent_image = new_latent_image
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced("disable", seed, adv_steps, new_latent_image, adv_steps, adv_steps+1, "disable", recover_special_sampler=False)
new_latent_image = base_sampler.sample_advanced(False, seed, adv_steps, new_latent_image, adv_steps, adv_steps+1, False,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
core.update_node_status(unique_id, f"{steps}/{steps} steps", total)
core.update_node_status(unique_id, "", None)
@@ -383,28 +451,38 @@ class RegionalSamplerAdvanced:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000}),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000}),
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
"latent_image": ("LATENT", ),
"base_sampler": ("KSAMPLER_ADVANCED", ),
"regional_prompts": ("REGIONAL_PROMPTS", ),
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled", "tooltip": "Whether to add noise"}),
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000, "tooltip": "The starting step of the sampling to be applied at this node within the range of 'steps'."}),
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000, "tooltip": "The step at which sampling applied at this node will stop within the range of steps (if greater than steps, sampling will continue only up to steps)."}),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000, "tooltip": "To smooth the seams of the region boundaries, expand the mask set in regional_prompts by the overlap_factor amount to overlap with other regions."}),
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled", "tooltip": "At each step, restore the noise outside the mask area to its original state, as per the principle of inpainting. This option is provided for backward compatibility, and it is recommended to always set it to true."}),
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled", "tooltip": "Whether to return the latent with noise remaining if the noise has not been completely removed according to the noise schedule, or to completely remove the noise before returning it."}),
"latent_image": ("LATENT", {"tooltip": "input latent image"}),
"base_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "The sampler applied outside the area set by the regional_prompt."}),
"regional_prompts": ("REGIONAL_PROMPTS", {"tooltip": "The prompt applied to each region"}),
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between", "tooltip": "..._sde or uni_pc and other special samplers are used, the region is not properly denoised, and it causes a phenomenon that destroys the overall harmony. To compensate for this, a recovery operation is performed using another sampler. This requires a longer time for sampling because a second sampling is performed at each step in each region using a special sampler. 1) DISABLE: Disable this feature. 2) ratio additional: After performing the denoise amount to be performed in the step with the sampler set in the region, the recovery sampler is additionally applied by the additional_sigma_ratio. If you use this option, the total denoise amount increases by additional_sigma_ratio. 3) ratio between: The denoise amount to be performed in the step with the sampler set in the region and the denoise amount to be applied to the recovery sampler are divided by additional_sigma_ratio, and denoise is performed for each denoise amount. If you use this option, the total denoise amount does not change."}),
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"], {"tooltip": "1) AUTO: Automatically set the recovery sampler. If the sampler is uni_pc, uni_pc_bh2, dpmpp_sde, dpmpp_sde_gpu, the dpm_fast sampler is selected If the sampler is dpmpp_2m_sde, dpmpp_2m_sde_gpu, dpmpp_3m_sde, dpmpp_3m_sde_gpu, the dpmpp_2m sampler is selected. 2) Others: Manually set the recovery sampler."}),
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Multiplier of noise schedule to be applied according to additional_mode."}),
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
OUTPUT_TOOLTIPS = ("result latent", )
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Regional"
def doit(self, add_noise, noise_seed, steps, start_at_step, end_at_step, overlap_factor, restore_latent,
return_with_leftover_noise, latent_image, base_sampler, regional_prompts, unique_id):
@staticmethod
def doit(add_noise, noise_seed, steps, start_at_step, end_at_step, overlap_factor, restore_latent, return_with_leftover_noise, latent_image, base_sampler, regional_prompts,
additional_mode, additional_sampler, additional_sigma_ratio, unique_id):
new_latent_image = latent_image.copy()
new_latent_image['samples'] = comfy.sample.fix_empty_latent_channels(base_sampler.params[0], new_latent_image['samples'])
if restore_latent:
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
else:
@@ -420,17 +498,24 @@ class RegionalSamplerAdvanced:
end_at_step = min(steps, end_at_step)
total = (end_at_step - start_at_step) * region_len
new_latent_image = latent_image.copy()
base_latent_image = None
region_masks = {}
for i in range(start_at_step, end_at_step):
for i in range(start_at_step, end_at_step-1):
core.update_node_status(unique_id, f"{start_at_step+i}/{end_at_step} steps | ", ((i-start_at_step)*region_len)/total)
cur_add_noise = "enable" if i == start_at_step and add_noise else "disable"
cur_add_noise = True if i == start_at_step and add_noise else False
if cur_add_noise:
noise = Noise_RandomNoise(noise_seed).generate_noise(new_latent_image)
for rp in regional_prompts:
noise = rp.touch_noise(noise)
else:
noise = None
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced(cur_add_noise, noise_seed, steps, new_latent_image, i, i + 1, "enable", recover_special_sampler=True)
new_latent_image = base_sampler.sample_advanced(cur_add_noise, noise_seed, steps, new_latent_image, i, i + 1, True,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio, noise=noise)
if restore_latent:
del new_latent_image['noise_mask']
@@ -450,8 +535,8 @@ class RegionalSamplerAdvanced:
region_mask = region_masks[j]
new_latent_image['noise_mask'] = region_mask
new_latent_image = regional_prompt.sampler.sample_advanced("disable", noise_seed, steps, new_latent_image,
i, i + 1, "enable", recover_special_sampler=True)
new_latent_image = regional_prompt.sampler.sample_advanced(False, noise_seed, steps, new_latent_image, i, i + 1, True,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
if restore_latent:
del new_latent_image['noise_mask']
@@ -468,7 +553,8 @@ class RegionalSamplerAdvanced:
base_latent_image = new_latent_image
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced("disable", noise_seed, steps, new_latent_image, end_at_step, end_at_step+1, return_with_leftover_noise, recover_special_sampler=False)
new_latent_image = base_sampler.sample_advanced(False, noise_seed, steps, new_latent_image, end_at_step-1, end_at_step, return_with_leftover_noise,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
core.update_node_status(unique_id, f"{end_at_step}/{end_at_step} steps", total)
core.update_node_status(unique_id, "", None)
@@ -486,63 +572,112 @@ class KSamplerBasicPipe:
@classmethod
def INPUT_TYPES(s):
return {"required":
{"basic_pipe": ("BASIC_PIPE",),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"latent_image": ("LATENT", ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
}
{"basic_pipe": ("BASIC_PIPE", {"tooltip": "basic_pipe input for sampling"}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "tooltip": "classifier free guidance value"}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "sampler"}),
"scheduler": (core.SCHEDULERS, {"tooltip": "noise schedule"}),
"latent_image": ("LATENT", {"tooltip": "input latent image"}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
},
"optional":
{
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
}
}
OUTPUT_TOOLTIPS = ("passthrough input basic_pipe", "result latent", "VAE in basic_pipe")
RETURN_TYPES = ("BASIC_PIPE", "LATENT", "VAE")
FUNCTION = "sample"
CATEGORY = "sampling"
CATEGORY = "ImpactPack/sampling"
def sample(self, basic_pipe, seed, steps, cfg, sampler_name, scheduler, latent_image, denoise=1.0):
@staticmethod
def sample(basic_pipe, seed, steps, cfg, sampler_name, scheduler, latent_image, denoise=1.0, scheduler_func_opt=None):
model, clip, vae, positive, negative = basic_pipe
latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)[0]
return (basic_pipe, latent, vae)
latent = impact_sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise, scheduler_func=scheduler_func_opt)
return basic_pipe, latent, vae
class KSamplerAdvancedBasicPipe:
@classmethod
def INPUT_TYPES(s):
return {"required":
{"basic_pipe": ("BASIC_PIPE",),
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enable", "label_off": "disable"}),
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"latent_image": ("LATENT", ),
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000}),
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enable", "label_off": "disable"}),
}
{"basic_pipe": ("BASIC_PIPE", {"tooltip": "basic_pipe input for sampling"}),
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enable", "label_off": "disable", "tooltip": "Whether to add noise"}),
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "tooltip": "classifier free guidance value"}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "sampler"}),
"scheduler": (core.SCHEDULERS, {"tooltip": "noise schedule"}),
"latent_image": ("LATENT", {"tooltip": "input latent image"}),
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000, "tooltip": "The starting step of the sampling to be applied at this node within the range of 'steps'."}),
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000, "tooltip": "The step at which sampling applied at this node will stop within the range of steps (if greater than steps, sampling will continue only up to steps)."}),
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enable", "label_off": "disable", "tooltip": "Whether to return the latent with noise remaining if the noise has not been completely removed according to the noise schedule, or to completely remove the noise before returning it."}),
},
"optional":
{
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
}
}
OUTPUT_TOOLTIPS = ("passthrough input basic_pipe", "result latent", "VAE in basic_pipe")
RETURN_TYPES = ("BASIC_PIPE", "LATENT", "VAE")
FUNCTION = "sample"
CATEGORY = "sampling"
CATEGORY = "ImpactPack/sampling"
def sample(self, basic_pipe, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise=1.0):
@staticmethod
def sample(basic_pipe, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise=1.0, scheduler_func_opt=None):
model, clip, vae, positive, negative = basic_pipe
if add_noise:
add_noise = "enable"
else:
add_noise = "disable"
latent = separated_sample(model, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, start_at_step, end_at_step, return_with_leftover_noise, scheduler_func=scheduler_func_opt)
return basic_pipe, latent, vae
if return_with_leftover_noise:
return_with_leftover_noise = "enable"
else:
return_with_leftover_noise = "disable"
latent = nodes.KSamplerAdvanced().sample(model, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise)[0]
return (basic_pipe, latent, vae)
class GITSSchedulerFuncProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"coeff": ("FLOAT", {"default": 1.20, "min": 0.80, "max": 1.50, "step": 0.05, "tooltip": "coeff factor of GITS Scheduler"}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "denoise amount for noise schedule"}),
}
}
OUTPUT_TOOLTIPS = ("Returns a function that generates a noise schedule using GITSScheduler. This can be used in place of a predetermined noise schedule to dynamically generate a noise schedule based on the steps.",)
RETURN_TYPES = ("SCHEDULER_FUNC",)
CATEGORY = "ImpactPack/sampling"
FUNCTION = "doit"
@staticmethod
def doit(coeff, denoise):
def f(model, sampler, steps):
if 'GITSScheduler' not in nodes.NODE_CLASS_MAPPINGS:
raise Exception("[Impact Pack] ComfyUI is an outdated version. Cannot use GITSScheduler.")
scheduler = nodes.NODE_CLASS_MAPPINGS['GITSScheduler']()
return scheduler.get_sigmas(coeff, steps, denoise)[0]
return (f, )
class NegativeConditioningPlaceholder:
@classmethod
def INPUT_TYPES(s):
return {"required": {}}
OUTPUT_TOOLTIPS = ("This is a Placeholder for the FLUX model that does not use Negative Conditioning.",)
RETURN_TYPES = ("CONDITIONING",)
CATEGORY = "ImpactPack/sampling"
FUNCTION = "doit"
@staticmethod
def doit():
return ("NegativePlaceholder", )
+577 -37
View File
@@ -1,75 +1,115 @@
from impact.utils import any_typ
from impact.utils import any_typ, ByPassTypeTuple, make_3d_mask
import comfy_extras.nodes_mask
from nodes import MAX_RESOLUTION
import torch
import comfy
import sys
import nodes
import re
import impact.core as core
from server import PromptServer
import inspect
class GeneralSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
"sel_mode": ("BOOLEAN", {"default": True, "label_on": "select_on_prompt", "label_off": "select_on_execution", "forceInput": False}),
},
"optional": {
"input1": (any_typ,),
dyn_inputs = {"input1": (any_typ, {"lazy": True, "tooltip": "Any input. When connected, one more input slot is added."}), }
if core.is_execution_model_version_supported():
stack = inspect.stack()
if stack[2].function == 'get_input_info':
# bypass validation
class AllContainer:
def __contains__(self, item):
return True
def __getitem__(self, key):
return any_typ, {"lazy": True}
dyn_inputs = AllContainer()
inputs = {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1, "tooltip": "The input number you want to output among the inputs"}),
"sel_mode": ("BOOLEAN", {"default": False, "label_on": "select_on_prompt", "label_off": "select_on_execution", "forceInput": False,
"tooltip": "In the case of 'select_on_execution', the selection is dynamically determined at the time of workflow execution. 'select_on_prompt' is an option that exists for older versions of ComfyUI, and it makes the decision before the workflow execution."}),
},
"optional": dyn_inputs,
"hidden": {"unique_id": "UNIQUE_ID", "extra_pnginfo": "EXTRA_PNGINFO"}
}
return inputs
RETURN_TYPES = (any_typ, "STRING", "INT")
RETURN_NAMES = ("selected_value", "selected_label", "selected_index")
OUTPUT_TOOLTIPS = ("Output is generated only from the input chosen by the 'select' value.", "Slot label of the selected input slot", "Outputs the select value as is")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, *args, **kwargs):
def check_lazy_status(self, *args, **kwargs):
selected_index = int(kwargs['select'])
input_name = f"input{selected_index}"
print(f"SELECTED: {input_name}")
if input_name in kwargs:
return [input_name]
else:
return []
@staticmethod
def doit(*args, **kwargs):
selected_index = int(kwargs['select'])
input_name = f"input{selected_index}"
selected_label = input_name
node_id = kwargs['unique_id']
nodelist = kwargs['extra_pnginfo']['workflow']['nodes']
for node in nodelist:
if str(node['id']) == node_id:
inputs = node['inputs']
for slot in inputs:
if slot['name'] == input_name and 'label' in slot:
selected_label = slot['label']
if 'extra_pnginfo' in kwargs and kwargs['extra_pnginfo'] is not None:
nodelist = kwargs['extra_pnginfo']['workflow']['nodes']
for node in nodelist:
if str(node['id']) == node_id:
inputs = node['inputs']
break
for slot in inputs:
if slot['name'] == input_name and 'label' in slot:
selected_label = slot['label']
break
else:
print(f"[Impact-Pack] The switch node does not guarantee proper functioning in API mode.")
if input_name in kwargs:
return (kwargs[input_name], selected_label, selected_index)
return kwargs[input_name], selected_label, selected_index
else:
print(f"ImpactSwitch: invalid select index (ignored)")
return (None, "", selected_index)
return None, "", selected_index
class GeneralInversedSwitch:
class LatentSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
"input": (any_typ,),
"select": ("INT", {"default": 1, "min": 1, "max": 99999, "step": 1}),
"latent1": ("LATENT",),
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = tuple([any_typ] * 100)
RETURN_TYPES = ("LATENT", )
OUTPUT_NODE = True
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, select, input, unique_id):
res = []
def doit(self, *args, **kwargs):
input_name = f"latent{int(kwargs['select'])}"
for i in range(0, select):
if select == i+1:
res.append(input)
else:
res.append(None)
return res
if input_name in kwargs:
return (kwargs[input_name],)
else:
print(f"LatentSwitch: invalid select index ('latent1' is selected)")
return (kwargs['latent1'],)
class ImageMaskSwitch:
@@ -92,6 +132,9 @@ class ImageMaskSwitch:
}
RETURN_TYPES = ("IMAGE", "MASK",)
OUTPUT_NODE = True
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
@@ -108,6 +151,54 @@ class ImageMaskSwitch:
return images4_opt, mask4_opt,
class GeneralInversedSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1, "tooltip": "The output number you want to send from the input"}),
"input": (any_typ, {"tooltip": "Any input. When connected, one more input slot is added."}),
},
"optional": {
"sel_mode": ("BOOLEAN", {"default": False, "label_on": "select_on_prompt", "label_off": "select_on_execution", "forceInput": False,
"tooltip": "In the case of 'select_on_execution', the selection is dynamically determined at the time of workflow execution. 'select_on_prompt' is an option that exists for older versions of ComfyUI, and it makes the decision before the workflow execution."}),
},
"hidden": {"prompt": "PROMPT", "unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ByPassTypeTuple((any_typ, ))
OUTPUT_TOOLTIPS = ("Output occurs only from the output selected by the 'select' value.\nWhen slots are connected, additional slots are created.", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, select, prompt, unique_id, input, **kwargs):
if core.is_execution_model_version_supported():
from comfy_execution.graph import ExecutionBlocker
else:
print("[Impact Pack] InversedSwitch: ComfyUI is outdated. The 'select_on_execution' mode cannot function properly.")
res = []
# search max output count in prompt
cnt = 0
for x in prompt.values():
for y in x.get('inputs', {}).values():
if isinstance(y, list) and len(y) == 2:
if y[0] == unique_id:
cnt = max(cnt, y[1])
for i in range(0, cnt + 1):
if select == i+1:
res.append(input)
elif core.is_execution_model_version_supported():
res.append(ExecutionBlocker(None))
else:
res.append(None)
return res
class RemoveNoiseMask:
@classmethod
def INPUT_TYPES(s):
@@ -155,9 +246,10 @@ class ImpactLogger:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"data": (any_typ, ""),
"data": (any_typ,),
"text": ("STRING", {"multiline": True}),
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO", "unique_id": "UNIQUE_ID"},
}
CATEGORY = "ImpactPack/Debug"
@@ -167,7 +259,7 @@ class ImpactLogger:
RETURN_TYPES = ()
FUNCTION = "doit"
def doit(self, data, prompt, extra_pnginfo):
def doit(self, data, text, prompt, extra_pnginfo, unique_id):
shape = ""
if hasattr(data, "shape"):
shape = f"{data.shape} / "
@@ -178,12 +270,13 @@ class ImpactLogger:
# for x in prompt:
# if 'inputs' in x and 'populated_text' in x['inputs']:
# print(f"PROMP: {x['10']['inputs']['populated_text']}")
# print(f"PROMPT: {x['10']['inputs']['populated_text']}")
#
# for x in extra_pnginfo['workflow']['nodes']:
# if x['type'] == 'ImpactWildcardProcessor':
# print(f" WV : {x['widgets_values'][1]}\n")
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": unique_id, "widget_name": "text", "type": "TEXT", "value": f"{data}"})
return {}
@@ -199,3 +292,450 @@ class ImpactDummyInput:
def doit(self):
return ("DUMMY",)
class MasksToMaskList:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"masks": ("MASK", ),
}
}
RETURN_TYPES = ("MASK", )
OUTPUT_IS_LIST = (True, )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Operation"
def doit(self, masks):
if masks is None:
empty_mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
return ([empty_mask], )
res = []
for mask in masks:
res.append(mask)
print(f"mask len: {len(res)}")
res = [make_3d_mask(x) for x in res]
return (res, )
class MaskListToMaskBatch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"mask": ("MASK", ),
}
}
INPUT_IS_LIST = True
RETURN_TYPES = ("MASK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Operation"
def doit(self, mask):
if len(mask) == 1:
mask = make_3d_mask(mask[0])
return (mask,)
elif len(mask) > 1:
mask1 = make_3d_mask(mask[0])
for mask2 in mask[1:]:
mask2 = make_3d_mask(mask2)
if mask1.shape[1:] != mask2.shape[1:]:
mask2 = comfy.utils.common_upscale(mask2.movedim(-1, 1), mask1.shape[2], mask1.shape[1], "lanczos", "center").movedim(1, -1)
mask1 = torch.cat((mask1, mask2), dim=0)
return (mask1,)
else:
empty_mask = torch.zeros((1, 64, 64), dtype=torch.float32, device="cpu").unsqueeze(0)
return (empty_mask,)
class ImageListToImageBatch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"images": ("IMAGE", ),
}
}
INPUT_IS_LIST = True
RETURN_TYPES = ("IMAGE", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Operation"
def doit(self, images):
if len(images) <= 1:
return (images[0],)
else:
image1 = images[0]
for image2 in images[1:]:
if image1.shape[1:] != image2.shape[1:]:
image2 = comfy.utils.common_upscale(image2.movedim(-1, 1), image1.shape[2], image1.shape[1], "lanczos", "center").movedim(1, -1)
image1 = torch.cat((image1, image2), dim=0)
return (image1,)
class ImageBatchToImageList:
@classmethod
def INPUT_TYPES(s):
return {"required": {"image": ("IMAGE",), }}
RETURN_TYPES = ("IMAGE",)
OUTPUT_IS_LIST = (True,)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, image):
images = [image[i:i + 1, ...] for i in range(image.shape[0])]
return (images, )
class MakeAnyList:
@classmethod
def INPUT_TYPES(s):
return {
"required": {},
"optional": {"value1": (any_typ,), }
}
RETURN_TYPES = (any_typ,)
OUTPUT_IS_LIST = (True,)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
values = []
for k, v in kwargs.items():
if v is not None:
values.append(v)
return (values, )
class MakeMaskList:
@classmethod
def INPUT_TYPES(s):
return {"required": {"mask1": ("MASK",), }}
RETURN_TYPES = ("MASK",)
OUTPUT_IS_LIST = (True,)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
masks = []
for k, v in kwargs.items():
masks.append(v)
return (masks, )
class NthItemOfAnyList:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"any_list": (any_typ,),
"index": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1, "tooltip": "The index of the item you want to select from the list."}),
}
}
RETURN_TYPES = (any_typ,)
INPUT_IS_LIST = True
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
DESCRIPTION = "Selects the Nth item from a list. If the index is out of range, it returns the last item in the list."
def doit(self, any_list, index):
i = index[0]
if i >= len(any_list):
return (any_list[-1],)
else:
return (any_list[i],)
class MakeImageList:
@classmethod
def INPUT_TYPES(s):
return {"required": {"image1": ("IMAGE",), }}
RETURN_TYPES = ("IMAGE",)
OUTPUT_IS_LIST = (True,)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
images = []
for k, v in kwargs.items():
images.append(v)
return (images, )
class MakeImageBatch:
@classmethod
def INPUT_TYPES(s):
return {"required": {"image1": ("IMAGE",), }}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
image1 = kwargs['image1']
del kwargs['image1']
images = [value for value in kwargs.values()]
if len(images) == 0:
return (image1,)
else:
for image2 in images:
if image1.shape[1:] != image2.shape[1:]:
image2 = comfy.utils.common_upscale(image2.movedim(-1, 1), image1.shape[2], image1.shape[1], "lanczos", "center").movedim(1, -1)
image1 = torch.cat((image1, image2), dim=0)
return (image1,)
class MakeMaskBatch:
@classmethod
def INPUT_TYPES(s):
return {"required": {"mask1": ("MASK",), }}
RETURN_TYPES = ("MASK",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
mask1 = kwargs['mask1']
del kwargs['mask1']
masks = [make_3d_mask(value) for value in kwargs.values()]
if len(masks) == 0:
return (mask1,)
else:
for mask2 in masks:
if mask1.shape[1:] != mask2.shape[1:]:
mask2 = comfy.utils.common_upscale(mask2.movedim(-1, 1), mask1.shape[2], mask1.shape[1], "lanczos", "center").movedim(1, -1)
mask1 = torch.cat((mask1, mask2), dim=0)
return (mask1,)
class ReencodeLatent:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"samples": ("LATENT", ),
"tile_mode": (["None", "Both", "Decode(input) only", "Encode(output) only"],),
"input_vae": ("VAE", ),
"output_vae": ("VAE", ),
"tile_size": ("INT", {"default": 512, "min": 320, "max": 4096, "step": 64}),
},
"optional": {
"overlap": ("INT", {"default": 64, "min": 0, "max": 4096, "step": 32, "tooltip": "This setting applies when 'tile_mode' is enabled."}),
}
}
CATEGORY = "ImpactPack/Util"
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
def doit(self, samples, tile_mode, input_vae, output_vae, tile_size=512, overlap=64):
if tile_mode in ["Both", "Decode(input) only"]:
decoder = nodes.VAEDecodeTiled()
if 'overlap' in inspect.signature(decoder.decode).parameters:
pixels = decoder.decode(input_vae, samples, tile_size, overlap=overlap)[0]
else:
pixels = decoder.decode(input_vae, samples, tile_size, overlap=overlap)[0]
else:
pixels = nodes.VAEDecode().decode(input_vae, samples)[0]
if tile_mode in ["Both", "Encode(output) only"]:
encoder = nodes.VAEEncodeTiled()
if 'overlap' in inspect.signature(encoder.encode).parameters:
return encoder.encode(output_vae, pixels, tile_size, overlap=overlap)
else:
return encoder.encode(output_vae, pixels, tile_size)
else:
return nodes.VAEEncode().encode(output_vae, pixels)
class ReencodeLatentPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"samples": ("LATENT", ),
"tile_mode": (["None", "Both", "Decode(input) only", "Encode(output) only"],),
"input_basic_pipe": ("BASIC_PIPE", ),
"output_basic_pipe": ("BASIC_PIPE", ),
},
}
CATEGORY = "ImpactPack/Util"
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
def doit(self, samples, tile_mode, input_basic_pipe, output_basic_pipe):
_, _, input_vae, _, _ = input_basic_pipe
_, _, output_vae, _, _ = output_basic_pipe
return ReencodeLatent().doit(samples, tile_mode, input_vae, output_vae)
class StringSelector:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"strings": ("STRING", {"multiline": True}),
"multiline": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
"select": ("INT", {"min": 0, "max": sys.maxsize, "step": 1, "default": 0}),
}}
RETURN_TYPES = ("STRING",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, strings, multiline, select):
lines = strings.split('\n')
if multiline:
result = []
current_string = ""
for line in lines:
if line.startswith("#"):
if current_string:
result.append(current_string.strip())
current_string = ""
current_string += line + "\n"
if current_string:
result.append(current_string.strip())
if len(result) == 0:
selected = strings
else:
selected = result[select % len(result)]
if selected.startswith('#'):
selected = selected[1:]
else:
if len(lines) == 0:
selected = strings
else:
selected = lines[select % len(lines)]
return (selected, )
class StringListToString:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"join_with": ("STRING", {"default": "\\n"}),
"string_list": ("STRING", {"forceInput": True}),
}
}
INPUT_IS_LIST = True
RETURN_TYPES = ("STRING",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, join_with, string_list):
# convert \\n to newline character
if join_with[0] == "\\n":
join_with[0] = "\n"
joined_text = join_with[0].join(string_list)
return (joined_text,)
class WildcardPromptFromString:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"string": ("STRING", {"forceInput": True}),
"delimiter": ("STRING", {"multiline": False, "default": "\\n" }),
"prefix_all": ("STRING", {"multiline": False}),
"postfix_all": ("STRING", {"multiline": False}),
"restrict_to_tags": ("STRING", {"multiline": False}),
"exclude_tags": ("STRING", {"multiline": False})
},
}
RETURN_TYPES = ("STRING", "STRING",)
RETURN_NAMES = ("wildcard", "segs_labels",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, string, delimiter, prefix_all, postfix_all, restrict_to_tags, exclude_tags):
# convert \\n to newline character
if delimiter == "\\n":
delimiter = "\n"
# some sanity checks and normalization for later processing
if prefix_all is None:
prefix_all = ""
if postfix_all is None:
postfix_all = ""
if restrict_to_tags is None:
restrict_to_tags = ""
if exclude_tags is None:
exclude_tags = ""
restrict_to_tags = restrict_to_tags.split(", ")
exclude_tags = exclude_tags.split(", ")
# build the wildcard prompt per list entry
output = ["[LAB]"]
labels = []
for x in string.split(delimiter):
label = str(len(labels) + 1)
labels.append(label)
x = x.split(", ")
# restrict to tags
if restrict_to_tags != [""]:
x = list(set(x) & set(restrict_to_tags))
# remove tags
if exclude_tags != [""]:
x = list(set(x) - set(exclude_tags))
# next row: <LABEL> <PREFIX> <TAGS> <POSTFIX>
prompt_for_seg = f'[{label}] {prefix_all} {", ".join(x)} {postfix_all}'.strip()
output.append(prompt_for_seg)
output = "\n".join(output)
# clean string: fixup double spaces, commas etc.
output = re.sub(r' ,', ',', output)
output = re.sub(r' +', ' ', output)
output = re.sub(r',,+', ',', output)
output = re.sub(r'\n, ', '\n', output)
return output, ", ".join(labels)
+413 -36
View File
@@ -1,23 +1,249 @@
import torch
import torchvision
import cv2
import numpy as np
from PIL import Image, ImageDraw, ImageFilter
import folder_paths
import nodes
from . import config
from PIL import Image
import comfy
import time
class TensorBatchBuilder:
def __init__(self):
self.tensor = None
def concat(self, new_tensor):
if self.tensor is None:
self.tensor = new_tensor
else:
self.tensor = torch.concat((self.tensor, new_tensor), dim=0)
def tensor_convert_rgba(image, prefer_copy=True):
"""Assumes NHWC format tensor with 1, 3 or 4 channels."""
_tensor_check_image(image)
n_channel = image.shape[-1]
if n_channel == 4:
return image
if n_channel == 3:
alpha = torch.ones((*image.shape[:-1], 1))
return torch.cat((image, alpha), axis=-1)
if n_channel == 1:
if prefer_copy:
image = image.repeat(1, -1, -1, 4)
else:
image = image.expand(1, -1, -1, 3)
return image
# NOTE: Similar error message as in PIL, for easier googling :P
raise ValueError(f"illegal conversion (channels: {n_channel} -> 4)")
def tensor_convert_rgb(image, prefer_copy=True):
"""Assumes NHWC format tensor with 1, 3 or 4 channels."""
_tensor_check_image(image)
n_channel = image.shape[-1]
if n_channel == 3:
return image
if n_channel == 4:
image = image[..., :3]
if prefer_copy:
image = image.copy()
return image
if n_channel == 1:
if prefer_copy:
image = image.repeat(1, -1, -1, 4)
else:
image = image.expand(1, -1, -1, 3)
return image
# NOTE: Same error message as in PIL, for easier googling :P
raise ValueError(f"illegal conversion (channels: {n_channel} -> 3)")
def general_tensor_resize(image, w: int, h: int):
_tensor_check_image(image)
image = image.permute(0, 3, 1, 2)
image = torch.nn.functional.interpolate(image, size=(h, w), mode="bilinear")
image = image.permute(0, 2, 3, 1)
return image
# TODO: Sadly, we need LANCZOS
LANCZOS = (Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS)
def tensor_resize(image, w: int, h: int):
_tensor_check_image(image)
if image.shape[3] >= 3:
scaled_images = TensorBatchBuilder()
for single_image in image:
single_image = single_image.unsqueeze(0)
single_pil = tensor2pil(single_image)
scaled_pil = single_pil.resize((w, h), resample=LANCZOS)
single_image = pil2tensor(scaled_pil)
scaled_images.concat(single_image)
return scaled_images.tensor
else:
return general_tensor_resize(image, w, h)
def pil2numpy(image):
return (np.array(image).astype(np.float32) / 255.0)[np.newaxis, :, :, :]
def tensor_get_size(image):
"""Mimicking `PIL.Image.size`"""
_tensor_check_image(image)
_, h, w, _ = image.shape
return (w, h)
def tensor2pil(image):
_tensor_check_image(image)
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(0), 0, 255).astype(np.uint8))
def pil2tensor(image):
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)
def tensor2pil(image):
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))
def numpy2pil(image):
return Image.fromarray(np.clip(255. * image.squeeze(0), 0, 255).astype(np.uint8))
def to_pil(image):
if isinstance(image, Image.Image):
return image
if isinstance(image, torch.Tensor):
return tensor2pil(image)
if isinstance(image, np.ndarray):
return numpy2pil(image)
raise ValueError(f"Cannot convert {type(image)} to PIL.Image")
def to_tensor(image):
if isinstance(image, Image.Image):
return torch.from_numpy(np.array(image)) / 255.0
if isinstance(image, torch.Tensor):
return image
if isinstance(image, np.ndarray):
return torch.from_numpy(image)
raise ValueError(f"Cannot convert {type(image)} to torch.Tensor")
def to_numpy(image):
if isinstance(image, Image.Image):
return np.array(image)
if isinstance(image, torch.Tensor):
return image.numpy()
if isinstance(image, np.ndarray):
return image
raise ValueError(f"Cannot convert {type(image)} to numpy.ndarray")
def tensor_putalpha(image, mask):
_tensor_check_image(image)
_tensor_check_mask(mask)
image[..., -1] = mask[..., 0]
def _tensor_check_image(image):
if image.ndim != 4:
raise ValueError(f"Expected NHWC tensor, but found {image.ndim} dimensions")
if image.shape[-1] not in (1, 3, 4):
raise ValueError(f"Expected 1, 3 or 4 channels for image, but found {image.shape[-1]} channels")
return
def _tensor_check_mask(mask):
if mask.ndim != 4:
raise ValueError(f"Expected NHWC tensor, but found {mask.ndim} dimensions")
if mask.shape[-1] != 1:
raise ValueError(f"Expected 1 channel for mask, but found {mask.shape[-1]} channels")
return
def tensor_crop(image, crop_region):
_tensor_check_image(image)
return crop_ndarray4(image, crop_region)
def tensor2numpy(image):
_tensor_check_image(image)
return image.numpy()
def tensor_paste(image1, image2, left_top, mask):
"""
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)
x, y = left_top
_, 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, :]
# 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
def center_of_bbox(bbox):
@@ -80,8 +306,7 @@ def bitwise_and_masks(mask1, mask2):
def to_binary_mask(mask, threshold=0):
if len(mask.shape) == 3:
mask = mask.squeeze(0)
mask = make_3d_mask(mask)
mask = mask.clone().cpu()
mask[mask > threshold] = 1.
@@ -95,10 +320,9 @@ def use_gpu_opencv():
def dilate_mask(mask, dilation_factor, iter=1):
if dilation_factor == 0:
return mask
return make_2d_mask(mask)
if len(mask.shape) == 3:
mask = mask.squeeze(0)
mask = make_2d_mask(mask)
kernel = np.ones((abs(dilation_factor), abs(dilation_factor)), np.uint8)
@@ -146,15 +370,65 @@ def dilate_masks(segmasks, dilation_factor, iter=1):
return dilated_masks
import torch.nn.functional as F
def feather_mask(mask, thickness):
mask = mask.permute(0, 3, 1, 2)
def feather_mask(mask, thickness, base_alpha=255):
pil_mask = Image.fromarray(np.uint8(mask * base_alpha))
# Gaussian kernel for blurring
kernel_size = 2 * int(thickness) + 1
sigma = thickness / 3 # Adjust the sigma value as needed
blur_kernel = _gaussian_kernel(kernel_size, sigma).to(mask.device, mask.dtype)
# Create a feathered mask by applying a Gaussian blur to the mask
blurred_mask = pil_mask.filter(ImageFilter.GaussianBlur(thickness))
feathered_mask = Image.new("L", pil_mask.size, 0)
feathered_mask.paste(blurred_mask, (0, 0), blurred_mask)
return feathered_mask
# Apply blur to the mask
blurred_mask = F.conv2d(mask, blur_kernel.unsqueeze(0).unsqueeze(0), padding=thickness)
blurred_mask = blurred_mask.permute(0, 2, 3, 1)
return blurred_mask
def _gaussian_kernel(kernel_size, sigma):
# Generate a 1D Gaussian kernel
kernel = torch.exp(-(torch.arange(kernel_size) - kernel_size // 2)**2 / (2 * sigma**2))
return kernel / kernel.sum()
def tensor_gaussian_blur_mask(mask, kernel_size, sigma=10.0):
"""Return NHWC torch.Tenser from ndim == 2 or 4 `np.ndarray` or `torch.Tensor`"""
if isinstance(mask, np.ndarray):
mask = torch.from_numpy(mask)
if mask.ndim == 2:
mask = mask[None, ..., None]
elif mask.ndim == 3:
mask = mask[..., None]
_tensor_check_mask(mask)
if kernel_size <= 0:
return mask
kernel_size = kernel_size*2+1
shortest = min(mask.shape[1], mask.shape[2])
if shortest <= kernel_size:
kernel_size = int(shortest/2)
if kernel_size % 2 == 0:
kernel_size += 1
if kernel_size < 3:
return mask # skip feathering
prev_device = mask.device
device = comfy.model_management.get_torch_device()
mask.to(device)
# apply gaussian blur
mask = mask[:, None, ..., 0]
blurred_mask = torchvision.transforms.GaussianBlur(kernel_size=kernel_size, sigma=sigma)(mask)
blurred_mask = blurred_mask[:, 0, ..., None]
blurred_mask.to(prev_device)
return blurred_mask
def subtract_masks(mask1, mask2):
@@ -239,6 +513,20 @@ def crop_ndarray4(npimg, crop_region):
return cropped
crop_tensor4 = crop_ndarray4
def crop_ndarray3(npimg, crop_region):
x1 = crop_region[0]
y1 = crop_region[1]
x2 = crop_region[2]
y2 = crop_region[3]
cropped = npimg[:, y1:y2, x1:x2]
return cropped
def crop_ndarray2(npimg, crop_region):
x1 = crop_region[0]
y1 = crop_region[1]
@@ -251,34 +539,124 @@ def crop_ndarray2(npimg, crop_region):
def crop_image(image, crop_region):
return crop_ndarray4(np.array(image), crop_region)
return crop_tensor4(image, crop_region)
def to_latent_image(pixels, vae):
def to_latent_image(pixels, vae, vae_tiled_encode=False):
x = pixels.shape[1]
y = pixels.shape[2]
if pixels.shape[1] != x or pixels.shape[2] != y:
pixels = pixels[:, :x, :y, :]
t = vae.encode(pixels[:, :, :, :3])
return {"samples": t}
start = time.time()
if vae_tiled_encode:
encoded = nodes.VAEEncodeTiled().encode(vae, pixels, 512, overlap=64)[0] # using default settings
print(f"[Impact Pack] vae encoded (tiled) in {time.time() - start:.1f}s")
else:
encoded = nodes.VAEEncode().encode(vae, pixels)[0]
print(f"[Impact Pack] vae encoded in {time.time() - start:.1f}s")
def scale_tensor(w, h, image):
image = tensor2pil(image)
scaled_image = image.resize((w, h), resample=LANCZOS)
return pil2tensor(scaled_image)
def scale_tensor_and_to_pil(w, h, image):
image = tensor2pil(image)
return image.resize((w, h), resample=LANCZOS)
return encoded
def empty_pil_tensor(w=64, h=64):
image = Image.new("RGB", (w, h))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, w-1, h-1), fill=(0, 0, 0))
return pil2tensor(image)
return torch.zeros((1, h, w, 3), dtype=torch.float32)
def make_2d_mask(mask):
if len(mask.shape) == 4:
return mask.squeeze(0).squeeze(0)
elif len(mask.shape) == 3:
return mask.squeeze(0)
return mask
def make_3d_mask(mask):
if len(mask.shape) == 4:
return mask.squeeze(0)
elif len(mask.shape) == 2:
return mask.unsqueeze(0)
return mask
def make_4d_mask(mask):
if len(mask.shape) == 3:
return mask.unsqueeze(0)
elif len(mask.shape) == 2:
return mask.unsqueeze(0).unsqueeze(0)
return mask
def is_same_device(a, b):
a_device = torch.device(a) if isinstance(a, str) else a
b_device = torch.device(b) if isinstance(b, str) else b
return a_device.type == b_device.type and a_device.index == b_device.index
def collect_non_reroute_nodes(node_map, links, res, node_id):
if node_map[node_id]['type'] != 'Reroute' and node_map[node_id]['type'] != 'Reroute (rgthree)':
res.append(node_id)
else:
for link in node_map[node_id]['outputs'][0]['links']:
next_node_id = str(links[link][2])
collect_non_reroute_nodes(node_map, links, res, next_node_id)
from torchvision.transforms.functional import to_pil_image
def resize_mask(mask, size):
mask = make_4d_mask(mask)
resized_mask = torch.nn.functional.interpolate(mask, size=size, mode='bilinear', align_corners=False)
return resized_mask.squeeze(0)
def apply_mask_alpha_to_pil(decoded_pil, mask):
decoded_rgba = decoded_pil.convert('RGBA')
mask_pil = to_pil_image(mask)
decoded_rgba.putalpha(mask_pil)
return decoded_rgba
def flatten_mask(all_masks):
merged_mask = (all_masks[0] * 255).to(torch.uint8)
for mask in all_masks[1:]:
merged_mask |= (mask * 255).to(torch.uint8)
return merged_mask
def try_install_custom_node(custom_node_url, msg):
try:
import cm_global
cm_global.try_call(api='cm.try-install-custom-node',
sender="Impact Pack", custom_node_url=custom_node_url, msg=msg)
except Exception:
print(msg)
print(f"[Impact Pack] ComfyUI-Manager is outdated. The custom node installation feature is not available.")
# author: Trung0246 --->
class TautologyStr(str):
def __ne__(self, other):
return False
class ByPassTypeTuple(tuple):
def __getitem__(self, index):
if index > 0:
index = 0
item = super().__getitem__(index)
if isinstance(item, str):
return TautologyStr(item)
return item
class NonListIterable:
@@ -289,7 +667,6 @@ class NonListIterable:
return self.data[index]
# author: Trung0246
def add_folder_path_and_extensions(folder_name, full_folder_paths, extensions):
# Iterate over the list of full folder paths
for full_folder_path in full_folder_paths:
@@ -309,7 +686,7 @@ def add_folder_path_and_extensions(folder_name, full_folder_paths, extensions):
# Now we just need to update the set of extensions as it would be an empty set
# Also ensure that all paths are included (since add_model_folder_path adds only one path at a time)
folder_paths.folder_names_and_paths[folder_name] = (full_folder_paths, extensions)
# <---
# wildcard trick is taken from pythongossss's
class AnyType(str):
+275 -69
View File
@@ -4,16 +4,32 @@ import os
import nodes
import folder_paths
import yaml
import numpy as np
import threading
from impact import utils
from impact import config
wildcards_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "wildcards"))
RE_WildCardQuantifier = re.compile(r"(?P<quantifier>\d+)#__(?P<keyword>[\w.\-+/*\\]+?)__", re.IGNORECASE)
wildcard_lock = threading.Lock()
wildcard_dict = {}
def get_wildcard_list():
return [f"__{x}__" for x in wildcard_dict.keys()]
with wildcard_lock:
return [f"__{x}__" for x in wildcard_dict.keys()]
def get_wildcard_dict():
global wildcard_dict
with wildcard_lock:
return wildcard_dict
def wildcard_normalize(x):
return x.replace("\\", "/").lower()
return x.replace("\\", "/").replace(' ', '-').lower()
def read_wildcard(k, v):
@@ -25,7 +41,12 @@ def read_wildcard(k, v):
new_key = f"{k}/{k2}"
new_key = wildcard_normalize(new_key)
read_wildcard(new_key, v2)
elif isinstance(v, str):
k = wildcard_normalize(k)
wildcard_dict[k] = [v]
elif isinstance(v, (int, float)):
k = wildcard_normalize(k)
wildcard_dict[k] = [str(v)]
def read_wildcard_dict(wildcard_path):
global wildcard_dict
@@ -34,30 +55,61 @@ def read_wildcard_dict(wildcard_path):
if file.endswith('.txt'):
file_path = os.path.join(root, file)
rel_path = os.path.relpath(file_path, wildcard_path)
key = os.path.splitext(rel_path)[0].replace('\\', '/').lower()
key = wildcard_normalize(os.path.splitext(rel_path)[0])
try:
with open(file_path, 'r', encoding="ISO-8859-1") as f:
lines = f.read().splitlines()
wildcard_dict[key] = lines
except UnicodeDecodeError:
wildcard_dict[key] = [x for x in lines if not x.strip().startswith('#')]
except yaml.reader.ReaderError:
with open(file_path, 'r', encoding="UTF-8", errors="ignore") as f:
lines = f.read().splitlines()
wildcard_dict[key] = lines
elif file.endswith('.yaml'):
wildcard_dict[key] = [x for x in lines if not x.strip().startswith('#')]
elif file.endswith('.yaml') or file.endswith('.yml'):
file_path = os.path.join(root, file)
with open(file_path, 'r') as f:
yaml_data = yaml.load(f, Loader=yaml.FullLoader)
for k, v in yaml_data.items():
read_wildcard(k, v)
try:
with open(file_path, 'r', encoding="ISO-8859-1") as f:
yaml_data = yaml.load(f, Loader=yaml.FullLoader)
except yaml.reader.ReaderError as e:
with open(file_path, 'r', encoding="UTF-8", errors="ignore") as f:
yaml_data = yaml.load(f, Loader=yaml.FullLoader)
for k, v in yaml_data.items():
read_wildcard(k, v)
return wildcard_dict
def process_comment_out(text):
lines = text.split('\n')
lines0 = []
flag = False
for line in lines:
if line.lstrip().startswith('#'):
flag = True
continue
if len(lines0) == 0:
lines0.append(line)
elif flag:
lines0[-1] += ' ' + line
flag = False
else:
lines0.append(line)
return '\n'.join(lines0)
def process(text, seed=None):
text = process_comment_out(text)
if seed is not None:
random.seed(seed)
random_gen = np.random.default_rng(seed)
local_wildcard_dict = get_wildcard_dict()
def replace_options(string):
replacements_found = False
@@ -71,6 +123,7 @@ def process(text, seed=None):
select_sep = ' '
range_pattern = r'(\d+)(-(\d+))?'
range_pattern2 = r'-(\d+)'
wildcard_pattern = r"__([\w.\-+/*\\]+?)__"
if len(multi_select_pattern) > 1:
r = re.match(range_pattern, options[0])
@@ -81,10 +134,11 @@ def process(text, seed=None):
b = r.group(1).strip()
else:
a = r.group(1).strip()
try:
b = r.group(3).strip()
except:
b = None
b = r.group(3)
if b is not None:
b = b.strip()
else:
b = "-1"
if r is not None:
if b is not None and is_numeric_string(a) and is_numeric_string(b):
@@ -95,20 +149,32 @@ def process(text, seed=None):
x = int(a)
select_range = (x, x)
# Expand wildcard path or return the string after $$
def expand_wildcard_or_return_string(options, pattern, wildcard_pattern):
matches = re.findall(wildcard_pattern, pattern)
if len(options) == 1 and matches:
# $$<single wildcard>
return get_wildcard_options(pattern)
else:
# $$opt1|opt2|...
options[0] = pattern
return options
if select_range is not None and len(multi_select_pattern) == 2:
# PATTERN: count$$
options[0] = multi_select_pattern[1]
options = expand_wildcard_or_return_string(options, multi_select_pattern[1], wildcard_pattern )
elif select_range is not None and len(multi_select_pattern) == 3:
# PATTERN: count$$ sep $$
select_sep = multi_select_pattern[1]
options[0] = multi_select_pattern[2]
options = expand_wildcard_or_return_string(options, multi_select_pattern[2], wildcard_pattern )
adjusted_probabilities = []
total_prob = 0
for option in options:
parts = option.split('::', 1)
parts = option.split('::', 1) if isinstance(option, str) else f"{option}".split('::', 1)
if len(parts) == 2 and is_numeric_string(parts[0].strip()):
config_value = float(parts[0].strip())
else:
@@ -122,22 +188,30 @@ def process(text, seed=None):
if select_range is None:
select_count = 1
else:
select_count = random.randint(select_range[0], select_range[1])
def calculate_max(_options_length, _max_select_range):
return min(_max_select_range + 1, _options_length + 1) if _max_select_range > 0 else _options_length + 1
if select_count > len(options):
def calculate_select_count(_max_value, _min_select_range, random_gen):
if max(_max_value, _min_select_range) <= 0:
return 0
# fix: low >= high
elif _max_value == _min_select_range:
return _max_value
else:
# fix: low >= high
_low_value = min(_min_select_range, _max_value)
_high_value = max(_min_select_range, _max_value)
return random_gen.integers(low=_low_value, high=_high_value, size=1)
select_count = calculate_select_count(calculate_max(len(options), select_range[1]), select_range[0], random_gen)
if select_count > len(options) or total_prob <= 1:
random_gen.shuffle(options)
selected_items = options
else:
selected_items = random.choices(options, weights=normalized_probabilities, k=select_count)
selected_items = set(selected_items)
selected_items = random_gen.choice(options, p=normalized_probabilities, size=select_count, replace=False)
try_count = 0
while len(selected_items) < select_count and try_count < 10:
remaining_count = select_count - len(selected_items)
additional_items = random.choices(options, weights=normalized_probabilities, k=remaining_count)
selected_items |= set(additional_items)
try_count += 1
selected_items2 = [re.sub(r'^\s*[0-9.]+::', '', x, 1) for x in selected_items]
# x may be numpy.int32, convert to string
selected_items2 = [re.sub(r'^\s*[0-9.]+::', '', str(x), 1) for x in selected_items]
replacement = select_sep.join(selected_items2)
if '::' in replacement:
pass
@@ -150,9 +224,36 @@ def process(text, seed=None):
return replaced_string, replacements_found
def get_wildcard_options(string):
pattern = r"__([\w.\-+/*\\]+?)__"
matches = re.findall(pattern, string)
options = []
for match in matches:
keyword = match.lower()
keyword = wildcard_normalize(keyword)
if keyword in local_wildcard_dict:
options.extend(local_wildcard_dict[keyword])
elif '*' in keyword:
subpattern = keyword.replace('*', '.*').replace('+', '\\+')
total_patterns = []
found = False
for k, v in local_wildcard_dict.items():
if re.match(subpattern, k) is not None or re.match(subpattern, k+'/') is not None:
total_patterns += v
found = True
if found:
options.extend(total_patterns)
elif '/' not in keyword:
string_fallback = string.replace(f"__{match}__", f"__*/{match}__", 1)
options.extend(get_wildcard_options(string_fallback))
return options
def replace_wildcard(string):
global wildcard_dict
pattern = r"__([\w.\-+/*\\]+)__"
pattern = r"__([\w.\-+/*\\]+?)__"
matches = re.findall(pattern, string)
replacements_found = False
@@ -160,21 +261,37 @@ def process(text, seed=None):
for match in matches:
keyword = match.lower()
keyword = wildcard_normalize(keyword)
if keyword in wildcard_dict:
replacement = random.choice(wildcard_dict[keyword])
if keyword in local_wildcard_dict:
# look for adjusted probability
adjusted_probabilities = []
total_prob = 0
options=local_wildcard_dict[keyword]
for option in options:
parts = option.split('::', 1)
if len(parts) == 2 and is_numeric_string(parts[0].strip()):
config_value = float(parts[0].strip())
else:
config_value = 1 # Default value if no configuration is provided
adjusted_probabilities.append(config_value)
total_prob += config_value
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)
replacements_found = True
string = string.replace(f"__{match}__", replacement, 1)
elif '*' in keyword:
subpattern = keyword.replace('*', '.*').replace('+','\+')
subpattern = keyword.replace('*', '.*').replace('+', '\\+')
total_patterns = []
found = False
for k, v in wildcard_dict.items():
if re.match(subpattern, k) is not None:
for k, v in local_wildcard_dict.items():
if re.match(subpattern, k) is not None or re.match(subpattern, k+'/') is not None:
total_patterns += v
found = True
if found:
replacement = random.choice(total_patterns)
replacement = random_gen.choice(total_patterns)
replacements_found = True
string = string.replace(f"__{match}__", replacement, 1)
elif '/' not in keyword:
@@ -187,6 +304,15 @@ def process(text, seed=None):
stop_unwrap = False
while not stop_unwrap and replace_depth > 1:
replace_depth -= 1 # prevent infinite loop
option_quantifier = [e.groupdict() for e in RE_WildCardQuantifier.finditer(text)]
for match in option_quantifier:
keyword = match['keyword'].lower()
quantifier = int(match['quantifier']) if match['quantifier'] else 1
replacement = '__|__'.join([keyword,] * quantifier)
wilder_keyword = keyword.replace('*', '\\*')
RE_TEMP = re.compile(fr"(?P<quantifier>\d+)#__(?P<keyword>{wilder_keyword})__", re.IGNORECASE)
text = RE_TEMP.sub(f"__{replacement}__", text)
# pass1: replace options
pass1, is_replaced1 = replace_options(text)
@@ -202,7 +328,7 @@ def process(text, seed=None):
def is_numeric_string(input_str):
return re.match(r'^-?\d+(\.\d+)?$', input_str) is not None
return re.match(r'^-?(\d*\.?\d+|\d+\.?\d*)$', input_str) is not None
def safe_float(x):
@@ -254,7 +380,7 @@ def extract_lora_values(string):
if a is None:
a = 1.0
if b is None:
b = 1.0
b = a
if lora is not None and lora not in added:
result.append((lora, a, b, lbw, lbw_a, lbw_b))
@@ -282,20 +408,37 @@ def resolve_lora_name(lora_name_cache, name):
return x
def process_with_loras(wildcard_opt, model, clip, clip_encoder=None):
def process_with_loras(wildcard_opt, model, clip, clip_encoder=None, seed=None, processed=None):
"""
process wildcard text including loras
:param wildcard_opt: wildcard text
:param model: model
:param clip: clip
:param clip_encoder: you can pass custom encoder such as adv_cliptext_encode
:param seed: seed for populating
:param processed: output variable - [pass1, pass2, pass3] will be saved into passed list
:return: model, clip, conditioning
"""
lora_name_cache = []
pass1 = process(wildcard_opt)
pass1 = process(wildcard_opt, seed)
loras = extract_lora_values(pass1)
pass2 = remove_lora_tags(pass1)
for lora_name, model_weight, clip_weight, lbw, lbw_a, lbw_b in loras:
if (lora_name.split('.')[-1]) not in folder_paths.supported_pt_extensions:
lora_name_ext = lora_name.split('.')
if ('.'+lora_name_ext[-1]) not in folder_paths.supported_pt_extensions:
lora_name = lora_name+".safetensors"
orig_lora_name = lora_name
lora_name = resolve_lora_name(lora_name_cache, lora_name)
path = folder_paths.get_full_path("loras", lora_name)
if lora_name is not None:
path = folder_paths.get_full_path("loras", lora_name)
else:
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}")
@@ -305,6 +448,10 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None):
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()
else:
@@ -313,19 +460,41 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None):
else:
model, clip = default_lora()
else:
print(f"LORA NOT FOUND: {lora_name}")
print(f"LORA NOT FOUND: {orig_lora_name}")
print(f"CLIP: {pass2}")
pass3 = [x.strip() for x in pass2.split("BREAK")]
pass3 = [x for x in pass3 if x != '']
if clip_encoder is None:
return model, clip, nodes.CLIPTextEncode().encode(clip, pass2)[0]
else:
return model, clip, clip_encoder.encode(clip, pass2)[0]
if len(pass3) == 0:
pass3 = ['']
pass3_str = [f'[{x}]' for x in pass3]
print(f"CLIP: {str.join(' + ', pass3_str)}")
result = None
for prompt in pass3:
if clip_encoder is None:
cur = nodes.CLIPTextEncode().encode(clip, prompt)[0]
else:
cur = clip_encoder.encode(clip, prompt)[0]
if result is not None:
result = nodes.ConditioningConcat().concat(result, cur)[0]
else:
result = cur
if processed is not None:
processed.append(pass1)
processed.append(pass2)
processed.append(pass3)
return model, clip, result
def starts_with_regex(pattern, text):
regex = re.compile(pattern)
return bool(regex.match(text))
return regex.match(text)
def split_to_dict(text):
@@ -370,6 +539,31 @@ class WildcardChooserDict:
return text
def split_string_with_sep(input_string):
sep_pattern = r'\[SEP(?:\:\w+)?\]'
substrings = re.split(sep_pattern, input_string)
result_list = [None]
matches = re.findall(sep_pattern, input_string)
for i, substring in enumerate(substrings):
result_list.append(substring)
if i < len(matches):
if matches[i] == '[SEP]':
result_list.append(None)
elif matches[i] == '[SEP:R]':
result_list.append(random.randint(0, 1125899906842624))
else:
try:
seed = int(matches[i][5:-1])
except:
seed = None
result_list.append(seed)
iterable = iter(result_list)
return list(zip(iterable, iterable))
def process_wildcard_for_segs(wildcard):
if wildcard.startswith('[LAB]'):
raw_items = split_to_dict(wildcard)
@@ -382,21 +576,33 @@ def process_wildcard_for_segs(wildcard):
return 'LAB', WildcardChooserDict(items)
elif starts_with_regex(r"\[(ASC|DSC|RND)\]", wildcard):
mode = wildcard[1:4]
raw_items = wildcard[5:].split('[SEP]')
items = []
for x in raw_items:
x = x.strip()
if x != '':
items.append(x)
if mode == 'RND':
random.shuffle(items)
return mode, WildcardChooser(items, True)
else:
return mode, WildcardChooser(items, False)
else:
return None, WildcardChooser([wildcard], False)
match = starts_with_regex(r"\[(ASC-SIZE|DSC-SIZE|ASC|DSC|RND)\]", wildcard)
if match:
mode = match[1]
items = split_string_with_sep(wildcard[len(match[0]):])
if mode == 'RND':
random.shuffle(items)
return mode, WildcardChooser(items, True)
else:
return mode, WildcardChooser(items, False)
else:
return None, WildcardChooser([(None, wildcard)], False)
def wildcard_load():
global wildcard_dict
wildcard_dict = {}
with wildcard_lock:
read_wildcard_dict(wildcards_path)
try:
read_wildcard_dict(config.get_config()['custom_wildcards'])
except Exception as e:
print(f"[Impact Pack] Failed to load custom wildcards directory.")
print(f"[Impact Pack] Wildcards loading done.")
+86
View File
@@ -0,0 +1,86 @@
# Due to the current lack of maintenance for the `ComfyUI_Noise` extension,
# I have copied the code from the applied PR.
# https://github.com/BlenderNeko/ComfyUI_Noise/pull/13/files
import comfy
import torch
from comfy import sampler_helpers
class Unsampler:
@classmethod
def INPUT_TYPES(s):
return {"required":
{"model": ("MODEL",),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"end_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
"cfg": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
"normalize": (["disable", "enable"],),
"positive": ("CONDITIONING",),
"negative": ("CONDITIONING",),
"latent_image": ("LATENT",),
}}
RETURN_TYPES = ("LATENT",)
FUNCTION = "unsampler"
CATEGORY = "sampling"
def unsampler(self, model, cfg, sampler_name, steps, end_at_step, scheduler, normalize, positive, negative,
latent_image):
normalize = normalize == "enable"
device = comfy.model_management.get_torch_device()
latent = latent_image
latent_image = latent["samples"]
end_at_step = min(end_at_step, steps - 1)
end_at_step = steps - end_at_step
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
noise_mask = None
if "noise_mask" in latent:
noise_mask = comfy.sampler_helpers.prepare_mask(latent["noise_mask"], noise.shape, device)
noise = noise.to(device)
latent_image = latent_image.to(device)
conds0 = \
{"positive": comfy.sampler_helpers.convert_cond(positive),
"negative": comfy.sampler_helpers.convert_cond(negative)}
conds = {}
for k in conds0:
conds[k] = list(map(lambda a: a.copy(), conds0[k]))
models, inference_memory = comfy.sampler_helpers.get_additional_models(conds, model.model_dtype())
comfy.model_management.load_models_gpu([model] + models, model.memory_required(noise.shape) + inference_memory)
sampler = comfy.samplers.KSampler(model, steps=steps, device=device, sampler=sampler_name,
scheduler=scheduler, denoise=1.0, model_options=model.model_options)
sigmas = sampler.sigmas.flip(0) + 0.0001
pbar = comfy.utils.ProgressBar(steps)
def callback(step, x0, x, total_steps):
pbar.update_absolute(step + 1, total_steps)
samples = sampler.sample(noise, positive, negative, cfg=cfg, latent_image=latent_image,
force_full_denoise=False, denoise_mask=noise_mask, sigmas=sigmas, start_step=0,
last_step=end_at_step, callback=callback)
if normalize:
# technically doesn't normalize because unsampling is not guaranteed to end at a std given by the schedule
samples -= samples.mean()
samples /= samples.std()
samples = samples.cpu()
comfy.sampler_helpers.cleanup_additional_models(models)
out = latent.copy()
out["samples"] = samples
return (out,)
+15
View File
@@ -0,0 +1,15 @@
[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.14.1"
license = { file = "LICENSE.txt" }
dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"]
[project.urls]
Repository = "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
# Used by Comfy Registry https://comfyregistry.org
[tool.comfy]
PublisherId = "drltdata"
DisplayName = "ComfyUI Impact Pack"
Icon = ""
+4
View File
@@ -3,3 +3,7 @@ scikit-image
piexif
transformers
opencv-python-headless
scipy>=1.11.4
numpy<2
dill
matplotlib
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long