Compare commits

...
88 Commits
Author SHA1 Message Date
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
28 changed files with 2121 additions and 947 deletions
+48 -74
View File
@@ -2,11 +2,16 @@
# 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
* 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.)
@@ -30,9 +35,6 @@ This custom node helps to conveniently enhance images through Detector, Detailer
## Custom Nodes
### [Detector nodes](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.
* You need to install the ComfyUI-CLIPSeg node extension.
@@ -46,7 +48,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer
### 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 an `control_image` is given, `segs_preprocessor` will be ignored.
* `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
@@ -66,6 +68,8 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* `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 nodes](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/detailers.md)
* `Detailer (SEGS)` - Refines the image based on SEGS.
@@ -87,6 +91,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* `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.
* `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.
@@ -104,6 +109,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* `SEGS Filter (range)` - This node retrieves only SEGs from SEGS that have a size and position within a certain range.
* `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.
@@ -189,15 +195,11 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* 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.
* `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](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}`.
@@ -220,6 +222,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* `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.
### Impact KSampler
* These samplers support basic_pipe and AYS scheduler
* `KSampler (pipe)` - pipe version of KSampler
@@ -229,16 +232,19 @@ This custom node helps to conveniently enhance images through Detector, Detailer
### Batch/List Util
* `Image batch To Image List` - Convert Image batch to Image List
* `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.
### Logics (experimental)
* These nodes are experimental nodes designed to implement the logic for loops and dynamic switching.
* `ImpactCompare`, `ImpactConditionalBranch`, `ImpactConditionalBranchSelMode`, `ImpactInt`, `ImpactValueSender`, `ImpactValueReceiver`, `ImpactImageInfo`, `ImpactMinMax`, `ImpactNeg`, `ImpactConditionalStopIteration`
* `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.
@@ -269,6 +275,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* 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.
### 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
@@ -278,11 +285,10 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* `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.
## MMDet nodes (DEPRECATED) - Don't use these 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.
* `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
@@ -290,72 +296,41 @@ This custom node helps to conveniently enhance images through Detector, Detailer
* 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?
### Install via ComfyUI-Manager (Recommended)
* Search `ComfyUI Impact Pack` in ComfyUI-Manager and click `Install` button.
## 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.
* civitai/[adetailer](https://civitai.com/search/models?sortBy=models_v5&query=adetailer) - You can download various types detection models....Many models are associated with NSFW content.
## How to activate 'MMDet usage' (DEPRECATED)
* 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
### Manual Install (Not Recommended)
1. `cd custom_nodes`
2. `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 clone https://github.com/ltdrdata/ComfyUI-Impact-Subpack impact_subpack`
* 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.
6. Restart ComfyUI
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.
## 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 (deprecated)
* mmcv==2.0.0, mmdet==3.0.0, mmengine==0.7.2
* linux packages (ubuntu)
* libgl1-mesa-glx
* libglib2.0-0
@@ -378,17 +353,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)
+35 -44
View File
@@ -13,7 +13,6 @@ 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")
sys.path.append(modules_path)
@@ -22,30 +21,9 @@ 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
@@ -63,10 +41,10 @@ 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
@@ -116,6 +94,7 @@ NODE_CLASS_MAPPINGS = {
"FromDetailerPipe": FromDetailerPipe,
"FromDetailerPipe_v2": FromDetailerPipe_v2,
"FromDetailerPipeSDXL": FromDetailerPipe_SDXL,
"AnyPipeToBasic": AnyPipeToBasic,
"ToBasicPipe": ToBasicPipe,
"FromBasicPipe": FromBasicPipe,
"FromBasicPipe_v2": FromBasicPipe_v2,
@@ -158,9 +137,12 @@ NODE_CLASS_MAPPINGS = {
"BitwiseAndMask": BitwiseAndMask,
"SubtractMask": SubtractMask,
"AddMask": AddMask,
"MaskRectArea": MaskRectArea,
"MaskRectAreaAdvanced": MaskRectAreaAdvanced,
"ImpactSegsAndMask": SegsBitwiseAndMask,
"ImpactSegsAndMaskForEach": SegsBitwiseAndMaskForEach,
"EmptySegs": EmptySEGS,
"ImpactFlattenMask": FlattenMask,
"MediaPipeFaceMeshToSEGS": MediaPipeFaceMeshToSEGS,
"MaskToSEGS": MaskToSEGS,
@@ -208,6 +190,8 @@ NODE_CLASS_MAPPINGS = {
"KSamplerAdvancedProvider": KSamplerAdvancedProvider,
"TwoAdvancedSamplersForMask": TwoAdvancedSamplersForMask,
"ImpactNegativeConditioningPlaceholder": NegativeConditioningPlaceholder,
"PreviewBridge": PreviewBridge,
"PreviewBridgeLatent": PreviewBridgeLatent,
"ImageSender": ImageSender,
@@ -235,6 +219,7 @@ NODE_CLASS_MAPPINGS = {
"ImpactSEGSConcat": SEGSConcat,
"ImpactSEGSPicker": SEGSPicker,
"ImpactMakeTileSEGS": MakeTileSEGS,
"ImpactSEGSMerge": SEGSMerge,
"SEGSDetailerForAnimateDiff": SEGSDetailerForAnimateDiff,
@@ -247,6 +232,9 @@ NODE_CLASS_MAPPINGS = {
"ImpactImageBatchToImageList": ImageBatchToImageList,
"ImpactMakeImageList": MakeImageList,
"ImpactMakeImageBatch": MakeImageBatch,
"ImpactMakeAnyList": MakeAnyList,
"ImpactMakeMaskList": MakeMaskList,
"ImpactMakeMaskBatch": MakeMaskBatch,
"RegionalSampler": RegionalSampler,
"RegionalSamplerAdvanced": RegionalSamplerAdvanced,
@@ -269,6 +257,7 @@ NODE_CLASS_MAPPINGS = {
"ImpactLogicalOperators": ImpactLogicalOperators,
"ImpactInt": ImpactInt,
"ImpactFloat": ImpactFloat,
"ImpactBoolean": ImpactBoolean,
"ImpactValueSender": ImpactValueSender,
"ImpactValueReceiver": ImpactValueReceiver,
"ImpactImageInfo": ImpactImageInfo,
@@ -279,6 +268,8 @@ NODE_CLASS_MAPPINGS = {
"ImpactStringSelector": StringSelector,
"StringListToString": StringListToString,
"WildcardPromptFromString": WildcardPromptFromString,
"ImpactExecutionOrderController": ImpactExecutionOrderController,
"ImpactListBridge": ImpactListBridge,
"RemoveNoiseMask": RemoveNoiseMask,
@@ -312,8 +303,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"ImpactSimpleDetectorSEGS_for_AD": "Simple Detector for AnimateDiff (SEGS)",
"ImpactSimpleDetectorSEGS": "Simple Detector (SEGS)",
"ImpactSimpleDetectorSEGSPipe": "Simple Detector (SEGS/pipe)",
"ImpactControlNetApplySEGS": "ControlNetApply (SEGS)",
"ImpactControlNetApplyAdvancedSEGS": "ControlNetApplyAdvanced (SEGS)",
"ImpactControlNetApplySEGS": "ControlNetApply (SEGS) - DEPRECATED",
"ImpactControlNetApplyAdvancedSEGS": "ControlNetApply (SEGS)",
"ImpactIPAdapterApplySEGS": "IPAdapterApply (SEGS)",
"BboxDetectorCombined_v2": "BBOX Detector (combined)",
@@ -329,6 +320,9 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"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)",
@@ -351,6 +345,7 @@ 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/on Pixel Space)",
@@ -373,6 +368,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"ImpactSEGSToMaskBatch": "SEGS to Mask Batch",
"ImpactSEGSPicker": "Picker (SEGS)",
"ImpactMakeTileSEGS": "Make Tile SEGS",
"ImpactSEGSMerge": "SEGS Merge",
"ImpactDecomposeSEGS": "Decompose (SEGS)",
"ImpactAssembleSEGS": "Assemble (SEGS)",
@@ -395,13 +391,20 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"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)",
"ImpactStringSelector": "String Selector",
"StringListToString": "String List to String",
"WildcardPromptFromString": "Wildcard Prompt from String",
@@ -433,6 +436,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"ImpactSchedulerAdapter": "Impact Scheduler Adapter",
"GITSSchedulerFuncProvider": "GITSScheduler Func Provider",
"ImpactNegativeConditioningPlaceholder": "Negative Cond Placeholder"
}
if not impact.config.get_config()['mmdet_skip']:
@@ -459,19 +463,6 @@ 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
+26 -199
View File
@@ -5,7 +5,6 @@ import subprocess
import threading
import locale
import traceback
import re
if sys.argv[0] == 'install.py':
@@ -13,14 +12,11 @@ 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.environ.get('COMFYUI_PATH')
if comfy_path is None:
print(f"\n[bold yellow]WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `{os.path.dirname(__file__)}/../../` as the ComfyUI path.[/bold yellow]", file=sys.stderr)
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')
@@ -33,7 +29,7 @@ if model_path is None:
if model_path is None:
model_path = os.path.abspath(os.path.join(comfy_path, 'models'))
print(f"\n[bold yellow]WARN: The `COMFYUI_MODEL_PATH` environment variable is not set. Assuming `{model_path}` as the ComfyUI path.[/bold yellow]", file=sys.stderr)
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)
@@ -71,219 +67,40 @@ def process_wrap(cmd_str, cwd=None, handler=None, env=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']
pip_upgrade = [sys.executable, '-s', '-m', 'pip', 'install', '-U']
mim_install = [sys.executable, '-s', '-m', 'mim', 'install']
else:
pip_install = [sys.executable, '-m', 'pip', 'install']
pip_upgrade = [sys.executable, '-m', 'pip', 'install', '-U']
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 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:
from cv2 import setNumThreads
except Exception:
try:
is_open_cv_installed = False
# upgrade if opencv is installed already
if is_installed('opencv-python'):
process_wrap(pip_upgrade + ['opencv-python'])
is_open_cv_installed = True
if is_installed('opencv-python-headless'):
process_wrap(pip_upgrade + ['opencv-python-headless'])
is_open_cv_installed = True
if is_installed('opencv-contrib-python'):
process_wrap(pip_upgrade + ['opencv-contrib-python'])
is_open_cv_installed = True
if is_installed('opencv-contrib-python-headless'):
process_wrap(pip_upgrade + ['opencv-contrib-python-headless'])
is_open_cv_installed = True
# if opencv is not installed install `opencv-python-headless`
if not is_open_cv_installed:
process_wrap(pip_install + ['opencv-python-headless'])
except:
print(f"[ERROR] ComfyUI-Impact-Pack: failed to install 'opencv-python'. Please, install manually.")
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():
subpack_install_script = os.path.join(subpack_path, "install.py")
print(f"### ComfyUI-Impact-Pack: Updating subpack")
try:
import git
except Exception:
if not is_installed('GitPython'):
process_wrap(pip_install + ['GitPython'])
ensure_subpack() # The installation of the subpack must take place before ensure_pip. cv2 triggers a permission error.
new_env = os.environ.copy()
new_env["COMFYUI_PATH"] = comfy_path
new_env["COMFYUI_MODEL_PATH"] = model_path
if os.path.exists(subpack_install_script):
process_wrap([sys.executable, 'install.py'], cwd=subpack_path, env=new_env)
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()
# Download model
print("### ComfyUI-Impact-Pack: Check basic models")
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})")
@@ -291,6 +108,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()
+55 -43
View File
@@ -237,7 +237,7 @@ app.registerExtension({
if(nodeData.name == "ImpactControlBridge") {
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
if(!link_info || this.inputs[0].type != '*')
if(index != 0 || !link_info || this.inputs[0].type != '*')
return;
// assign type
@@ -353,7 +353,7 @@ app.registerExtension({
}
this.outputs[0].type = origin_type;
this.outputs[0].name = origin_type;
this.outputs[0].name = 'output1';
}
return;
@@ -383,7 +383,7 @@ app.registerExtension({
}
let select_slot = this.inputs.find(x => x.name == "select");
if(this.widgets) {
if(this.widgets?.length) {
this.widgets[0].options.max = select_slot?this.outputs.length-1:this.outputs.length;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
if(this.widgets[0].options.max > 0 && this.widgets[0].value == 0)
@@ -393,7 +393,8 @@ app.registerExtension({
}
if (nodeData.name === 'ImpactMakeImageList' || nodeData.name === 'ImpactMakeImageBatch' ||
nodeData.name === 'CombineRegionalPrompts' ||
nodeData.name === 'ImpactMakeMaskList' || nodeData.name === 'ImpactMakeMaskBatch' ||
nodeData.name === 'ImpactMakeAnyList' || nodeData.name === 'CombineRegionalPrompts' ||
nodeData.name === 'ImpactCombineConditionings' || nodeData.name === 'ImpactConcatConditionings' ||
nodeData.name === 'ImpactSEGSConcat' ||
nodeData.name === 'ImpactSwitch' || nodeData.name === 'LatentSwitch' || nodeData.name == 'SEGSSwitch') {
@@ -405,6 +406,15 @@ app.registerExtension({
input_name = "image";
break;
case 'ImpactMakeMaskList':
case 'ImpactMakeMaskBatch':
input_name = "mask";
break;
case 'ImpactMakeAnyList':
input_name = "value";
break;
case 'ImpactSEGSConcat':
input_name = "segs";
break;
@@ -473,8 +483,12 @@ app.registerExtension({
if(this.inputs[0].type == '*'){
const node = app.graph.getNodeById(link_info.origin_id);
let origin_type = node.outputs[link_info.origin_slot].type;
let origin_type = node.outputs[link_info.origin_slot]?.type;
if(link_info.target_slot == 0 && this.inputs.length > 1) {
origin_type = this.inputs[1].type;
node.connect(link_info.origin_slot, node.id, 'input1');
}
if(origin_type == '*') {
this.disconnectInput(link_info.target_slot);
return;
@@ -507,7 +521,7 @@ app.registerExtension({
!stackTrace.includes('LGraphNode.connect') && // for mouse device
!stackTrace.includes('loadGraphData') &&
this.inputs[index].name != 'select') {
this.removeInput(index);
this.removeInput(index);
}
}
@@ -527,7 +541,7 @@ app.registerExtension({
this.addInput(`${input_name}${slot_i}`, this.outputs[0].type);
}
if(this.widgets) {
if(this.widgets?.length) {
this.widgets[0].options.max = select_slot?this.inputs.length-1:this.inputs.length;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
if(this.widgets[0].options.max > 0 && this.widgets[0].value == 0)
@@ -573,17 +587,17 @@ app.registerExtension({
}
if(node.comfyClass == "ImpactSEGSLabelFilter" || node.comfyClass == "SEGSLabelFilterDetailerHookProvider") {
node.widgets[0].callback = (value, canvas, node, pos, e) => {
if(node.widgets[1].value.trim() != "" && !node.widgets[1].value.trim().endsWith(","))
node.widgets[1].value += ", "
node.widgets[1].value += value;
if(node.widgets_values)
node.widgets_values[1] = node.widgets[1].value;
}
Object.defineProperty(node.widgets[0], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(node.widgets[1].value.trim() != "" && !node.widgets[1].value.trim().endsWith(","))
node.widgets[1].value += ", "
node.widgets[1].value += value;
node.widgets_values[1] = node.widgets[1].value;
}
node._value = value;
},
get: () => {
@@ -653,18 +667,18 @@ app.registerExtension({
break;
}
node.widgets[combo_id+1].callback = (value, canvas, node, pos, e) => {
if(node.widgets[tbox_id].value != '')
node.widgets[tbox_id].value += ', '
node.widgets[tbox_id].value += node._wildcard_value;
}
Object.defineProperty(node.widgets[combo_id+1], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Select the Wildcard to add to the text") {
if(node.widgets[tbox_id].value != '')
node.widgets[tbox_id].value += ', '
node.widgets[tbox_id].value += value;
}
}
},
if (value !== "Select the Wildcard to add to the text")
node._wildcard_value = value;
},
get: () => { return "Select the Wildcard to add to the text"; }
});
@@ -676,24 +690,22 @@ app.registerExtension({
});
if(has_lora) {
node.widgets[combo_id].callback = (value, canvas, node, pos, e) => {
let lora_name = node._value;
if(lora_name.endsWith('.safetensors')) {
lora_name = lora_name.slice(0, -12);
}
node.widgets[tbox_id].value += `<lora:${lora_name}>`;
if(node.widgets_values) {
node.widgets_values[tbox_id] = node.widgets[tbox_id].value;
}
}
Object.defineProperty(node.widgets[combo_id], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Select the LoRA to add to the text") {
let lora_name = value;
if (lora_name.endsWith('.safetensors')) {
lora_name = lora_name.slice(0, -12);
}
node.widgets[tbox_id].value += `<lora:${lora_name}>`;
if(node.widgets_values) {
node.widgets_values[tbox_id] = node.widgets[tbox_id].value;
}
}
}
node._value = value;
if (value !== "Select the LoRA to add to the text")
node._value = value;
},
get: () => { return "Select the LoRA to add to the text"; }
+12 -8
View File
@@ -262,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);
@@ -353,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";
@@ -473,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);
}
@@ -508,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) {
+11 -7
View File
@@ -6,11 +6,15 @@ let refresh_btn2 = document.querySelector('button[title="Refresh widgets in node
let orig = refresh_btn.onclick;
refresh_btn.onclick = function() {
orig();
api.fetchApi('/impact/wildcards/refresh');
};
if(refresh_btn) {
refresh_btn.onclick = function() {
orig();
api.fetchApi('/impact/wildcards/refresh');
};
}
refresh_btn2.addEventListener('click', function() {
api.fetchApi('/impact/wildcards/refresh');
});
if(refresh_btn2) {
refresh_btn2?.addEventListener('click', function() {
api.fetchApi('/impact/wildcards/refresh');
});
}
+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;
}
+10
View File
@@ -5,6 +5,13 @@ 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):
@@ -53,6 +60,9 @@ class SEGSDetailerForAnimateDiff:
new_segs = []
cnet_image_list = []
if 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
+107 -16
View File
@@ -3,6 +3,7 @@ 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.
@@ -18,7 +19,11 @@ class PreviewBridge:
"images": ("IMAGE",),
"image": ("STRING", {"default": ""}),
},
"hidden": {"unique_id": "UNIQUE_ID"},
"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", )
@@ -29,6 +34,8 @@ class PreviewBridge:
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()
@@ -69,7 +76,7 @@ class PreviewBridge:
return image, mask.unsqueeze(0), ui_item
def doit(self, images, image, unique_id):
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:
@@ -82,10 +89,25 @@ class PreviewBridge:
pixels, mask, path_item = PreviewBridge.load_image(image)
image = [path_item]
else:
res = nodes.PreviewImage().save_images(images, filename_prefix="PreviewBridge/PB-")
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
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
path = os.path.join(folder_paths.get_temp_directory(), 'PreviewBridge', image2[0]['filename'])
core.set_previewbridge_image(unique_id, path, image2[0])
@@ -95,9 +117,23 @@ class PreviewBridge:
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": (pixels, mask, ),
"result": result,
}
@@ -118,6 +154,8 @@ def decode_latent(latent, preview_method, vae_opt=None):
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]
@@ -145,6 +183,12 @@ def decode_latent(latent, preview_method, vae_opt=None):
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()
@@ -166,15 +210,19 @@ class PreviewBridgeLatent:
return {"required": {
"latent": ("LATENT",),
"image": ("STRING", {"default": ""}),
"preview_method": (["Latent2RGB-SD3", "Latent2RGB-SDXL", "Latent2RGB-SD15",
"preview_method": (["Latent2RGB-FLUX.1",
"Latent2RGB-SDXL", "Latent2RGB-SD15", "Latent2RGB-SD3",
"Latent2RGB-SD-X4", "Latent2RGB-Playground-2.5",
"Latent2RGB-SC-Prior", "Latent2RGB-SC-B",
"TAESD3", "TAESDXL", "TAESD15"],),
"Latent2RGB-LTXV",
"TAEF1", "TAESDXL", "TAESD15", "TAESD3"],),
},
"optional": {
"vae_opt": ("VAE", )
"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"},
"hidden": {"unique_id": "UNIQUE_ID", "prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
RETURN_TYPES = ("LATENT", "MASK", )
@@ -185,6 +233,8 @@ class PreviewBridgeLatent:
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()
@@ -226,13 +276,19 @@ class PreviewBridgeLatent:
return image, mask, ui_item
def doit(self, latent, image, preview_method, vae_opt=None, unique_id=None):
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]
preview_method_channels = 16 if 'SD3' in preview_method or 'SC-Prior' in preview_method else 4
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, and SC-B 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, and SC-B are not compatible with each other.")
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
@@ -255,10 +311,14 @@ class PreviewBridgeLatent:
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)
@@ -280,11 +340,30 @@ class PreviewBridgeLatent:
'subfolder': 'PreviewBridge',
'type': 'temp',
}]
is_empty_mask = False
else:
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-")
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])
@@ -293,7 +372,19 @@ class PreviewBridgeLatent:
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": (res_latent, mask, ),
"result": result,
}
+2 -2
View File
@@ -1,10 +1,10 @@
import configparser
import os
version_code = [5, 18, 14]
version_code = [8, 1, 1]
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
dependency_version = 22
dependency_version = 24
my_path = os.path.dirname(__file__)
old_config_path = os.path.join(my_path, "impact-pack.ini")
+72 -24
View File
@@ -11,6 +11,7 @@ from impact.utils import *
from collections import namedtuple
import numpy as np
from skimage.measure import label
from PIL import ImageOps
import nodes
import comfy_extras.nodes_upscale_model as model_upscale
@@ -24,6 +25,8 @@ from comfy import model_management
from impact import utils
from impact import impact_sampling
from concurrent.futures import ThreadPoolExecutor
import inspect
try:
from comfy_extras import nodes_differential_diffusion
@@ -39,10 +42,21 @@ SEG = namedtuple("SEG",
pb_id_cnt = time.time()
preview_bridge_image_id_map = {}
preview_bridge_image_name_map = {}
preview_bridge_cache = {}
preview_bridge_last_mask_cache = {}
current_prompt = None
SCHEDULERS = comfy.samplers.KSampler.SCHEDULERS + ['AYS SDXL', 'AYS SD1', 'AYS SVD', 'GITS[coeff=1.2]']
SCHEDULERS = comfy.samplers.KSampler.SCHEDULERS + ['AYS SDXL', 'AYS SD1', 'AYS SVD', 'GITS[coeff=1.2]', 'LTXV[default]']
def is_execution_model_version_supported():
try:
import comfy_execution
return True
except:
return False
def set_previewbridge_image(node_id, file, item):
@@ -56,6 +70,13 @@ def set_previewbridge_image(node_id, file, item):
pb_id = f"${node_id}-{pb_id_cnt}"
preview_bridge_image_id_map[pb_id] = (file, item)
preview_bridge_image_name_map[node_id, file] = (pb_id, item)
if os.path.isfile(file):
i = Image.open(file)
i = ImageOps.exif_transpose(i)
if 'A' in i.getbands():
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
mask = 1. - torch.from_numpy(mask)
preview_bridge_last_mask_cache[node_id] = mask.unsqueeze(0)
pb_id_cnt += 1
return pb_id
@@ -229,7 +250,7 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
noise_mask = utils.tensor_gaussian_blur_mask(noise_mask, noise_mask_feather)
noise_mask = noise_mask.squeeze(3)
if noise_mask_feather > 0:
if noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
if wildcard_opt is not None and wildcard_opt != "":
@@ -306,7 +327,12 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
# prepare mask
if noise_mask is not None and inpaint_model:
positive, negative, latent_image = nodes.InpaintModelConditioning().encode(positive, negative, upscaled_image, vae, noise_mask)
imc_encode = nodes.InpaintModelConditioning().encode
if 'noise_mask' in inspect.signature(imc_encode).parameters:
positive, negative, latent_image = imc_encode(positive, negative, upscaled_image, vae, mask=noise_mask, noise_mask=True)
else:
print(f"[Impact Pack] ComfyUI is an outdated version.")
positive, negative, latent_image = imc_encode(positive, negative, upscaled_image, vae, noise_mask)
else:
latent_image = to_latent_image(upscaled_image, vae)
if noise_mask is not None:
@@ -375,7 +401,7 @@ def enhance_detail_for_animatediff(image_frames, model, clip, vae, guide_size, g
noise_mask = utils.tensor_gaussian_blur_mask(noise_mask, noise_mask_feather)
noise_mask = noise_mask.squeeze(3)
if noise_mask_feather > 0:
if noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
if wildcard_opt is not None and wildcard_opt != "":
@@ -1341,9 +1367,14 @@ def segs_to_masklist(segs):
return masks
def vae_decode(vae, samples, use_tile, hook, tile_size=512):
def vae_decode(vae, samples, use_tile, hook, tile_size=512, overlap=64):
if use_tile:
pixels = nodes.VAEDecodeTiled().decode(vae, samples, tile_size)[0]
decoder = nodes.VAEDecodeTiled()
if 'overlap' in inspect.signature(decoder.decode).parameters:
pixels = decoder.decode(vae, samples, tile_size, overlap=overlap)[0]
else:
print(f"[Impact Pack] Your ComfyUI is outdated.")
pixels = decoder.decode(vae, samples, tile_size)[0]
else:
pixels = nodes.VAEDecode().decode(vae, samples)[0]
@@ -1365,12 +1396,12 @@ def vae_encode(vae, pixels, use_tile, hook, tile_size=512):
return samples
def latent_upscale_on_pixel_space_shape(samples, scale_method, w, h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
return latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
def latent_upscale_on_pixel_space_shape(samples, scale_method, w, h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None, overlap=64):
return latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae, use_tile, tile_size, save_temp_prefix, hook, overlap=overlap)[0]
def latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size)
def latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None, overlap=64):
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size, overlap=overlap)
if save_temp_prefix is not None:
nodes.PreviewImage().save_images(pixels, filename_prefix=save_temp_prefix)
@@ -1384,12 +1415,12 @@ def latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae, use_t
return (vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size), old_pixels)
def latent_upscale_on_pixel_space(samples, scale_method, scale_factor, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
return latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
def latent_upscale_on_pixel_space(samples, scale_method, scale_factor, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None, overlap=64):
return latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use_tile, tile_size, save_temp_prefix, hook, overlap=overlap)[0]
def latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size)
def latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None, overlap=64):
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size, overlap=overlap)
if save_temp_prefix is not None:
nodes.PreviewImage().save_images(pixels, filename_prefix=save_temp_prefix)
@@ -1405,12 +1436,12 @@ def latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use
return (vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size), old_pixels)
def latent_upscale_on_pixel_space_with_model_shape(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
return latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
def latent_upscale_on_pixel_space_with_model_shape(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None, overlap=64):
return latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile, tile_size, save_temp_prefix, hook, overlap=overlap)[0]
def latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size)
def latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None, overlap=64):
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size, overlap=overlap)
if save_temp_prefix is not None:
nodes.PreviewImage().save_images(pixels, filename_prefix=save_temp_prefix)
@@ -1437,12 +1468,12 @@ def latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, upsca
def latent_upscale_on_pixel_space_with_model(samples, scale_method, upscale_model, scale_factor, vae, use_tile=False,
tile_size=512, save_temp_prefix=None, hook=None):
return latent_upscale_on_pixel_space_with_model2(samples, scale_method, upscale_model, scale_factor, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
tile_size=512, save_temp_prefix=None, hook=None, overlap=64):
return latent_upscale_on_pixel_space_with_model2(samples, scale_method, upscale_model, scale_factor, vae, use_tile, tile_size, save_temp_prefix, hook, overlap=overlap)[0]
def latent_upscale_on_pixel_space_with_model2(samples, scale_method, upscale_model, scale_factor, vae, use_tile=False,
tile_size=512, save_temp_prefix=None, hook=None):
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size)
tile_size=512, save_temp_prefix=None, hook=None, overlap=64):
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size, overlap=overlap)
if save_temp_prefix is not None:
nodes.PreviewImage().save_images(pixels, filename_prefix=save_temp_prefix)
@@ -1672,6 +1703,9 @@ class PixelKSampleUpscaler:
self.hook.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
upscaled_latent, denoise)
if 'noise_mask' in samples:
upscaled_latent['noise_mask'] = samples['noise_mask']
refined_latent = self.sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise, upscaled_images)
return refined_latent
@@ -1701,6 +1735,9 @@ class PixelKSampleUpscaler:
self.hook.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
upscaled_latent, denoise)
if 'noise_mask' in samples:
upscaled_latent['noise_mask'] = samples['noise_mask']
refined_latent = self.sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise, upscaled_images)
return refined_latent
@@ -1811,13 +1848,14 @@ class ControlNetWrapper:
class ControlNetAdvancedWrapper:
def __init__(self, control_net, strength, start_percent, end_percent, preprocessor, prev_control_net=None,
original_size=None, crop_region=None, control_image=None):
original_size=None, crop_region=None, control_image=None, vae=None):
self.control_net = control_net
self.strength = strength
self.preprocessor = preprocessor
self.prev_control_net = prev_control_net
self.start_percent = start_percent
self.end_percent = end_percent
self.vae = vae
if original_size is not None and crop_region is not None and control_image is not None:
self.control_image = utils.tensor_resize(control_image, original_size[1], original_size[0])
@@ -1858,7 +1896,17 @@ class ControlNetAdvancedWrapper:
"To use 'ControlNetAdvancedWrapper' for AnimateDiff, 'ComfyUI-Advanced-ControlNet' extension is required.")
raise Exception("'ACN_AdvancedControlNetApply' node isn't installed.")
else:
positive, negative = nodes.ControlNetApplyAdvanced().apply_controlnet(positive, negative, self.control_net, cnet_image, self.strength, self.start_percent, self.end_percent)
if self.vae is not None:
apply_controlnet = nodes.ControlNetApplyAdvanced().apply_controlnet
signature = inspect.signature(apply_controlnet)
if 'vae' in signature.parameters:
positive, negative = nodes.ControlNetApplyAdvanced().apply_controlnet(positive, negative, self.control_net, cnet_image, self.strength, self.start_percent, self.end_percent, vae=self.vae)
else:
print(f"[Impact Pack] ERROR: The ComfyUI version is outdated. VAE cannot be used in ApplyControlNet.")
raise Exception("[Impact Pack] ERROR: The ComfyUI version is outdated. VAE cannot be used in ApplyControlNet.")
else:
positive, negative = nodes.ControlNetApplyAdvanced().apply_controlnet(positive, negative, self.control_net, cnet_image, self.strength, self.start_percent, self.end_percent)
return positive, negative, cnet_image_list
+29 -19
View File
@@ -5,21 +5,31 @@ 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})
}
}
@@ -38,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})
}
}
@@ -199,7 +209,7 @@ class SimpleDetectorForEach:
},
"optional": {
"post_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"sam_model_opt": ("SAM_MODEL", ),
"sam_model_opt": ("SAM_MODEL", SAM_MODEL_TOOLTIP_OPTIONAL),
"segm_detector_opt": ("SEGM_DETECTOR", ),
}
}
@@ -311,7 +321,7 @@ class SimpleDetectorForAnimateDiff:
"optional": {
"masking_mode": (["Pivot SEGS", "Combine neighboring frames", "Don't combine"],),
"segs_pivot": (["Combined mask", "1st frame mask"],),
"sam_model_opt": ("SAM_MODEL", ),
"sam_model_opt": ("SAM_MODEL", SAM_MODEL_TOOLTIP_OPTIONAL),
"segm_detector_opt": ("SEGM_DETECTOR", ),
}
}
+3 -1
View File
@@ -78,6 +78,8 @@ class PreviewDetailerHookProvider:
CATEGORY = "ImpactPack/Util"
NOT_IDEMPOTENT = True
def doit(self, quality, unique_id):
hook = hooks.PreviewDetailerHook(unique_id, quality)
return (hook, hook)
return hook, hook
+264 -36
View File
@@ -27,6 +27,15 @@ import comfy.model_management
import base64
import impact.wildcards as wildcards
from . import hooks
from . import utils
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.")
warnings.filterwarnings('ignore', category=UserWarning, message='TypedStorage is deprecated')
@@ -61,10 +70,10 @@ class CLIPSegDetectorProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"text": ("STRING", {"multiline": False}),
"blur": ("FLOAT", {"min": 0, "max": 15, "step": 0.1, "default": 7}),
"threshold": ("FLOAT", {"min": 0, "max": 1, "step": 0.05, "default": 0.4}),
"dilation_factor": ("INT", {"min": 0, "max": 10, "step": 1, "default": 4}),
"text": ("STRING", {"multiline": False, "tooltip": "Enter the targets to be detected, separated by commas"}),
"blur": ("FLOAT", {"min": 0, "max": 15, "step": 0.1, "default": 7, "tooltip": "Blurs the detected mask"}),
"threshold": ("FLOAT", {"min": 0, "max": 1, "step": 0.05, "default": 0.4, "tooltip": "Detects only areas that are certain above the threshold."}),
"dilation_factor": ("INT", {"min": 0, "max": 10, "step": 1, "default": 4, "tooltip": "Dilates the detected mask."}),
}
}
@@ -73,6 +82,8 @@ class CLIPSegDetectorProvider:
CATEGORY = "ImpactPack/Util"
DESCRIPTION = "Provides a detection function using CLIPSeg, which generates masks based on text prompts.\nTo use this node, the CLIPSeg custom node must be installed."
def doit(self, text, blur, threshold, dilation_factor):
if "CLIPSeg" in nodes.NODE_CLASS_MAPPINGS:
return (core.BBoxDetectorBasedOnCLIPSeg(text, blur, threshold, dilation_factor), )
@@ -86,8 +97,10 @@ class SAMLoader:
models = [x for x in folder_paths.get_filename_list("sams") if 'hq' not in x]
return {
"required": {
"model_name": (models + ['ESAM'], ),
"device_mode": (["AUTO", "Prefer GPU", "CPU"],),
"model_name": (models + ['ESAM'], {"tooltip": "The detection accuracy varies depending on the SAM model. ESAM can only be used if ComfyUI-YoloWorld-EfficientSAM is installed."}),
"device_mode": (["AUTO", "Prefer GPU", "CPU"], {"tooltip": "AUTO: Only applicable when a GPU is available. It temporarily loads the SAM_MODEL into VRAM only when the detection function is used.\n"
"Prefer GPU: Tries to keep the SAM_MODEL on the GPU whenever possible. This can be used when there is sufficient VRAM available.\n"
"CPU: Always loads only on the CPU."}),
}
}
@@ -96,6 +109,8 @@ class SAMLoader:
CATEGORY = "ImpactPack"
DESCRIPTION = "Load the SAM (Segment Anything) model. This can be used in places that utilize SAM detection functionality, such as SAMDetector or SimpleDetector.\nThe SAM detection functionality in Impact Pack must use the SAM_MODEL loaded through this node."
def load_model(self, model_name, device_mode="auto"):
if model_name == 'ESAM':
if 'ESAM_ModelLoader_Zho' not in nodes.NODE_CLASS_MAPPINGS:
@@ -210,6 +225,10 @@ class DetailerForEach:
CATEGORY = "ImpactPack/Detailer"
@staticmethod
def get_core_module():
return core
@staticmethod
def do_detail(image, segs, model, clip, vae, guide_size, guide_size_for_bbox, max_size, seed, steps, cfg, sampler_name, scheduler,
positive, negative, denoise, feather, noise_mask, force_inpaint, wildcard_opt=None, detailer_hook=None,
@@ -237,14 +256,22 @@ class DetailerForEach:
else:
wmode, wildcard_chooser = None, None
if wmode in ['ASC', 'DSC']:
if wmode in ['ASC', 'DSC', 'ASC-SIZE', 'DSC-SIZE']:
if wmode == 'ASC':
ordered_segs = sorted(segs[1], key=lambda x: (x.bbox[0], x.bbox[1]))
else:
elif wmode == 'DSC':
ordered_segs = sorted(segs[1], key=lambda x: (x.bbox[0], x.bbox[1]), reverse=True)
elif wmode == 'ASC-SIZE':
ordered_segs = sorted(segs[1], key=lambda x: (x.bbox[2]-x.bbox[0]) * (x.bbox[3]-x.bbox[1]))
else: # wmode == 'DSC-SIZE'
ordered_segs = sorted(segs[1], key=lambda x: (x.bbox[2]-x.bbox[0]) * (x.bbox[3]-x.bbox[1]), reverse=True)
else:
ordered_segs = segs[1]
if noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
for i, seg in enumerate(ordered_segs):
cropped_image = crop_ndarray4(image.cpu().numpy(), seg.crop_region) # Never use seg.cropped_image to handle overlapping area
cropped_image = to_tensor(cropped_image)
@@ -278,14 +305,25 @@ class DetailerForEach:
for condition, details in positive
]
cropped_negative = [
[condition, {
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
for k, v in details.items()
}]
for condition, details in negative
]
if not isinstance(negative, str):
cropped_negative = [
[condition, {
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
for k, v in details.items()
}]
for condition, details in negative
]
else:
# Negative Conditioning is placeholder such as FLUX.1
cropped_negative = negative
if wildcard_item and wildcard_item.strip() == '[SKIP]':
continue
if wildcard_item and wildcard_item.strip() == '[STOP]':
break
orig_cropped_image = cropped_image.clone()
enhanced_image, cnet_pils = core.enhance_detail(cropped_image, model, clip, vae, guide_size, guide_size_for_bbox, max_size,
seg.bbox, seg_seed, steps, cfg, sampler_name, scheduler,
cropped_positive, cropped_negative, denoise, cropped_mask, force_inpaint,
@@ -305,7 +343,7 @@ class DetailerForEach:
# use image paste
image = image.cpu()
enhanced_image = enhanced_image.cpu()
tensor_paste(image, enhanced_image, (seg.crop_region[0], seg.crop_region[1]), mask)
tensor_paste(image, enhanced_image, (seg.crop_region[0], seg.crop_region[1]), mask) # this code affecting to `cropped_image`.
enhanced_list.append(enhanced_image)
if detailer_hook is not None:
@@ -323,7 +361,7 @@ class DetailerForEach:
else:
new_seg_image = None
cropped_list.append(cropped_image)
cropped_list.append(orig_cropped_image) # NOTE: Don't use `cropped_image`
new_seg = SEG(new_seg_image, seg.cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, seg.control_net_wrapper)
new_segs.append(new_seg)
@@ -964,7 +1002,10 @@ class PixelTiledKSampleUpscalerProvider:
tile_size=max(tile_width, tile_height), tile_cnet_strength=tile_cnet_strength)
return (upscaler, )
else:
print("[ERROR] PixelTiledKSampleUpscalerProvider: ComfyUI_TiledKSampler custom node isn't installed. You must install BlenderNeko/ComfyUI_TiledKSampler extension to use this node.")
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_TiledKSampler',
"To use 'PixelTiledKSampleUpscalerProvider' node, 'BlenderNeko/ComfyUI_TiledKSampler' extension is required.")
raise Exception("[ERROR] PixelTiledKSampleUpscalerProvider: ComfyUI_TiledKSampler custom node isn't installed. You must install BlenderNeko/ComfyUI_TiledKSampler extension to use this node.")
class PixelTiledKSampleUpscalerProviderPipe:
@@ -1213,6 +1254,7 @@ class IterativeLatentUpscale:
upscale_factor_unit = max(0, (upscale_factor - 1.0) / steps)
current_latent = samples
noise_mask = current_latent.get('noise_mask')
scale = 1
for i in range(steps-1):
@@ -1227,6 +1269,8 @@ class IterativeLatentUpscale:
print(f"IterativeLatentUpscale[{i+1}/{steps}]: {new_w:.1f}x{new_h:.1f} (scale:{scale:.2f}) ")
step_info = i, steps
current_latent = upscaler.upscale_shape(step_info, current_latent, new_w, new_h, temp_prefix)
if noise_mask is not None:
current_latent['noise_mask'] = noise_mask
if scale < upscale_factor:
new_w = w*upscale_factor
@@ -1238,7 +1282,7 @@ class IterativeLatentUpscale:
core.update_node_status(unique_id, "", None)
return (current_latent, upscaler.vae)
return current_latent, upscaler.vae
class IterativeImageUpscale:
@@ -1621,6 +1665,8 @@ class BitwiseAndMaskForEach:
CATEGORY = "ImpactPack/Operation"
DESCRIPTION = "Retains only the overlapping areas between the masks included in base_segs and the mask regions of mask_segs. SEGS with no overlapping mask areas are filtered out."
def doit(self, base_segs, mask_segs):
mask = core.segs_to_combined_mask(mask_segs)
mask = make_3d_mask(mask)
@@ -1642,6 +1688,8 @@ class SubtractMaskForEach:
CATEGORY = "ImpactPack/Operation"
DESCRIPTION = "Removes only the overlapping areas between the masks included in base_segs and the mask regions of mask_segs. SEGS with no overlapping mask areas are filtered out."
def doit(self, base_segs, mask_segs):
mask = core.segs_to_combined_mask(mask_segs)
mask = make_3d_mask(mask)
@@ -1667,6 +1715,25 @@ class ToBinaryMask:
return (mask,)
class FlattenMask:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"masks": ("MASK",),
}
}
RETURN_TYPES = ("MASK",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Operation"
def doit(self, masks):
masks = utils.make_3d_mask(masks)
masks = utils.flatten_mask(masks)
return (masks,)
class BitwiseAndMask:
@classmethod
def INPUT_TYPES(s):
@@ -1767,6 +1834,135 @@ def get_file_item(base_type, path):
}
class MaskRectArea:
# Creates a rectangle mask using percentage.
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
},
"hidden": {"extra_pnginfo": "EXTRA_PNGINFO", "unique_id": "UNIQUE_ID"}
}
RETURN_TYPES = ("MASK",)
CATEGORY = "ImpactPack/Operation"
FUNCTION = "create_mask"
def create_mask(self, extra_pnginfo, unique_id, **kwargs):
# search for node
node_found = False
for node in extra_pnginfo["workflow"]["nodes"]:
if node["id"] == int(unique_id):
min_x = node["properties"].get("x", 0) / 100
min_y = node["properties"].get("y", 0) / 100
width = node["properties"].get("w", 0) / 100
height = node["properties"].get("h", 0) / 100
blur_radius = node["properties"].get("blur_radius", 0)
node_found = True
break
if not node_found:
raise ValueError(f"No node found with unique_id {unique_id}.")
# Create a mask with standard resolution (e.g., 512x512)
resolution = 512
mask = torch.zeros((resolution, resolution))
# Calculate pixel coordinates
min_x_px = int(min_x * resolution)
min_y_px = int(min_y * resolution)
max_x_px = int((min_x + width) * resolution)
max_y_px = int((min_y + height) * resolution)
# Draw the rectangle on the mask
mask[min_y_px:max_y_px, min_x_px:max_x_px] = 1
# Apply blur if the radii are greater than 0
if blur_radius > 0:
dx = blur_radius * 2 + 1
dy = blur_radius * 2 + 1
# Convert the mask to a format compatible with OpenCV (numpy array)
mask_np = mask.cpu().numpy().astype("float32")
# Apply Gaussian Blur
blurred_mask = cv2.GaussianBlur(mask_np, (dx, dy), 0)
# Convert back to tensor
mask = torch.from_numpy(blurred_mask)
# Return the mask as a tensor with an additional channel
return (mask.unsqueeze(0),)
class MaskRectAreaAdvanced:
# Creates a rectangle mask using pixels relative to image size.
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
},
"hidden": {"extra_pnginfo": "EXTRA_PNGINFO", "unique_id": "UNIQUE_ID"}
}
RETURN_TYPES = ("MASK",)
CATEGORY = "ImpactPack/Operation"
FUNCTION = "create_mask_advanced"
def create_mask_advanced(self, extra_pnginfo, unique_id, **kwargs):
# search for node
node_found = False
for node in extra_pnginfo["workflow"]["nodes"]:
if node["id"] == int(unique_id):
min_x = node["properties"]["x"]
min_y = node["properties"]["y"]
width = node["properties"]["w"]
height = node["properties"]["h"]
image_width = node["properties"]["width"]
image_height = node["properties"]["height"]
blur_radius = node["properties"]["blur_radius"]
node_found = True
break
if not node_found:
raise ValueError(f"No node found with unique_id {unique_id}.")
# Calculate maximum coordinates
max_x = min_x + width
max_y = min_y + height
# Create a mask with the image dimensions
mask = torch.zeros((image_height, image_width))
# Draw the rectangle on the mask
mask[int(min_y):int(max_y), int(min_x):int(max_x)] = 1
# Apply blur if the radii are greater than 0
if blur_radius > 0:
dx = blur_radius * 2 + 1
dy = blur_radius * 2 + 1
# Convert the mask to a format compatible with OpenCV (numpy array)
mask_np = mask.cpu().numpy().astype("float32")
# Apply Gaussian Blur
blurred_mask = cv2.GaussianBlur(mask_np, (dx, dy), 0)
# Convert back to tensor
mask = torch.from_numpy(blurred_mask)
# Return the mask as a tensor with an additional channel
return (mask.unsqueeze(0),)
class ImageReceiver:
@classmethod
def INPUT_TYPES(s):
@@ -1964,7 +2160,12 @@ class LatentSender(nodes.SaveLatent):
"samples": ("LATENT", ),
"filename_prefix": ("STRING", {"default": "latents/LatentSender"}),
"link_id": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
"preview_method": (["Latent2RGB-SDXL", "Latent2RGB-SD15", "TAESDXL", "TAESD15"],)
"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"],)
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
@@ -2006,14 +2207,33 @@ class LatentSender(nodes.SaveLatent):
if preview_method == "Latent2RGB-SD15":
latent_format = latent_formats.SD15()
method = LatentPreviewMethod.Latent2RGB
elif preview_method == "TAESD15":
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] LatentSender: '{preview_method}' is unsupported preview method.")
latent_format = latent_formats.SD15()
method = LatentPreviewMethod.TAESD
elif preview_method == "TAESDXL":
latent_format = latent_formats.SDXL()
method = LatentPreviewMethod.TAESD
else: # preview_method == "Latent2RGB-SDXL"
latent_format = latent_formats.SDXL()
method = LatentPreviewMethod.Latent2RGB
previewer = core.get_previewer("cpu", latent_format=latent_format, force=True, method=method)
@@ -2087,16 +2307,19 @@ class ImpactWildcardProcessor:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"wildcard_text": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"populated_text": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"mode": ("BOOLEAN", {"default": True, "label_on": "Populate", "label_off": "Fixed"}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"wildcard_text": ("STRING", {"multiline": True, "dynamicPrompts": False, "tooltip": "Enter a prompt using wildcard syntax."}),
"populated_text": ("STRING", {"multiline": True, "dynamicPrompts": False, "tooltip": "The actual value passed during the execution of 'ImpactWildcardProcessor' is what is shown here. The behavior varies slightly depending on the mode. Wildcard syntax can also be used in 'populated_text'."}),
"mode": ("BOOLEAN", {"default": True, "label_on": "Populate", "label_off": "Fixed", "tooltip": "Populate: Before running the workflow, it overwrites the existing value of 'populated_text' with the prompt processed from 'wildcard_text'. In this mode, 'populated_text' cannot be edited.\nFixed: Ignores wildcard_text and keeps 'populated_text' as is. You can edit 'populated_text' in this mode."}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Determines the random seed to be used for wildcard processing."}),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
}
CATEGORY = "ImpactPack/Prompt"
DESCRIPTION = ("The 'ImpactWildcardProcessor' processes text prompts written in wildcard syntax and outputs the processed text prompt.\n\n"
"TIP: Before the workflow is executed, the processing result of 'wildcard_text' is displayed in 'populated_text', and the populated text is saved along with the workflow. If you want to use a seed converted as input, write the prompt directly in 'populated_text' instead of 'wildcard_text', and set the mode to 'Fixed'.")
RETURN_TYPES = ("STRING", )
FUNCTION = "doit"
@@ -2115,17 +2338,22 @@ class ImpactWildcardEncode:
return {"required": {
"model": ("MODEL",),
"clip": ("CLIP",),
"wildcard_text": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"populated_text": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"mode": ("BOOLEAN", {"default": True, "label_on": "Populate", "label_off": "Fixed"}),
"wildcard_text": ("STRING", {"multiline": True, "dynamicPrompts": False, "tooltip": "Enter a prompt using wildcard syntax."}),
"populated_text": ("STRING", {"multiline": True, "dynamicPrompts": False, "tooltip": "The actual value passed during the execution of 'ImpactWildcardEncode' is what is shown here. The behavior varies slightly depending on the mode. Wildcard syntax can also be used in 'populated_text'."}),
"mode": ("BOOLEAN", {"default": True, "label_on": "Populate", "label_off": "Fixed", "tooltip": "Populate: Before running the workflow, it overwrites the existing value of 'populated_text' with the prompt processed from 'wildcard_text'. In this mode, 'populated_text' cannot be edited.\n"
"Fixed: Ignores wildcard_text and keeps 'populated_text' as is. You can edit 'populated_text' in this mode."}),
"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"], ),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Determines the random seed to be used for wildcard processing."}),
},
}
CATEGORY = "ImpactPack/Prompt"
DESCRIPTION = ("The 'ImpactWildcardEncode' node processes text prompts written in wildcard syntax and outputs them as conditioning. It also supports LoRA syntax, with the applied LoRA reflected in the model's output.\n\n"
"TIP1: Before the workflow is executed, the processing result of 'wildcard_text' is displayed in 'populated_text', and the populated text is saved along with the workflow. If you want to use a seed converted as input, write the prompt directly in 'populated_text' instead of 'wildcard_text', and set the mode to 'Fixed'.\n"
"TIP2: If the 'Inspire Pack' is installed, LBW(LoRA Block Weight) syntax can also be applied.")
RETURN_TYPES = ("MODEL", "CLIP", "CONDITIONING", "STRING")
RETURN_NAMES = ("model", "clip", "conditioning", "populated_text")
FUNCTION = "doit"
@@ -2150,7 +2378,7 @@ class ImpactSchedulerAdapter:
def INPUT_TYPES(s):
return {"required": {
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, {"defaultInput": True, }),
"extra_scheduler": (['None', 'AYS SDXL', 'AYS SD1', 'AYS SVD', 'GITS[coeff=1.2]'],),
"extra_scheduler": (['None', 'AYS SDXL', 'AYS SD1', 'AYS SVD', 'GITS[coeff=1.2]', 'LTXV[default]'],),
}}
CATEGORY = "ImpactPack/Util"
+27 -1
View File
@@ -6,10 +6,12 @@ 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.")
@@ -25,6 +27,8 @@ def calculate_sigmas(model, sampler, scheduler, steps):
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]
else:
sigmas = samplers.calculate_sigmas(model.get_model_object("model_sampling"), scheduler, steps)
@@ -140,7 +144,29 @@ def sample_with_custom_noise(model, add_noise, noise_seed, cfg, positive, negati
touched_callback = preview_callback
disable_pbar = not comfy.utils.PROGRESS_BAR_ENABLED
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)
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:
+26 -40
View File
@@ -24,37 +24,6 @@ import random
from server import PromptServer
@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)
sam_predictor = None
default_sam_model_name = os.path.join(impact_pack.model_path, "sams", "sam_vit_b_01ec64.pth")
@@ -346,6 +315,8 @@ 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:
@@ -353,13 +324,16 @@ 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' in v['inputs'] and v['inputs']['sel_mode'] and 'select' in v['inputs']:
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:
print(f"\n##### ##### #####\n[WARN] {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'] and 'select' in v['inputs']:
@@ -372,10 +346,14 @@ 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")
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 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']
@@ -400,6 +378,9 @@ def onprompt_for_switch(json_data):
if vv[1] + 1 != inversed_switch_info[vv[0]]:
disable_targets.add(kk)
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]}"
for kk, vv in v['inputs'].items():
@@ -437,9 +418,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']
+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):
+157 -67
View File
@@ -10,7 +10,6 @@ import re
import nodes
import traceback
class ImpactCompare:
@classmethod
def INPUT_TYPES(cls):
@@ -66,8 +65,8 @@ class ImpactConditionalBranch:
return {
"required": {
"cond": ("BOOLEAN",),
"tt_value": (any_typ,),
"ff_value": (any_typ,),
"tt_value": (any_typ,{"lazy": True}),
"ff_value": (any_typ,{"lazy": True}),
},
}
@@ -76,7 +75,13 @@ class ImpactConditionalBranch:
RETURN_TYPES = (any_typ, )
def doit(self, cond, tt_value, ff_value):
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:
@@ -86,11 +91,18 @@ class ImpactConditionalBranch:
class ImpactConditionalBranchSelMode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
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,),
@@ -102,7 +114,7 @@ class ImpactConditionalBranchSelMode:
RETURN_TYPES = (any_typ, )
def doit(self, cond, sel_mode, tt_value=None, ff_value=None):
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,)
@@ -260,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):
@@ -618,85 +648,145 @@ class ImpactControlBridge:
def INPUT_TYPES(cls):
return {"required": {
"value": (any_typ,),
"mode": ("BOOLEAN", {"default": True, "label_on": "Active", "label_off": "Mute/Bypass"}),
"behavior": ("BOOLEAN", {"default": True, "label_on": "Mute", "label_off": "Bypass"}),
"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
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=True, unique_id=None, prompt=None, extra_pnginfo=None):
# 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
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 = []
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)
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=True, unique_id=None, prompt=None, extra_pnginfo=None):
def doit(self, value, mode, behavior="Stop", unique_id=None, prompt=None, extra_pnginfo=None):
global error_skip_flag
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
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()
if core.is_execution_model_version_supported():
from comfy_execution.graph import ExecutionBlocker
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()
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), )
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
+19
View File
@@ -1,5 +1,7 @@
import folder_paths
import impact.wildcards
from impact.utils import any_typ
class ToDetailerPipe:
@classmethod
@@ -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):
+83 -10
View File
@@ -14,6 +14,13 @@ from comfy.cli_args import args
import math
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 SEGSDetailer:
@classmethod
def INPUT_TYPES(s):
@@ -69,6 +76,9 @@ class SEGSDetailer:
new_segs = []
cnet_pil_list = []
if noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
for i in range(batch_size):
seed += 1
for seg in segs[1]:
@@ -694,6 +704,68 @@ class SEGSToMaskBatch:
return (mask_batch,)
class SEGSMerge:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"segs": ("SEGS", ),
},
}
RETURN_TYPES = ("SEGS",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
DESCRIPTION = "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."
def doit(self, segs):
crop_left = sys.maxsize
crop_right = 0
crop_top = sys.maxsize
crop_bottom = 0
bbox_left = sys.maxsize
bbox_right = 0
bbox_top = sys.maxsize
bbox_bottom = 0
min_confidence = 1.0
for seg in segs[1]:
cx1 = seg.crop_region[0]
cy1 = seg.crop_region[1]
cx2 = seg.crop_region[2]
cy2 = seg.crop_region[3]
bx1 = seg.bbox[0]
by1 = seg.bbox[1]
bx2 = seg.bbox[2]
by2 = seg.bbox[3]
crop_left = min(crop_left, cx1)
crop_top = min(crop_top, cy1)
crop_right = max(crop_right, cx2)
crop_bottom = max(crop_bottom, cy2)
bbox_left = min(bbox_left, bx1)
bbox_top = min(bbox_top, by1)
bbox_right = max(bbox_right, bx2)
bbox_bottom = max(bbox_bottom, by2)
min_confidence = min(min_confidence, seg.confidence)
combined_mask = core.segs_to_combined_mask(segs)
cropped_mask = combined_mask[crop_top:crop_bottom, crop_left:crop_right]
cropped_mask = cropped_mask.unsqueeze(0)
crop_region = [crop_left, crop_top, crop_right, crop_bottom]
bbox = [bbox_left, bbox_top, bbox_right, bbox_bottom]
seg = SEG(None, cropped_mask, min_confidence, crop_region, bbox, 'merged', None)
return ((segs[0], [seg]),)
class SEGSConcat:
@classmethod
def INPUT_TYPES(s):
@@ -824,7 +896,7 @@ class From_SEG_ELT_bbox:
CATEGORY = "ImpactPack/Util"
def doit(self, bbox):
return bbox
return [int(c) for c in bbox]
class From_SEG_ELT_crop_region:
@@ -1029,10 +1101,10 @@ class SEG_ELT_BBOX_ScaleBy:
x1, y1, x2, y2 = x1-cx1, y1-cy1, x2-cx1, y2-cy1
h, w = mask.shape
x1 = min(w-1, max(0, x1))
x2 = min(w-1, max(0, x2))
y1 = min(h-1, max(0, y1))
y2 = min(h-1, max(0, y2))
x1 = int(min(w-1, max(0, x1)))
x2 = int(min(w-1, max(0, x2)))
y1 = int(min(h-1, max(0, y1)))
y2 = int(min(h-1, max(0, y2)))
mask_cropped = mask.copy()
mask_cropped[:, :x1] = 0 # zero fill left side
@@ -1290,6 +1362,8 @@ class ControlNetApplySEGS:
RETURN_TYPES = ("SEGS",)
FUNCTION = "doit"
DEPRECATED = True
CATEGORY = "ImpactPack/Util"
@staticmethod
@@ -1317,7 +1391,8 @@ class ControlNetApplyAdvancedSEGS:
},
"optional": {
"segs_preprocessor": ("SEGS_PREPROCESSOR",),
"control_image": ("IMAGE",)
"control_image": ("IMAGE",),
"vae": ("VAE",)
}
}
@@ -1327,13 +1402,13 @@ class ControlNetApplyAdvancedSEGS:
CATEGORY = "ImpactPack/Util"
@staticmethod
def doit(segs, control_net, strength, start_percent, end_percent, segs_preprocessor=None, control_image=None):
def doit(segs, control_net, strength, start_percent, end_percent, segs_preprocessor=None, control_image=None, vae=None):
new_segs = []
for seg in segs[1]:
control_net_wrapper = core.ControlNetAdvancedWrapper(control_net, strength, start_percent, end_percent, segs_preprocessor,
seg.control_net_wrapper, original_size=segs[0], crop_region=seg.crop_region,
control_image=control_image)
control_image=control_image, vae=vae)
new_seg = SEG(seg.cropped_image, seg.cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, control_net_wrapper)
new_segs.append(new_seg)
@@ -1403,8 +1478,6 @@ class SEGSPicker:
RETURN_TYPES = ("SEGS", )
OUTPUT_NODE = True
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
+7 -2
View File
@@ -98,7 +98,7 @@ def img2img_segs(image, model, clip, vae, seed, steps, cfg, sampler_name, schedu
noise_mask = tensor_gaussian_blur_mask(noise_mask, noise_mask_feather)
noise_mask = noise_mask.squeeze(3)
if noise_mask_feather > 0:
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:
@@ -106,7 +106,12 @@ def img2img_segs(image, model, clip, vae, seed, steps, cfg, sampler_name, schedu
# prepare mask
if noise_mask is not None and inpaint_model:
positive, negative, latent_image = nodes.InpaintModelConditioning().encode(positive, negative, image, vae, noise_mask)
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:
+146 -305
View File
@@ -5,39 +5,25 @@ 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"})
}}
TOOLTIPS = {
"input": {
"seed": "Random seed to use for generating CPU noise for sampling.",
"steps": "total sampling steps",
"cfg": "classifier free guidance value",
"sampler_name": "sampler",
"scheduler": "noise schedule",
"denoise": "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": "Sets the width of the tile to be used in TiledKSampler.",
"tile_height": "Sets the height of the tile to be used in TiledKSampler.",
"tiling_strategy": "Sets the tiling strategy for TiledKSampler.",
"basic_pipe": "basic_pipe input for sampling",
},
"output": ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
}
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
RETURN_TYPES = ("KSAMPLER",)
FUNCTION = "doit"
@@ -57,32 +43,20 @@ 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": (core.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",),
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
}
}
TOOLTIPS = {
"input": {
"seed": "Random seed to use for generating CPU noise for sampling.",
"steps": "total sampling steps",
"cfg": "classifier free guidance value",
"sampler_name": "sampler",
"scheduler": "noise schedule",
"denoise": "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 input for sampling",
"scheduler_func_opt": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored.",
},
"output": ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
}
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)",)
RETURN_TYPES = ("KSAMPLER",)
FUNCTION = "doit"
@@ -100,30 +74,19 @@ 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": (core.SCHEDULERS, ),
"sigma_factor": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}),
"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", ),
"scheduler_func_opt": ("SCHEDULER_FUNC",),
"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."}),
}
}
TOOLTIPS = {
"input": {
"cfg": "classifier free guidance value",
"sampler_name": "sampler",
"scheduler": "noise schedule",
"sigma_factor": "Multiplier of noise schedule",
"basic_pipe": "basic_pipe input for sampling",
"sampler_opt": "[OPTIONAL] Uses the passed sampler instead of internal impact_sampler.",
"scheduler_func_opt": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored.",
},
"output": ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
}
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
RETURN_TYPES = ("KSAMPLER_ADVANCED",)
FUNCTION = "doit"
@@ -141,22 +104,14 @@ 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"})
},
}
TOOLTIPS = {
"input": {
"latent_image": "input latent image",
"base_sampler": "Sampler to apply to the region outside the mask.",
"mask_sampler": "Sampler to apply to the masked region.",
"mask": "region mask",
},
"output": ("result latent", )
}
OUTPUT_TOOLTIPS = ("result latent", )
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
@@ -182,102 +137,50 @@ 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."})
},
}
TOOLTIPS = {
"input": {
"seed": "Random seed to use for generating CPU noise for sampling.",
"steps": "total sampling steps",
"denoise": "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": "input latent image",
"base_sampler": "Sampler to apply to the region outside the mask.",
"mask_sampler": "Sampler to apply to the masked region.",
"mask": "region mask",
"overlap_factor": "To smooth the seams of the region boundaries, expand the mask by the overlap_factor amount to overlap with other regions.",
},
"output": ("result latent", )
}
OUTPUT_TOOLTIPS = ("result latent", )
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
@staticmethod
def mask_erosion(samples, mask, grow_mask_by):
mask = mask.clone()
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()
@staticmethod
def doit(seed, steps, denoise, samples, base_sampler, mask_sampler, mask, overlap_factor):
regional_prompts = RegionalPrompt().doit(mask=mask, advanced_sampler=mask_sampler)[0]
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", recovery_mode="ratio additional")
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, recovery_mode="ratio additional")
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}),
"variation_strength": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"variation_method": (["linear", "slerp"],),
"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."}),
}
}
TOOLTIPS = {
"input": {
"mask": "region mask",
"advanced_sampler": "sampler for specified region",
},
"output": ("regional prompts. (Can be used in the RegionalSampler.)", )
}
OUTPUT_TOOLTIPS = ("regional prompts. (Can be used in the RegionalSampler.)", )
RETURN_TYPES = ("REGIONAL_PROMPTS", )
FUNCTION = "doit"
@@ -294,16 +197,11 @@ 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.)"}),
},
}
TOOLTIPS = {
"input": {
"regional_prompts1": "input regional_prompts. (Connecting to the input slot increases the number of additional slots.)",
},
"output": ("Combined REGIONAL_PROMPTS", )
}
OUTPUT_TOOLTIPS = ("Combined REGIONAL_PROMPTS", )
RETURN_TYPES = ("REGIONAL_PROMPTS", )
FUNCTION = "doit"
@@ -323,16 +221,11 @@ 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.)" }),
},
}
TOOLTIPS = {
"input": {
"conditioning1": "input conditionings. (Connecting to the input slot increases the number of additional slots.)",
},
"output": ("Combined conditioning", )
}
OUTPUT_TOOLTIPS = ("Combined conditioning", )
RETURN_TYPES = ("CONDITIONING", )
FUNCTION = "doit"
@@ -352,16 +245,11 @@ class ConcatConditionings:
@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.)" }),
},
}
TOOLTIPS = {
"input": {
"conditioning1": "input conditionings. (Connecting to the input slot increases the number of additional slots.)",
},
"output": ("Concatenated conditioning", )
}
OUTPUT_TOOLTIPS = ("Concatenated conditioning", )
RETURN_TYPES = ("CONDITIONING", )
FUNCTION = "doit"
@@ -394,43 +282,25 @@ 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"}),
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between"}),
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"],),
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01}),
"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"},
}
TOOLTIPS = {
"input": {
"seed": "Random seed to use for generating CPU noise for sampling.",
"seed_2nd": "Additional noise seed. The behavior is determined by seed_2nd_mode.",
"seed_2nd_mode": "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": "total sampling steps",
"base_only_steps": "total sampling steps",
"denoise": "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": "input latent image",
"base_sampler": "The sampler applied outside the area set by the regional_prompt.",
"regional_prompts": "The prompt applied to each region",
"overlap_factor": "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": "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": "..._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": "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": "Multiplier of noise schedule to be applied according to additional_mode.",
},
"output": ("result latent", )
}
OUTPUT_TOOLTIPS = ("result latent", )
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
@@ -462,6 +332,10 @@ class RegionalSampler:
@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:
@@ -519,7 +393,8 @@ class RegionalSampler:
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, 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:
@@ -576,44 +451,25 @@ 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", ),
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between"}),
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"],),
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01}),
"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"},
}
TOOLTIPS = {
"input": {
"add_noise": "Whether to add noise",
"noise_seed": "Random seed to use for generating CPU noise for sampling.",
"steps": "total sampling steps",
"start_at_step": "The starting step of the sampling to be applied at this node within the range of 'steps'.",
"end_at_step": "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": "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": "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": "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": "input latent image",
"base_sampler": "The sampler applied outside the area set by the regional_prompt.",
"regional_prompts": "The prompt applied to each region",
"additional_mode": "..._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": "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": "Multiplier of noise schedule to be applied according to additional_mode.",
},
"output": ("result latent", )
}
OUTPUT_TOOLTIPS = ("result latent", )
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
@@ -624,6 +480,9 @@ class RegionalSamplerAdvanced:
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:
@@ -639,7 +498,6 @@ 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 = {}
@@ -714,35 +572,22 @@ 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": (core.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", ),
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
}
}
TOOLTIPS = {
"input": {
"basic_pipe": "basic_pipe input for sampling",
"seed": "Random seed to use for generating CPU noise for sampling.",
"steps": "total sampling steps",
"cfg": "classifier free guidance value",
"sampler_name": "sampler",
"scheduler": "noise schedule",
"latent_image": "input latent image",
"denoise": "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.",
"scheduler_func_opt": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored.",
},
"output": ("passthrough input basic_pipe", "result latent", "VAE in basic_pipe")
}
OUTPUT_TOOLTIPS = ("passthrough input basic_pipe", "result latent", "VAE in basic_pipe")
RETURN_TYPES = ("BASIC_PIPE", "LATENT", "VAE")
FUNCTION = "sample"
@@ -760,41 +605,25 @@ 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": (core.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", ),
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
}
}
TOOLTIPS = {
"input": {
"basic_pipe": "basic_pipe input for sampling",
"add_noise": "Whether to add noise",
"noise_seed": "Random seed to use for generating CPU noise for sampling.",
"steps": "total sampling steps",
"cfg": "classifier free guidance value",
"sampler_name": "sampler",
"scheduler": "noise schedule",
"latent_image": "input latent image",
"start_at_step": "The starting step of the sampling to be applied at this node within the range of 'steps'.",
"end_at_step": "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": "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.",
"scheduler_func_opt": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored.",
},
"output": ("passthrough input basic_pipe", "result latent", "VAE in basic_pipe")
}
OUTPUT_TOOLTIPS = ("passthrough input basic_pipe", "result latent", "VAE in basic_pipe")
RETURN_TYPES = ("BASIC_PIPE", "LATENT", "VAE")
FUNCTION = "sample"
@@ -813,25 +642,20 @@ class GITSSchedulerFuncProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"coeff": ("FLOAT", {"default": 1.20, "min": 0.80, "max": 1.50, "step": 0.05}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"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"}),
}
}
TOOLTIPS = {
"input": {
"coeff": "coeff factor of GITS Scheduler",
"denoise": "denoise amount for noise schedule",
},
"output": ("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.",)
}
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"
def doit(self, coeff, denoise):
@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.")
@@ -840,3 +664,20 @@ class GITSSchedulerFuncProvider:
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", )
+135 -16
View File
@@ -6,29 +6,59 @@ 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}"
@@ -50,11 +80,10 @@ class GeneralSwitch:
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 LatentSwitch:
@classmethod
@@ -126,23 +155,44 @@ class GeneralInversedSwitch:
@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": 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."}),
},
"hidden": {"unique_id": "UNIQUE_ID"},
"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, input, unique_id):
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 = []
for i in range(0, select):
# 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)
@@ -326,7 +376,7 @@ class ImageListToImageBatch:
def doit(self, images):
if len(images) <= 1:
return (images,)
return (images[0],)
else:
image1 = images[0]
for image2 in images[1:]:
@@ -352,6 +402,50 @@ class ImageBatchToImageList:
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 MakeImageList:
@classmethod
def INPUT_TYPES(s):
@@ -397,6 +491,31 @@ class MakeImageBatch:
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):
+21 -3
View File
@@ -5,8 +5,7 @@ import numpy as np
import folder_paths
import nodes
from . import config
from PIL import Image, ImageFilter
from scipy.ndimage import zoom
from PIL import Image
import comfy
@@ -537,6 +536,16 @@ def make_3d_mask(mask):
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
@@ -556,7 +565,8 @@ from torchvision.transforms.functional import to_pil_image
def resize_mask(mask, size):
resized_mask = torch.nn.functional.interpolate(mask.unsqueeze(0), size=size, mode='bilinear', align_corners=False)
mask = make_4d_mask(mask)
resized_mask = torch.nn.functional.interpolate(mask, size=size, mode='bilinear', align_corners=False)
return resized_mask.squeeze(0)
@@ -568,6 +578,14 @@ def apply_mask_alpha_to_pil(decoded_pil, mask):
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
+62 -26
View File
@@ -12,7 +12,7 @@ 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)
RE_WildCardQuantifier = re.compile(r"(?P<quantifier>\d+)#__(?P<keyword>[\w.\-+/*\\]+?)__", re.IGNORECASE)
wildcard_lock = threading.Lock()
wildcard_dict = {}
@@ -29,7 +29,7 @@ def get_wildcard_dict():
def wildcard_normalize(x):
return x.replace("\\", "/").lower()
return x.replace("\\", "/").replace(' ', '-').lower()
def read_wildcard(k, v):
@@ -53,23 +53,28 @@ 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
wildcard_dict[key] = [x for x in lines if not x.strip().startswith('#')]
elif file.endswith('.yaml'):
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
@@ -116,7 +121,7 @@ def process(text, seed=None):
select_sep = ' '
range_pattern = r'(\d+)(-(\d+))?'
range_pattern2 = r'-(\d+)'
wildcard_pattern = r"__([\w.\-+/*\\]+)__"
wildcard_pattern = r"__([\w.\-+/*\\]+?)__"
if len(multi_select_pattern) > 1:
r = re.match(range_pattern, options[0])
@@ -145,7 +150,7 @@ def process(text, seed=None):
matches = re.findall(wildcard_pattern, multi_select_pattern[1])
if len(options) == 1 and matches:
# count$$<single wildcard>
options = local_wildcard_dict.get(matches[0])
options = get_wildcard_options(multi_select_pattern[1])
else:
# count$$opt1|opt2|...
options[0] = multi_select_pattern[1]
@@ -194,8 +199,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):
pattern = r"__([\w.\-+/*\\]+)__"
pattern = r"__([\w.\-+/*\\]+?)__"
matches = re.findall(pattern, string)
replacements_found = False
@@ -254,7 +287,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):
@@ -420,7 +453,7 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None, seed=None,
def starts_with_regex(pattern, text):
regex = re.compile(pattern)
return bool(regex.match(text))
return regex.match(text)
def split_to_dict(text):
@@ -502,18 +535,21 @@ def process_wildcard_for_segs(wildcard):
return 'LAB', WildcardChooserDict(items)
elif starts_with_regex(r"\[(ASC|DSC|RND)\]", wildcard):
mode = wildcard[1:4]
items = split_string_with_sep(wildcard[5:])
if mode == 'RND':
random.shuffle(items)
return mode, WildcardChooser(items, True)
else:
return mode, WildcardChooser(items, False)
else:
return None, WildcardChooser([(None, 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():
+3 -3
View File
@@ -1,8 +1,8 @@
[project]
name = "comfyui-impact-pack"
description = "This extension offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler."
version = "5.18.14"
license = "LICENSE"
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.1.1"
license = { file = "LICENSE.txt" }
dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"]
[project.urls]
+2 -1
View File
@@ -3,6 +3,7 @@ scikit-image
piexif
transformers
opencv-python-headless
GitPython
scipy>=1.11.4
numpy<2
dill
matplotlib