Compare commits
122
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2824aa943 | ||
|
|
1b86633194 | ||
|
|
585787bfa7 | ||
|
|
84d7fb848a | ||
|
|
3fdede4e90 | ||
|
|
747afc4980 | ||
|
|
042a6fd793 | ||
|
|
f66da62702 | ||
|
|
ec2040bd78 | ||
|
|
606882362e | ||
|
|
27ec34e3ed | ||
|
|
8afba2e654 | ||
|
|
a823348392 | ||
|
|
f4b7dba485 | ||
|
|
2ffd006bec | ||
|
|
b798ed027f | ||
|
|
cc7812bcfe | ||
|
|
decff0d4c6 | ||
|
|
b095838302 | ||
|
|
0a9327bb5d | ||
|
|
8028d3b6c0 | ||
|
|
f83c907cba | ||
|
|
c486e65f0f | ||
|
|
9e7c4ea155 | ||
|
|
1af01b1ae3 | ||
|
|
170c9c35d9 | ||
|
|
eb4801e823 | ||
|
|
b2dd2ce794 | ||
|
|
837ac5c1f7 | ||
|
|
6183c00b95 | ||
|
|
b9eb80f599 | ||
|
|
50bd68238f | ||
|
|
b15c583917 | ||
|
|
6bc63ef415 | ||
|
|
31b3db7b16 | ||
|
|
c5c5e5c22d | ||
|
|
3f89d6efb5 | ||
|
|
8fc1073204 | ||
|
|
1f0b2fb79c | ||
|
|
7f7646b72f | ||
|
|
3169234402 | ||
|
|
01e35166d2 | ||
|
|
5ef704c022 | ||
|
|
0df8f5809d | ||
|
|
1e445bcacf | ||
|
|
5e225e9d5a | ||
|
|
f1c3afdbdb | ||
|
|
510d4355f2 | ||
|
|
3c25e6f52e | ||
|
|
c6a5a0f98a | ||
|
|
f6ec3a8164 | ||
|
|
4aec82be08 | ||
|
|
265738e71f | ||
|
|
77b0cd21b6 | ||
|
|
5ff4b3f0bc | ||
|
|
c4839a8b91 | ||
|
|
ddaedfe836 | ||
|
|
36fbaab563 | ||
|
|
c5cdfa2f40 | ||
|
|
9d22e7e55c | ||
|
|
4667ba1a8a | ||
|
|
7c96cdb771 | ||
|
|
7f70bf0eee | ||
|
|
da9d04d9a2 | ||
|
|
f705e47a0f | ||
|
|
a9440d63ec | ||
|
|
f942627b12 | ||
|
|
2555beb5cd | ||
|
|
c4ef168cc7 | ||
|
|
4d39c93122 | ||
|
|
bcab35a3b1 | ||
|
|
0742390991 | ||
|
|
1e6e0f92bf | ||
|
|
fe5a8cbf8a | ||
|
|
75799f5834 | ||
|
|
d1aaa4a097 | ||
|
|
483594f6be | ||
|
|
14c26fce8d | ||
|
|
e089110464 | ||
|
|
d511080f04 | ||
|
|
3a28fe18c6 | ||
|
|
b02d288635 | ||
|
|
2f5ff69b9e | ||
|
|
f88a4cfb06 | ||
|
|
e118f7b6af | ||
|
|
f3c44a568f | ||
|
|
548b2a3542 | ||
|
|
4ab4f59dc0 | ||
|
|
3a9c326a6b | ||
|
|
a6ace5b6a1 | ||
|
|
686c6e3ca7 | ||
|
|
5426b83d76 | ||
|
|
70196caa30 | ||
|
|
b3360478bc | ||
|
|
757d07c789 | ||
|
|
a820a88fb0 | ||
|
|
6626cb6781 | ||
|
|
aa47f5c7a1 | ||
|
|
6e11efd7fe | ||
|
|
33c68fdd8e | ||
|
|
b8a4febd51 | ||
|
|
9d3f786e5e | ||
|
|
3cefd47a32 | ||
|
|
b6aaa3994b | ||
|
|
d5598126c7 | ||
|
|
a733b506bd | ||
|
|
5d4cf09824 | ||
|
|
c9a90186f8 | ||
|
|
d3eab72eb8 | ||
|
|
b47cf8509b | ||
|
|
bd29e99d63 | ||
|
|
9dfd983da9 | ||
|
|
f0d3bd9d29 | ||
|
|
177ec41177 | ||
|
|
a6b438f562 | ||
|
|
95d4193815 | ||
|
|
33b8e7ba93 | ||
|
|
784c4fb884 | ||
|
|
c1e26a7008 | ||
|
|
ef8095b9af | ||
|
|
cbe1acb91c | ||
|
|
a295802b35 |
+3
-1
@@ -4,4 +4,6 @@ wildcards/**
|
||||
.vscode/
|
||||
.idea/
|
||||
subpack
|
||||
impact_subpack
|
||||
impact_subpack
|
||||
*.txt
|
||||
*.yaml
|
||||
|
||||
@@ -7,6 +7,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer
|
||||
|
||||
|
||||
## NOTICE
|
||||
* V4.73.3: ControlNetApply (SEGS) supports AnimateDiff
|
||||
* V4.20.1: Due to the feature update in `RegionalSampler`, the parameter order has changed, causing malfunctions in previously created `RegionalSamplers`. Please adjust the parameters accordingly.
|
||||
* V4.12: `MASKS` is changed to `MASK`.
|
||||
* V4.7.2 isn't compatible with old version of `ControlNet Auxiliary Preprocessor`. If you will use `MediaPipe FaceMesh to SEGS` update to latest version(Sep. 17th).
|
||||
@@ -39,7 +40,12 @@ This custom node helps to conveniently enhance images through Detector, Detailer
|
||||
* While `batch_masks` may not be completely separated, it provides functionality to perform some level of segmentation.
|
||||
* Simple Detector (SEGS) - Operating primarily with `BBOX_DETECTOR`, and with the additional provision of `SAM_MODEL` or `SEGM_DETECTOR`, this node internally generates improved SEGS through mask operations on both *bbox* and *silhouette*. It serves as a convenient tool to simplify a somewhat intricate workflow.
|
||||
|
||||
* ControlNetApply (SEGS) - To apply ControlNet in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
|
||||
* ControlNet
|
||||
* 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.
|
||||
* 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
|
||||
|
||||
* Bitwise(SEGS & SEGS) - Performs a 'bitwise and' operation between two SEGS.
|
||||
* Bitwise(SEGS - SEGS) - Subtracts one SEGS from another.
|
||||
@@ -79,6 +85,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer
|
||||
* SEGSPreview - Provides a preview of SEGS.
|
||||
* This option is used to preview the improved image through `SEGSDetailer` before merging it into the original. Prior to going through ```SEGSDetailer```, SEGS only contains mask information without image information. If fallback_image_opt is connected to the original image, SEGS without image information will generate a preview using the original image. However, if SEGS already contains image information, fallback_image_opt will be ignored.
|
||||
* This node can be used in conjunction with the processing results of AnimateDiff.
|
||||
* SEGSPreview (CNET Image) - Show images configured with `ControlNetApply (SEGS)` for debugging purposes.
|
||||
* SEGSToImageList - Convert SEGS To Image List
|
||||
* SEGSToMaskList - Convert SEGS To Mask List
|
||||
* SEGS Filter (label) - This node filters SEGS based on the label of the detected areas.
|
||||
@@ -86,14 +93,23 @@ 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.
|
||||
* SEGSConcat - Concatenate segs1 and segs2. If source shape of segs1 and segs2 are different from segs2 will be ignored.
|
||||
* Picker (SEGS) - Among the input SEGS, you can select a specific SEG through a dialog. If no SEG is selected, it outputs an empty SEGS. Increasing the batch_size of SEGSDetailer can be used for the purpose of selecting from the candidates.
|
||||
* DecomposeSEGS - Decompose SEGS to allow for detailed manipulation.
|
||||
* AssembleSEGS - Reassemble the decomposed SEGS.
|
||||
* From SEG_ELT - Extract detailed information from SEG_ELT.
|
||||
* Edit SEG_ELT - Modify some of the information in SEG_ELT.
|
||||
* Dilate SEG_ELT - Dilate the mask of SEG_ELT.
|
||||
* Set Default Image For SEGS - Set a default image for SEGS. SEGS with images set this way do not need to have a fallback image set. When override is set to false, the original image is preserved.
|
||||
* Remove Image from SEGS - Remove the image set for the SEGS that has been configured by "Set Default Image for SEGS" or SEGSDetailer. When the image for the SEGS is removed, the Detailer node will operate based on the currently processed image instead of the SEGS.
|
||||
* Make Tile SEGS - [experimental] Create SEGS in the form of tiles from an image to facilitate experiments for Tiled Upscale using the Detailer.
|
||||
* The `filter_in_segs_opt` and `filter_out_segs_opt` are optional inputs. If these inputs are provided, when creating the tiles, the mask for each tile is generated by overlapping with the mask of `filter_in_segs_opt` and excluding the overlap with the mask of `filter_out_segs_opt`. Tiles with an empty mask will not be created as SEGS.
|
||||
* Dilate Mask (SEGS) - Dilate/Erosion Mask in SEGS
|
||||
* Gaussian Blur Mask (SEGS) - Apply Gaussian Blur to Mask in SEGS
|
||||
* SEGS_ELT Manipulation - experimental nodes
|
||||
* DecomposeSEGS - Decompose SEGS to allow for detailed manipulation.
|
||||
* AssembleSEGS - Reassemble the decomposed SEGS.
|
||||
* From SEG_ELT - Extract detailed information from SEG_ELT.
|
||||
* Edit SEG_ELT - Modify some of the information in SEG_ELT.
|
||||
* Dilate SEG_ELT - Dilate the mask of SEG_ELT.
|
||||
|
||||
* Dilate Mask - Dilate Mask.
|
||||
* Support erosion for negative value.
|
||||
* Mask Manipulation
|
||||
* Dilate Mask - Dilate Mask.
|
||||
* Support erosion for negative value.
|
||||
* Gaussian Blur Mask - Apply Gaussian Blur to Mask. You can utilize this for mask feathering.
|
||||
|
||||
* Pipe nodes
|
||||
* ToDetailerPipe, FromDetailerPipe - These nodes are used to bundle multiple inputs used in the detailer, such as models and vae, ..., into a single DETAILER_PIPE or extract the elements that are bundled in the DETAILER_PIPE.
|
||||
@@ -107,19 +123,29 @@ This custom node helps to conveniently enhance images through Detector, Detailer
|
||||
* PixelTiledKSampleUpscalerProvider - It is similar to PixelKSampleUpscalerProvider, but it uses ComfyUI_TiledKSampler and Tiled VAE Decoder/Encoder to avoid GPU VRAM issues at high resolutions.
|
||||
* You need to install the [BlenderNeko/ComfyUI_TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) node extension.
|
||||
|
||||
* DenoiseScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the denoise to target_denoise as the step progresses.
|
||||
* CfgScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the cfg to target_cfg as the step progresses.
|
||||
* PixelKSampleHookCombine - This is used to connect two PK_HOOKs. hook1 is executed first and then hook2 is executed.
|
||||
* If you want to simultaneously change cfg and denoise, you can combine the PK_HOOKs of CfgScheduleHookProvider and PixelKSampleHookCombine.
|
||||
* NoiseInjectionHookProvider - During each iteration of IterativeUpscale, noise is injected into the latent space while varying the strength according to a schedule.
|
||||
* You need to install the [BlenderNeko/ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) node extension.
|
||||
* The seed serves as the initial value required for generating noise, and it increments by 1 with each iteration as the process unfolds.
|
||||
* The source determines the types of CPU noise and GPU noise to be configured.
|
||||
* Currently, there is only a simple schedule available, where the strength of the noise varies from start_strength to end_strength during the progression of each iteration.
|
||||
* NoiseInjectionDetailerHookProvider - The `detailer_hook` is a hook in the `Detailer` that injects noise during the processing of each SEGS.
|
||||
* CoreMLDetailerHookProvider - CoreML supports only 512x512, 512x768, 768x512, 768x768 size sampling. CoreMLDetailerHookProvider precisely fixes the upscale of the crop_region to this size. When using this hook, it will always be selected size, regardless of the guide_size. However, if the guide_size is too small, skipping will occur.
|
||||
* PK_HOOK
|
||||
* DenoiseScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the denoise to target_denoise as the step progresses.
|
||||
* CfgScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the cfg to target_cfg as the step progresses.
|
||||
* NoiseInjectionHookProvider - During each iteration of IterativeUpscale, noise is injected into the latent space while varying the strength according to a schedule.
|
||||
* You need to install the [BlenderNeko/ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) node extension.
|
||||
* The seed serves as the initial value required for generating noise, and it increments by 1 with each iteration as the process unfolds.
|
||||
* The source determines the types of CPU noise and GPU noise to be configured.
|
||||
* Currently, there is only a simple schedule available, where the strength of the noise varies from start_strength to end_strength during the progression of each iteration.
|
||||
* UnsamplerHookProvider - Apply Unsampler during each iteration. To use this node, ComfyUI_Noise must be installed.
|
||||
* PixelKSampleHookCombine - This is used to connect two PK_HOOKs. hook1 is executed first and then hook2 is executed.
|
||||
* If you want to simultaneously change cfg and denoise, you can combine the PK_HOOKs of CfgScheduleHookProvider and PixelKSampleHookCombine.
|
||||
|
||||
* DETAILER_HOOK
|
||||
* NoiseInjectionDetailerHookProvider - The `detailer_hook` is a hook in the `Detailer` that injects noise during the processing of each SEGS.
|
||||
* UnsamplerDetailerHookProvider - Apply Unsampler during each cycle. To use this node, ComfyUI_Noise must be installed.
|
||||
* DenoiseSchedulerDetailerHookProvider - During the progress of the cycle, the detailer's denoise is altered up to the `target_denoise`.
|
||||
* CoreMLDetailerHookProvider - CoreML supports only 512x512, 512x768, 768x512, 768x768 size sampling. CoreMLDetailerHookProvider precisely fixes the upscale of the crop_region to this size. When using this hook, it will always be selected size, regardless of the guide_size. However, if the guide_size is too small, skipping will occur.
|
||||
* DetailerHookCombine - This is used to connect two DETAILER_HOOKs. Similar to PixelKSampleHookCombine.
|
||||
* SEGSOrderedFilterDetailerHook, SEGSRangeFilterDetailerHook, SEGSLabelFilterDetailerHook - There are a wrapper node that provides SEGSFilter nodes to be applied in FaceDetailer or Detector by creating DETAILER_HOOK.
|
||||
* PreviewDetailerHOok - Connecting this hook node helps provide assistance for viewing previews whenever SEGS Detailing tasks are completed. When working with a large number of SEGS, such as Make Tile SEGS, it allows for monitoring the situation as improvements progress incrementally.
|
||||
* Since this is the hook applied when pasting onto the original image, it has no effect on nodes like `SEGSDetailer`.
|
||||
|
||||
* Iterative Upscale (Latent) - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling.
|
||||
* Iterative Upscale (Latent/on Pixel Space) - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling.
|
||||
This takes latent as input and outputs latent as the result.
|
||||
* Iterative Upscale (Image) - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling. This takes image as input and outputs image as the result.
|
||||
* Internally, this node uses 'Iterative Upscale (Latent)'.
|
||||
@@ -136,11 +162,17 @@ This takes latent as input and outputs latent as the result.
|
||||
* TwoSamplersForMaskUpscalerProvider - This is an Upscaler that extends TwoSamplersForMask to be used in Iterative Upscale.
|
||||
* TwoSamplersForMaskUpscalerProviderPipe - pipe version of TwoSamplersForMaskUpscalerProvider.
|
||||
|
||||
* PreviewBridge - This custom node can be used with a bridge when using the MaskEditor feature of Clipspace.
|
||||
* ImageSender, ImageReceiver - The images generated in ImageSender are automatically sent to the ImageReceiver with the same link_id.
|
||||
* LatentSender, LatentReceiver - The latent generated in LatentSender are automatically sent to the LatentReceiver with the same link_id.
|
||||
* Furthermore, LatentSender is implemented with PreviewLatent, which stores the latent in payload form within the image thumbnail.
|
||||
* Due to the current structure of ComfyUI, it is unable to distinguish between SDXL latent and SD1.5/SD2.1 latent. Therefore, it generates thumbnails by decoding them using the SD1.5 method.
|
||||
* Image Utils
|
||||
* PreviewBridge (image) - This custom node can be used with a bridge for image when using the MaskEditor feature of Clipspace.
|
||||
* PreviewBridge (latent) - This custom node can be used with a bridge for latent image when using the MaskEditor feature of Clipspace.
|
||||
* If a latent with a mask is provided as input, it displays the mask. Additionally, the mask output provides the mask set in the latent.
|
||||
* If a latent without a mask is provided as input, it outputs the original latent as is, but the mask output provides an output with the entire region set as a mask.
|
||||
* When set mask through MaskEditor, a mask is applied to the latent, and the output includes the stored mask. The same mask is also output as the mask output.
|
||||
* When connected to `vae_opt`, it takes higher priority than the `preview_method`.
|
||||
* ImageSender, ImageReceiver - The images generated in ImageSender are automatically sent to the ImageReceiver with the same link_id.
|
||||
* LatentSender, LatentReceiver - The latent generated in LatentSender are automatically sent to the LatentReceiver with the same link_id.
|
||||
* Furthermore, LatentSender is implemented with PreviewLatent, which stores the latent in payload form within the image thumbnail.
|
||||
* Due to the current structure of ComfyUI, it is unable to distinguish between SDXL latent and SD1.5/SD2.1 latent. Therefore, it generates thumbnails by decoding them using the SD1.5 method.
|
||||
|
||||
* Switch nodes
|
||||
* Switch (image,mask), Switch (latent), Switch (SEGS) - Among multiple inputs, it selects the input designated by the selector and outputs it. The first input must be provided, while the others are optional. However, if the input specified by the selector is not connected, an error may occur.
|
||||
@@ -180,20 +212,24 @@ This takes latent as input and outputs latent as the result.
|
||||
|
||||
* 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.
|
||||
|
||||
* Logics (experimental) - These nodes are experimental nodes designed to implement the logic for loops and dynamic switching.
|
||||
* ImpactCompare, ImpactConditionalBranch, ImpactInt, ImpactValueSender, ImpactValueReceiver, ImpactImageInfo, ImpactMinMax, ImpactNeg, ImpactConditionalStopIteration
|
||||
* ImpactCompare, ImpactConditionalBranch, ImpactConditionalBranchSelMode, ImpactInt, ImpactValueSender, ImpactValueReceiver, ImpactImageInfo, ImpactMinMax, ImpactNeg, ImpactConditionalStopIteration
|
||||
* ImpactIsNotEmptySEGS - This node returns `true` only if the input SEGS is not empty.
|
||||
* Queue Trigger - When this node is executed, it adds a new queue to assist with repetitive tasks. It will only execute if the signal's status changes.
|
||||
* Queue Trigger (Countdown) - Like the Queue Trigger, it adds a queue, but only adds it if it's greater than 1, and decrements the count by one each time it runs.
|
||||
* Sleep - Waits for the specified time (in seconds).
|
||||
* Set Widget Value - This node sets one of the optional inputs to the specified node's widget. An error may occur if the types do not match.
|
||||
* Set Mute State - This node changes the mute state of a specific node.
|
||||
* Control Bridge - Depending on whether the mode is set to `block` or `pass`, it changes the mute status of connected nodes. If there are nodes that require a change, the current execution is paused, the mute status is updated, and a new prompt queue is inserted.
|
||||
* Control Bridge - This node modifies the state of the connected control nodes based on the `mode` and `behavior` . If there are nodes that require a change, the current execution is paused, the mute status is updated, and a new prompt queue is inserted.
|
||||
* When the `mode` is `active`, it makes the connected control nodes active regardless of the behavior.
|
||||
* When the `mode` is `Bypass/Mute`, it changes the state of the connected nodes based on whether the behavior is `Bypass` or `Mute`.
|
||||
* **Limitation**: Due to these characteristics, it does not function correctly when the batch count exceeds 1. Additionally, it does not guarantee proper operation when the seed is randomized or when the state of nodes is altered by actions such as `Queue Trigger`, `Set Widget Value`, `Set Mute`, before the Control Bridge.
|
||||
* When utilizing this node, please structure the workflow in such a way that `Queue Trigger`, `Set Widget Value`, `Set Mute State`, and similar actions are executed at the end of the workflow.
|
||||
* If you want to change the value of the seed at each iteration, please ensure that Set Widget Value is executed at the end of the workflow instead of using randomization.
|
||||
* It is not a problem if the seed changes due to randomization as long as it occurs after the Control Bridge section.
|
||||
* Remote Boolean (on prompt), Remote Int (on prompt) - At the start of the prompt, this node forcibly sets the `widget_value` of `node_id`. It is disregarded if the target widget type is different.
|
||||
* You can find the `node_id` by checking through [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager) using the format `Badge: #ID Nickname`.
|
||||
* Experimental set of nodes for implementing loop functionality (tutorial to be prepared later / [example workflow](test/loop-test.json)).
|
||||
|
||||
@@ -232,6 +268,7 @@ This takes latent as input and outputs latent as the result.
|
||||
## 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'
|
||||
* Upon the initial execution, an `impact-pack.ini` file will be generated in the custom_nodes/ComfyUI-Impact-Pack directory.
|
||||
@@ -409,3 +446,5 @@ The tile sampler allows high-resolution sampling even in places with low GPU VRA
|
||||
BlenderNeok/[ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) - The noise injection feature relies on this function.
|
||||
|
||||
WASasquatch/[was-node-suite-comfyui](https://github.com/WASasquatch/was-node-suite-comfyui) - A powerful custom node extensions of ComfyUI.
|
||||
|
||||
Trung0246/[ComfyUI-0246](https://github.com/Trung0246/ComfyUI-0246) - Nice bypass hack!
|
||||
|
||||
+86
-14
@@ -20,7 +20,6 @@ custom_wildcards_path = os.path.join(os.path.dirname(__file__), "custom_wildcard
|
||||
|
||||
sys.path.append(modules_path)
|
||||
|
||||
|
||||
import impact.config
|
||||
import impact.sample_error_enhancer
|
||||
print(f"### Loading: ComfyUI-Impact-Pack ({impact.config.version})")
|
||||
@@ -105,12 +104,29 @@ from impact.util_nodes import *
|
||||
from impact.segs_nodes import *
|
||||
from impact.special_samplers import *
|
||||
from impact.hf_nodes import *
|
||||
from impact.bridge_nodes import *
|
||||
from impact.hook_nodes import *
|
||||
from impact.animatediff_nodes import *
|
||||
|
||||
import threading
|
||||
|
||||
wildcard_path = impact.config.get_config()['custom_wildcards']
|
||||
|
||||
|
||||
def wildcard_load():
|
||||
with wildcards.wildcard_lock:
|
||||
impact.wildcards.read_wildcard_dict(wildcards_path)
|
||||
|
||||
try:
|
||||
impact.wildcards.read_wildcard_dict(impact.config.get_config()['custom_wildcards'])
|
||||
except Exception as e:
|
||||
print(f"[Impact Pack] Failed to load custom wildcards directory.")
|
||||
|
||||
print(f"[Impact Pack] Wildcards loading done.")
|
||||
|
||||
|
||||
threading.Thread(target=wildcard_load).start()
|
||||
|
||||
impact.wildcards.read_wildcard_dict(wildcards_path)
|
||||
try:
|
||||
impact.wildcards.read_wildcard_dict(impact.config.get_config()['custom_wildcards'])
|
||||
except Exception as e:
|
||||
print(f"[Impact Pack] Failed to load custom wildcards directory.")
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"SAMLoader": SAMLoader,
|
||||
@@ -124,6 +140,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"DetailerForEachDebug": DetailerForEachTest,
|
||||
"DetailerForEachPipe": DetailerForEachPipe,
|
||||
"DetailerForEachDebugPipe": DetailerForEachTestPipe,
|
||||
"DetailerForEachPipeForAnimateDiff": DetailerForEachPipeForAnimateDiff,
|
||||
|
||||
"SAMDetectorCombined": SAMDetectorCombined,
|
||||
"SAMDetectorSegmented": SAMDetectorSegmented,
|
||||
@@ -161,8 +178,17 @@ NODE_CLASS_MAPPINGS = {
|
||||
"DenoiseScheduleHookProvider": DenoiseScheduleHookProvider,
|
||||
"CfgScheduleHookProvider": CfgScheduleHookProvider,
|
||||
"NoiseInjectionHookProvider": NoiseInjectionHookProvider,
|
||||
"NoiseInjectionDetailerHookProvider": NoiseInjectionDetailerHookProvider,
|
||||
"UnsamplerHookProvider": UnsamplerHookProvider,
|
||||
"CoreMLDetailerHookProvider": CoreMLDetailerHookProvider,
|
||||
"PreviewDetailerHookProvider": PreviewDetailerHookProvider,
|
||||
|
||||
"DetailerHookCombine": DetailerHookCombine,
|
||||
"NoiseInjectionDetailerHookProvider": NoiseInjectionDetailerHookProvider,
|
||||
"UnsamplerDetailerHookProvider": UnsamplerDetailerHookProvider,
|
||||
"DenoiseSchedulerDetailerHookProvider": DenoiseSchedulerDetailerHookProvider,
|
||||
"SEGSOrderedFilterDetailerHookProvider": SEGSOrderedFilterDetailerHookProvider,
|
||||
"SEGSRangeFilterDetailerHookProvider": SEGSRangeFilterDetailerHookProvider,
|
||||
"SEGSLabelFilterDetailerHookProvider": SEGSLabelFilterDetailerHookProvider,
|
||||
|
||||
"BitwiseAndMask": BitwiseAndMask,
|
||||
"SubtractMask": SubtractMask,
|
||||
@@ -177,7 +203,9 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ToBinaryMask": ToBinaryMask,
|
||||
"MasksToMaskList": MasksToMaskList,
|
||||
"MaskListToMaskBatch": MaskListToMaskBatch,
|
||||
"ImageListToImageBatch": ImageListToMaskBatch,
|
||||
"ImageListToImageBatch": ImageListToImageBatch,
|
||||
"SetDefaultImageForSEGS": DefaultImageForSEGS,
|
||||
"RemoveImageFromSEGS": RemoveImageFromSEGS,
|
||||
|
||||
"BboxDetectorSEGS": BboxDetectorForEach,
|
||||
"SegmDetectorSEGS": SegmDetectorForEach,
|
||||
@@ -186,6 +214,8 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactSimpleDetectorSEGS": SimpleDetectorForEach,
|
||||
"ImpactSimpleDetectorSEGSPipe": SimpleDetectorForEachPipe,
|
||||
"ImpactControlNetApplySEGS": ControlNetApplySEGS,
|
||||
"ImpactControlNetApplyAdvancedSEGS": ControlNetApplyAdvancedSEGS,
|
||||
"ImpactControlNetClearSEGS": ControlNetClearSEGS,
|
||||
|
||||
"ImpactDecomposeSEGS": DecomposeSEGS,
|
||||
"ImpactAssembleSEGS": AssembleSEGS,
|
||||
@@ -193,7 +223,11 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactEdit_SEG_ELT": Edit_SEG_ELT,
|
||||
"ImpactDilate_Mask_SEG_ELT": Dilate_SEG_ELT,
|
||||
"ImpactDilateMask": DilateMask,
|
||||
"ImpactGaussianBlurMask": GaussianBlurMask,
|
||||
"ImpactDilateMaskInSEGS": DilateMaskInSEGS,
|
||||
"ImpactGaussianBlurMaskInSEGS": GaussianBlurMaskInSEGS,
|
||||
"ImpactScaleBy_BBOX_SEG_ELT": SEG_ELT_BBOX_ScaleBy,
|
||||
"ImpactSEGSLatentComposite": SEGSLatentComposite,
|
||||
|
||||
"BboxDetectorCombined_v2": BboxDetectorCombined,
|
||||
"SegmDetectorCombined_v2": SegmDetectorCombined,
|
||||
@@ -207,6 +241,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"TwoAdvancedSamplersForMask": TwoAdvancedSamplersForMask,
|
||||
|
||||
"PreviewBridge": PreviewBridge,
|
||||
"PreviewBridgeLatent": PreviewBridgeLatent,
|
||||
"ImageSender": ImageSender,
|
||||
"ImageReceiver": ImageReceiver,
|
||||
"LatentSender": LatentSender,
|
||||
@@ -223,11 +258,13 @@ NODE_CLASS_MAPPINGS = {
|
||||
"SEGSDetailer": SEGSDetailer,
|
||||
"SEGSPaste": SEGSPaste,
|
||||
"SEGSPreview": SEGSPreview,
|
||||
"SEGSPreviewCNet": SEGSPreviewCNet,
|
||||
"SEGSToImageList": SEGSToImageList,
|
||||
"ImpactSEGSToMaskList": SEGSToMaskList,
|
||||
"ImpactSEGSToMaskBatch": SEGSToMaskBatch,
|
||||
"ImpactSEGSConcat": SEGSConcat,
|
||||
"ImpactSEGSPicker": SEGSPicker,
|
||||
"ImpactMakeTileSEGS": MakeTileSEGS,
|
||||
|
||||
"SEGSDetailerForAnimateDiff": SEGSDetailerForAnimateDiff,
|
||||
|
||||
@@ -247,6 +284,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"RegionalPrompt": RegionalPrompt,
|
||||
|
||||
"ImpactCombineConditionings": CombineConditionings,
|
||||
"ImpactConcatConditionings": ConcatConditionings,
|
||||
|
||||
"ImpactSEGSLabelFilter": SEGSLabelFilter,
|
||||
"ImpactSEGSRangeFilter": SEGSRangeFilter,
|
||||
@@ -254,11 +292,16 @@ NODE_CLASS_MAPPINGS = {
|
||||
|
||||
"ImpactCompare": ImpactCompare,
|
||||
"ImpactConditionalBranch": ImpactConditionalBranch,
|
||||
"ImpactConditionalBranchSelMode": ImpactConditionalBranchSelMode,
|
||||
"ImpactIfNone": ImpactIfNone,
|
||||
"ImpactConvertDataType": ImpactConvertDataType,
|
||||
"ImpactLogicalOperators": ImpactLogicalOperators,
|
||||
"ImpactInt": ImpactInt,
|
||||
# "ImpactFloat": ImpactFloat,
|
||||
"ImpactFloat": ImpactFloat,
|
||||
"ImpactValueSender": ImpactValueSender,
|
||||
"ImpactValueReceiver": ImpactValueReceiver,
|
||||
"ImpactImageInfo": ImpactImageInfo,
|
||||
"ImpactLatentInfo": ImpactLatentInfo,
|
||||
"ImpactMinMax": ImpactMinMax,
|
||||
"ImpactNeg": ImpactNeg,
|
||||
"ImpactConditionalStopIteration": ImpactConditionalStopIteration,
|
||||
@@ -276,6 +319,8 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactControlBridge": ImpactControlBridge,
|
||||
"ImpactIsNotEmptySEGS": ImpactNotEmptySEGS,
|
||||
"ImpactSleep": ImpactSleep,
|
||||
"ImpactRemoteBoolean": ImpactRemoteBoolean,
|
||||
"ImpactRemoteInt": ImpactRemoteInt,
|
||||
|
||||
"ImpactHFTransformersClassifierProvider": HF_TransformersClassifierProvider,
|
||||
"ImpactSEGSClassify": SEGS_Classify
|
||||
@@ -283,6 +328,8 @@ NODE_CLASS_MAPPINGS = {
|
||||
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"SAMLoader": "SAMLoader (Impact)",
|
||||
|
||||
"BboxDetectorSEGS": "BBOX Detector (SEGS)",
|
||||
"SegmDetectorSEGS": "SEGM Detector (SEGS)",
|
||||
"ONNXDetectorSEGS": "ONNX Detector (SEGS/legacy) - use BBOXDetector",
|
||||
@@ -290,6 +337,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ImpactSimpleDetectorSEGS": "Simple Detector (SEGS)",
|
||||
"ImpactSimpleDetectorSEGSPipe": "Simple Detector (SEGS/pipe)",
|
||||
"ImpactControlNetApplySEGS": "ControlNetApply (SEGS)",
|
||||
"ImpactControlNetApplyAdvancedSEGS": "ControlNetApplyAdvanced (SEGS)",
|
||||
|
||||
"BboxDetectorCombined_v2": "BBOX Detector (combined)",
|
||||
"SegmDetectorCombined_v2": "SEGM Detector (combined)",
|
||||
@@ -308,12 +356,13 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"DetailerForEachPipe": "Detailer (SEGS/pipe)",
|
||||
"DetailerForEachDebug": "DetailerDebug (SEGS)",
|
||||
"DetailerForEachDebugPipe": "DetailerDebug (SEGS/pipe)",
|
||||
"SEGSDetailerForAnimateDiff": "Detailer For AnimateDiff (SEGS/pipe)",
|
||||
"SEGSDetailerForAnimateDiff": "SEGSDetailer For AnimateDiff (SEGS/pipe)",
|
||||
"DetailerForEachPipeForAnimateDiff": "Detailer For AnimateDiff (SEGS/pipe)",
|
||||
|
||||
"SAMDetectorCombined": "SAMDetector (combined)",
|
||||
"SAMDetectorSegmented": "SAMDetector (segmented)",
|
||||
"FaceDetailerPipe": "FaceDetailer (pipe)",
|
||||
"MaskDetailerPipe": "MaskDetailer (Pipe)",
|
||||
"MaskDetailerPipe": "MaskDetailer (pipe)",
|
||||
|
||||
"FromDetailerPipeSDXL": "FromDetailer (SDXL/pipe)",
|
||||
"BasicPipeToDetailerPipeSDXL": "BasicPipe -> DetailerPipe (SDXL)",
|
||||
@@ -325,7 +374,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"EditDetailerPipe": "Edit DetailerPipe",
|
||||
|
||||
"LatentPixelScale": "Latent Scale (on Pixel Space)",
|
||||
"IterativeLatentUpscale": "Iterative Upscale (Latent)",
|
||||
"IterativeLatentUpscale": "Iterative Upscale (Latent/on Pixel Space)",
|
||||
"IterativeImageUpscale": "Iterative Upscale (Image)",
|
||||
|
||||
"TwoSamplersForMaskUpscalerProvider": "TwoSamplersForMask Upscaler Provider",
|
||||
@@ -343,6 +392,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ImpactSEGSToMaskList": "SEGS to Mask List",
|
||||
"ImpactSEGSToMaskBatch": "SEGS to Mask Batch",
|
||||
"ImpactSEGSPicker": "Picker (SEGS)",
|
||||
"ImpactMakeTileSEGS": "Make Tile SEGS",
|
||||
|
||||
"ImpactDecomposeSEGS": "Decompose (SEGS)",
|
||||
"ImpactAssembleSEGS": "Assemble (SEGS)",
|
||||
@@ -351,8 +401,12 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ImpactDilate_Mask_SEG_ELT": "Dilate Mask (SEG_ELT)",
|
||||
"ImpactScaleBy_BBOX_SEG_ELT": "ScaleBy BBOX (SEG_ELT)",
|
||||
"ImpactDilateMask": "Dilate Mask",
|
||||
"ImpactGaussianBlurMask": "Gaussian Blur Mask",
|
||||
"ImpactDilateMaskInSEGS": "Dilate Mask (SEGS)",
|
||||
"ImpactGaussianBlurMaskInSEGS": "Gaussian Blur Mask (SEGS)",
|
||||
|
||||
"PreviewBridge": "Preview Bridge",
|
||||
"PreviewBridge": "Preview Bridge (Image)",
|
||||
"PreviewBridgeLatent": "Preview Bridge (Latent)",
|
||||
"ImageSender": "Image Sender",
|
||||
"ImageReceiver": "Image Receiver",
|
||||
"ImageMaskSwitch": "Switch (images, mask)",
|
||||
@@ -367,10 +421,13 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ImpactMakeImageBatch": "Make Image Batch",
|
||||
"ImpactStringSelector": "String Selector",
|
||||
"ImpactIsNotEmptySEGS": "SEGS isn't Empty",
|
||||
"SetDefaultImageForSEGS": "Set Default Image for SEGS",
|
||||
"RemoveImageFromSEGS": "Remove Image from SEGS",
|
||||
|
||||
"RemoveNoiseMask": "Remove Noise Mask",
|
||||
|
||||
"ImpactCombineConditionings": "Combine Conditionings",
|
||||
"ImpactConcatConditionings": "Concat Conditionings",
|
||||
|
||||
"ImpactQueueTrigger": "Queue Trigger",
|
||||
"ImpactQueueTriggerCountdown": "Queue Trigger (Countdown)",
|
||||
@@ -378,12 +435,16 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ImpactNodeSetMuteState": "Set Mute State",
|
||||
"ImpactControlBridge": "Control Bridge",
|
||||
"ImpactSleep": "Sleep",
|
||||
"ImpactRemoteBoolean": "Remote Boolean (on prompt)",
|
||||
"ImpactRemoteInt": "Remote Int (on prompt)",
|
||||
|
||||
"ImpactHFTransformersClassifierProvider": "HF Transformers Classifier Provider",
|
||||
"ImpactSEGSClassify": "SEGS Classify",
|
||||
|
||||
"LatentSwitch": "Switch (latent/legacy)",
|
||||
"SEGSSwitch": "Switch (SEGS/legacy)"
|
||||
"SEGSSwitch": "Switch (SEGS/legacy)",
|
||||
|
||||
"SEGSPreviewCNet": "SEGSPreview (CNET Image)"
|
||||
}
|
||||
|
||||
if not impact.config.get_config()['mmdet_skip']:
|
||||
@@ -426,3 +487,14 @@ except Exception as e:
|
||||
|
||||
WEB_DIRECTORY = "js"
|
||||
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
|
||||
|
||||
|
||||
try:
|
||||
import cm_global
|
||||
cm_global.register_extension('ComfyUI-Impact-Pack',
|
||||
{'version': config.version_code,
|
||||
'name': 'Impact Pack',
|
||||
'nodes': set(NODE_CLASS_MAPPINGS.keys()),
|
||||
'description': 'This extension provides inpainting functionality based on the detector and detailer, along with convenient workflow features like wildcards and logics.', })
|
||||
except:
|
||||
pass
|
||||
|
||||
+6
-6
@@ -207,12 +207,6 @@ try:
|
||||
except:
|
||||
print(f"[ERROR] ComfyUI-Impact-Pack: failed to install 'opencv-python'. Please, install manually.")
|
||||
|
||||
try:
|
||||
import git
|
||||
except Exception:
|
||||
if not is_installed('gitpython'):
|
||||
process_wrap(pip_install + ['gitpython'])
|
||||
|
||||
def ensure_mmdet_package():
|
||||
try:
|
||||
import mmcv
|
||||
@@ -232,6 +226,12 @@ try:
|
||||
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.
|
||||
|
||||
if os.path.exists(subpack_install_script):
|
||||
|
||||
+17
-13
@@ -9,22 +9,26 @@ app.registerExtension({
|
||||
for(let i in node.widgets) {
|
||||
let widget = node.widgets[i];
|
||||
|
||||
if(conflict_check == undefined) {
|
||||
conflict_check = !!app.extensions.find((ext) => ext.name === "Comfy.comboBoolMigration");
|
||||
}
|
||||
if(conflict_check == undefined) {
|
||||
conflict_check = !!app.extensions.find((ext) => ext.name === "Comfy.comboBoolMigration");
|
||||
}
|
||||
|
||||
if(conflict_check)
|
||||
return;
|
||||
if(conflict_check)
|
||||
return;
|
||||
|
||||
if(widget.type == "toggle") {
|
||||
let value = widget.value;
|
||||
Object.defineProperty(widget, "value", {
|
||||
set: (value) => {
|
||||
delete widget.value;
|
||||
widget.value = value == true || value == widget.options.on;
|
||||
},
|
||||
get: () => { return value; }
|
||||
});
|
||||
let value = widget.value;
|
||||
|
||||
var v = Object.getOwnPropertyDescriptor(widget, 'value');
|
||||
if(!v) {
|
||||
Object.defineProperty(widget, "value", {
|
||||
set: (value) => {
|
||||
delete widget.value;
|
||||
widget.value = value == true || value == widget.options.on;
|
||||
},
|
||||
get: () => { return value; }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ async function bridgeContinue(event) {
|
||||
if(node) {
|
||||
const mutes = new Set(event.detail.mutes);
|
||||
const actives = new Set(event.detail.actives);
|
||||
const bypasses = new Set(event.detail.bypasses);
|
||||
|
||||
for(let i in app.graph._nodes_by_id) {
|
||||
let this_node = app.graph._nodes_by_id[i];
|
||||
@@ -62,6 +63,9 @@ async function bridgeContinue(event) {
|
||||
else if(actives.has(i)) {
|
||||
this_node.mode = 0;
|
||||
}
|
||||
else if(bypasses.has(i)) {
|
||||
this_node.mode = 4;
|
||||
}
|
||||
}
|
||||
|
||||
await app.queuePrompt(0, 1);
|
||||
@@ -76,3 +80,16 @@ function addQueue(event) {
|
||||
}
|
||||
|
||||
api.addEventListener("impact-add-queue", addQueue);
|
||||
|
||||
|
||||
function refreshPreview(event) {
|
||||
let node_id = event.detail.node_id;
|
||||
let item = event.detail.item;
|
||||
let img = new Image();
|
||||
img.src = `/view?filename=${item.filename}&subfolder=${item.subfolder}&type=${item.type}&no-cache=${Date.now()}`;
|
||||
let node = app.graph._nodes_by_id[node_id];
|
||||
if(node)
|
||||
node.imgs = [img];
|
||||
}
|
||||
|
||||
api.addEventListener("impact-preview", refreshPreview);
|
||||
|
||||
+30
-25
@@ -9,31 +9,31 @@ function load_image(str) {
|
||||
|
||||
function getFileItem(baseType, path) {
|
||||
try {
|
||||
let pathType = baseType;
|
||||
let pathType = baseType;
|
||||
|
||||
if (path.endsWith("[output]")) {
|
||||
pathType = "output";
|
||||
path = path.slice(0, -9);
|
||||
} else if (path.endsWith("[input]")) {
|
||||
pathType = "input";
|
||||
path = path.slice(0, -8);
|
||||
} else if (path.endsWith("[temp]")) {
|
||||
pathType = "temp";
|
||||
path = path.slice(0, -7);
|
||||
}
|
||||
if (path.endsWith("[output]")) {
|
||||
pathType = "output";
|
||||
path = path.slice(0, -9);
|
||||
} else if (path.endsWith("[input]")) {
|
||||
pathType = "input";
|
||||
path = path.slice(0, -8);
|
||||
} else if (path.endsWith("[temp]")) {
|
||||
pathType = "temp";
|
||||
path = path.slice(0, -7);
|
||||
}
|
||||
|
||||
const subfolder = path.substring(0, path.lastIndexOf('/'));
|
||||
const filename = path.substring(path.lastIndexOf('/') + 1);
|
||||
const subfolder = path.substring(0, path.lastIndexOf('/'));
|
||||
const filename = path.substring(path.lastIndexOf('/') + 1);
|
||||
|
||||
return {
|
||||
filename: filename,
|
||||
subfolder: subfolder,
|
||||
type: pathType
|
||||
};
|
||||
}
|
||||
catch(exception) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
filename: filename,
|
||||
subfolder: subfolder,
|
||||
type: pathType
|
||||
};
|
||||
}
|
||||
catch(exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadImageFromUrl(image, node_id, v, need_to_load) {
|
||||
@@ -74,13 +74,16 @@ app.registerExtension({
|
||||
name: "Comfy.Impact.img",
|
||||
|
||||
nodeCreated(node, app) {
|
||||
if(node.comfyClass == "PreviewBridge") {
|
||||
if(node.comfyClass == "PreviewBridge" || node.comfyClass == "PreviewBridgeLatent") {
|
||||
let w = node.widgets.find(obj => obj.name === 'image');
|
||||
node._imgs = [new Image()];
|
||||
node.imageIndex = 0;
|
||||
|
||||
Object.defineProperty(w, 'value', {
|
||||
async set(v) {
|
||||
if(w._lock)
|
||||
return;
|
||||
|
||||
const stackTrace = new Error().stack;
|
||||
if(stackTrace.includes('presetText.js'))
|
||||
return;
|
||||
@@ -101,7 +104,9 @@ app.registerExtension({
|
||||
}
|
||||
else {
|
||||
// from clipspace
|
||||
w._lock = true;
|
||||
w._value = await loadImageFromUrl(image, node.id, v, false);
|
||||
w._lock = false;
|
||||
}
|
||||
},
|
||||
get() {
|
||||
@@ -220,5 +225,5 @@ app.registerExtension({
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
+385
-354
@@ -11,6 +11,9 @@ async function load_wildcards() {
|
||||
|
||||
load_wildcards();
|
||||
|
||||
export function get_wildcards_list() {
|
||||
return wildcards_list;
|
||||
}
|
||||
|
||||
// temporary implementation (copying from https://github.com/pythongosssss/ComfyUI-WD14-Tagger)
|
||||
// I think this should be included into master!!
|
||||
@@ -123,6 +126,7 @@ function imgSendHandler(event) {
|
||||
img.onload = (event) => {
|
||||
nodes[i].imgs = [img];
|
||||
nodes[i].size[1] = Math.max(200, nodes[i].size[1]);
|
||||
app.canvas.setDirty(true);
|
||||
};
|
||||
img.src = `/view?filename=${data.filename}&type=${data.type}&subfolder=${data.subfolder}`+app.getPreviewFormatParam();
|
||||
}
|
||||
@@ -158,38 +162,38 @@ function latentSendHandler(event) {
|
||||
|
||||
|
||||
function valueSendHandler(event) {
|
||||
let nodes = app.graph._nodes;
|
||||
for(let i in nodes) {
|
||||
if(nodes[i].type == 'ImpactValueReceiver') {
|
||||
if(nodes[i].widgets[2].value == event.detail.link_id) {
|
||||
nodes[i].widgets[1].value = event.detail.value;
|
||||
let nodes = app.graph._nodes;
|
||||
for(let i in nodes) {
|
||||
if(nodes[i].type == 'ImpactValueReceiver') {
|
||||
if(nodes[i].widgets[2].value == event.detail.link_id) {
|
||||
nodes[i].widgets[1].value = event.detail.value;
|
||||
|
||||
let typ = typeof event.detail.value;
|
||||
if(typ == 'string') {
|
||||
nodes[i].widgets[0].value = "STRING";
|
||||
}
|
||||
else if(typ == "boolean") {
|
||||
nodes[i].widgets[0].value = "BOOLEAN";
|
||||
}
|
||||
else if(typ != "number") {
|
||||
nodes[i].widgets[0].value = typeof event.detail.value;
|
||||
}
|
||||
else if(Number.isInteger(event.detail.value)) {
|
||||
nodes[i].widgets[0].value = "INT";
|
||||
}
|
||||
else {
|
||||
nodes[i].widgets[0].value = "FLOAT";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let typ = typeof event.detail.value;
|
||||
if(typ == 'string') {
|
||||
nodes[i].widgets[0].value = "STRING";
|
||||
}
|
||||
else if(typ == "boolean") {
|
||||
nodes[i].widgets[0].value = "BOOLEAN";
|
||||
}
|
||||
else if(typ != "number") {
|
||||
nodes[i].widgets[0].value = typeof event.detail.value;
|
||||
}
|
||||
else if(Number.isInteger(event.detail.value)) {
|
||||
nodes[i].widgets[0].value = "INT";
|
||||
}
|
||||
else {
|
||||
nodes[i].widgets[0].value = "FLOAT";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const impactProgressBadge = new ImpactProgressBadge();
|
||||
|
||||
api.addEventListener("stop-iteration", () => {
|
||||
document.getElementById("autoQueueCheckbox").checked = false;
|
||||
document.getElementById("autoQueueCheckbox").checked = false;
|
||||
});
|
||||
api.addEventListener("value-send", valueSendHandler);
|
||||
api.addEventListener("img-send", imgSendHandler);
|
||||
@@ -206,244 +210,311 @@ app.registerExtension({
|
||||
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name == "IterativeLatentUpscale" || nodeData.name == "IterativeImageUpscale"
|
||||
|| nodeData.name == "RegionalSampler"|| nodeData.name == "RegionalSamplerAdvanced") {
|
||||
|| nodeData.name == "RegionalSampler"|| nodeData.name == "RegionalSamplerAdvanced") {
|
||||
impactProgressBadge.addStatusHandler(nodeType);
|
||||
}
|
||||
|
||||
if(nodeData.name === 'ImpactInversedSwitch') {
|
||||
nodeData.output = ['*'];
|
||||
nodeData.output_is_list = [false];
|
||||
nodeData.output_name = ['output1'];
|
||||
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 != '*')
|
||||
return;
|
||||
|
||||
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
|
||||
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
|
||||
if(!link_info)
|
||||
return;
|
||||
// assign type
|
||||
let slot_type = '*';
|
||||
|
||||
if(type == 2) {
|
||||
// connect output
|
||||
if(connected){
|
||||
if(app.graph._nodes_by_id[link_info.target_id].type == 'Reroute') {
|
||||
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
|
||||
}
|
||||
if(type == 2) {
|
||||
slot_type = link_info.type;
|
||||
}
|
||||
else {
|
||||
const node = app.graph.getNodeById(link_info.origin_id);
|
||||
slot_type = node.outputs[link_info.origin_slot].type;
|
||||
}
|
||||
|
||||
if(this.outputs[0].type == '*'){
|
||||
if(link_info.type == '*') {
|
||||
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
|
||||
}
|
||||
else {
|
||||
// propagate type
|
||||
this.outputs[0].type = link_info.type;
|
||||
this.outputs[0].name = link_info.type;
|
||||
this.inputs[0].type = slot_type;
|
||||
this.outputs[0].type = slot_type;
|
||||
this.outputs[0].label = slot_type;
|
||||
}
|
||||
}
|
||||
|
||||
for(let i in this.inputs) {
|
||||
if(this.inputs[i].name != 'select')
|
||||
this.inputs[i].type = link_info.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(app.graph._nodes_by_id[link_info.origin_id].type == 'Reroute')
|
||||
this.disconnectInput(link_info.target_slot);
|
||||
if(nodeData.name == "ImpactConditionalBranch" || nodeData.name == "ImpactConditionalBranchSelMode") {
|
||||
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
|
||||
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
|
||||
if(!link_info || this.inputs[0].type != '*')
|
||||
return;
|
||||
|
||||
// connect input
|
||||
if(this.inputs[0].type == '*'){
|
||||
const node = app.graph.getNodeById(link_info.origin_id);
|
||||
let origin_type = node.outputs[link_info.origin_slot].type;
|
||||
if(index >= 2)
|
||||
return;
|
||||
|
||||
if(origin_type == '*') {
|
||||
this.disconnectInput(link_info.target_slot);
|
||||
return;
|
||||
}
|
||||
// assign type
|
||||
let slot_type = '*';
|
||||
|
||||
for(let i in this.inputs) {
|
||||
if(this.inputs[i].name != 'select')
|
||||
this.inputs[i].type = origin_type;
|
||||
}
|
||||
if(type == 2) {
|
||||
slot_type = link_info.type;
|
||||
}
|
||||
else {
|
||||
const node = app.graph.getNodeById(link_info.origin_id);
|
||||
slot_type = node.outputs[link_info.origin_slot].type;
|
||||
}
|
||||
|
||||
this.outputs[0].type = origin_type;
|
||||
this.outputs[0].name = origin_type;
|
||||
}
|
||||
this.inputs[0].type = slot_type;
|
||||
this.inputs[1].type = slot_type;
|
||||
this.outputs[0].type = slot_type;
|
||||
this.outputs[0].label = slot_type;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if(nodeData.name == "ImpactCompare") {
|
||||
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
|
||||
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
|
||||
if(!link_info || this.inputs[0].type != '*' || type == 2)
|
||||
return;
|
||||
|
||||
if (!connected && this.outputs.length > 1) {
|
||||
const stackTrace = new Error().stack;
|
||||
// assign type
|
||||
const node = app.graph.getNodeById(link_info.origin_id);
|
||||
let slot_type = node.outputs[link_info.origin_slot].type;
|
||||
|
||||
if(
|
||||
!stackTrace.includes('LGraphNode.prototype.connect') && // for touch device
|
||||
!stackTrace.includes('LGraphNode.connect') && // for mouse device
|
||||
!stackTrace.includes('loadGraphData')) {
|
||||
if(this.outputs[link_info.origin_slot].links.length == 0)
|
||||
this.removeOutput(link_info.origin_slot);
|
||||
}
|
||||
}
|
||||
this.inputs[0].type = slot_type;
|
||||
this.inputs[1].type = slot_type;
|
||||
}
|
||||
}
|
||||
|
||||
if(nodeData.name === 'ImpactInversedSwitch') {
|
||||
nodeData.output = ['*'];
|
||||
nodeData.output_is_list = [false];
|
||||
nodeData.output_name = ['output1'];
|
||||
|
||||
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
|
||||
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
|
||||
if(!link_info)
|
||||
return;
|
||||
|
||||
if(type == 2) {
|
||||
// connect output
|
||||
if(connected){
|
||||
if(app.graph._nodes_by_id[link_info.target_id].type == 'Reroute') {
|
||||
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
|
||||
}
|
||||
|
||||
if(this.outputs[0].type == '*'){
|
||||
if(link_info.type == '*') {
|
||||
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
|
||||
}
|
||||
else {
|
||||
// propagate type
|
||||
this.outputs[0].type = link_info.type;
|
||||
this.outputs[0].name = link_info.type;
|
||||
|
||||
for(let i in this.inputs) {
|
||||
if(this.inputs[i].name != 'select')
|
||||
this.inputs[i].type = link_info.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(app.graph._nodes_by_id[link_info.origin_id].type == 'Reroute')
|
||||
this.disconnectInput(link_info.target_slot);
|
||||
|
||||
// connect input
|
||||
if(this.inputs[0].type == '*'){
|
||||
const node = app.graph.getNodeById(link_info.origin_id);
|
||||
let origin_type = node.outputs[link_info.origin_slot].type;
|
||||
|
||||
if(origin_type == '*') {
|
||||
this.disconnectInput(link_info.target_slot);
|
||||
return;
|
||||
}
|
||||
|
||||
for(let i in this.inputs) {
|
||||
if(this.inputs[i].name != 'select')
|
||||
this.inputs[i].type = origin_type;
|
||||
}
|
||||
|
||||
this.outputs[0].type = origin_type;
|
||||
this.outputs[0].name = origin_type;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!connected && this.outputs.length > 1) {
|
||||
const stackTrace = new Error().stack;
|
||||
|
||||
if(
|
||||
!stackTrace.includes('LGraphNode.prototype.connect') && // for touch device
|
||||
!stackTrace.includes('LGraphNode.connect') && // for mouse device
|
||||
!stackTrace.includes('loadGraphData')) {
|
||||
if(this.outputs[link_info.origin_slot].links.length == 0)
|
||||
this.removeOutput(link_info.origin_slot);
|
||||
}
|
||||
}
|
||||
|
||||
let slot_i = 1;
|
||||
for (let i = 0; i < this.outputs.length; i++) {
|
||||
this.outputs[i].name = `output${slot_i}`
|
||||
slot_i++;
|
||||
}
|
||||
for (let i = 0; i < this.outputs.length; i++) {
|
||||
this.outputs[i].name = `output${slot_i}`
|
||||
slot_i++;
|
||||
}
|
||||
|
||||
let last_slot = this.outputs[this.outputs.length - 1];
|
||||
if (last_slot.slot_index == link_info.origin_slot) {
|
||||
this.addOutput(`output${slot_i}`, this.outputs[0].type);
|
||||
}
|
||||
if (last_slot.slot_index == link_info.origin_slot) {
|
||||
this.addOutput(`output${slot_i}`, this.outputs[0].type);
|
||||
}
|
||||
|
||||
let select_slot = this.inputs.find(x => x.name == "select");
|
||||
if(this.widgets) {
|
||||
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)
|
||||
this.widgets[0].value = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
let select_slot = this.inputs.find(x => x.name == "select");
|
||||
if(this.widgets) {
|
||||
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)
|
||||
this.widgets[0].value = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nodeData.name === 'ImpactMakeImageList' || nodeData.name === 'ImpactMakeImageBatch' ||
|
||||
nodeData.name === 'CombineRegionalPrompts' || nodeData.name === 'ImpactCombineConditionings' ||
|
||||
nodeData.name === 'ImpactSEGSConcat' ||
|
||||
nodeData.name === 'ImpactSwitch' || nodeData.name === 'LatentSwitch' || nodeData.name == 'SEGSSwitch') {
|
||||
var input_name = "input";
|
||||
if (nodeData.name === 'ImpactMakeImageList' || nodeData.name === 'ImpactMakeImageBatch' ||
|
||||
nodeData.name === 'CombineRegionalPrompts' ||
|
||||
nodeData.name === 'ImpactCombineConditionings' || nodeData.name === 'ImpactConcatConditionings' ||
|
||||
nodeData.name === 'ImpactSEGSConcat' ||
|
||||
nodeData.name === 'ImpactSwitch' || nodeData.name === 'LatentSwitch' || nodeData.name == 'SEGSSwitch') {
|
||||
var input_name = "input";
|
||||
|
||||
switch(nodeData.name) {
|
||||
case 'ImpactMakeImageList':
|
||||
case 'ImpactMakeImageBatch':
|
||||
input_name = "image";
|
||||
break;
|
||||
switch(nodeData.name) {
|
||||
case 'ImpactMakeImageList':
|
||||
case 'ImpactMakeImageBatch':
|
||||
input_name = "image";
|
||||
break;
|
||||
|
||||
case 'ImpactSEGSConcat':
|
||||
input_name = "segs";
|
||||
break;
|
||||
case 'ImpactSEGSConcat':
|
||||
input_name = "segs";
|
||||
break;
|
||||
|
||||
case 'CombineRegionalPrompts':
|
||||
input_name = "regional_prompts";
|
||||
break;
|
||||
case 'CombineRegionalPrompts':
|
||||
input_name = "regional_prompts";
|
||||
break;
|
||||
|
||||
case 'ImpactCombineConditionings':
|
||||
input_name = "conditioning";
|
||||
break;
|
||||
case 'ImpactCombineConditionings':
|
||||
case 'ImpactConcatConditionings':
|
||||
input_name = "conditioning";
|
||||
break;
|
||||
|
||||
case 'LatentSwitch':
|
||||
input_name = "input";
|
||||
break;
|
||||
case 'LatentSwitch':
|
||||
input_name = "input";
|
||||
break;
|
||||
|
||||
case 'SEGSSwitch':
|
||||
input_name = "input";
|
||||
break;
|
||||
case 'SEGSSwitch':
|
||||
input_name = "input";
|
||||
break;
|
||||
|
||||
case 'ImpactSwitch':
|
||||
input_name = "input";
|
||||
}
|
||||
case 'ImpactSwitch':
|
||||
input_name = "input";
|
||||
}
|
||||
|
||||
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
|
||||
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
|
||||
if(!link_info)
|
||||
return;
|
||||
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
|
||||
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
|
||||
if(!link_info)
|
||||
return;
|
||||
|
||||
if(type == 2) {
|
||||
// connect output
|
||||
if(connected && index == 0){
|
||||
if(nodeData.name == 'ImpactSwitch' && app.graph._nodes_by_id[link_info.target_id]?.type == 'Reroute') {
|
||||
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
|
||||
}
|
||||
if(type == 2) {
|
||||
// connect output
|
||||
if(connected && index == 0){
|
||||
if(nodeData.name == 'ImpactSwitch' && app.graph._nodes_by_id[link_info.target_id]?.type == 'Reroute') {
|
||||
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
|
||||
}
|
||||
|
||||
if(this.outputs[0].type == '*'){
|
||||
if(link_info.type == '*') {
|
||||
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
|
||||
}
|
||||
else {
|
||||
// propagate type
|
||||
this.outputs[0].type = link_info.type;
|
||||
this.outputs[0].label = link_info.type;
|
||||
this.outputs[0].name = link_info.type;
|
||||
if(this.outputs[0].type == '*'){
|
||||
if(link_info.type == '*') {
|
||||
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
|
||||
}
|
||||
else {
|
||||
// propagate type
|
||||
this.outputs[0].type = link_info.type;
|
||||
this.outputs[0].label = link_info.type;
|
||||
this.outputs[0].name = link_info.type;
|
||||
|
||||
for(let i in this.inputs) {
|
||||
let input_i = this.inputs[i];
|
||||
if(input_i.name != 'select' && input_i.name != 'sel_mode')
|
||||
input_i.type = link_info.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(let i in this.inputs) {
|
||||
let input_i = this.inputs[i];
|
||||
if(input_i.name != 'select' && input_i.name != 'sel_mode')
|
||||
input_i.type = link_info.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if(nodeData.name == 'ImpactSwitch' && app.graph._nodes_by_id[link_info.origin_id].type == 'Reroute')
|
||||
this.disconnectInput(link_info.target_slot);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if(nodeData.name == 'ImpactSwitch' && app.graph._nodes_by_id[link_info.origin_id].type == 'Reroute')
|
||||
this.disconnectInput(link_info.target_slot);
|
||||
|
||||
// connect input
|
||||
if(this.inputs[index].name == 'select' || this.inputs[index].name == 'sel_mode')
|
||||
return;
|
||||
// connect input
|
||||
if(this.inputs[index].name == 'select' || this.inputs[index].name == 'sel_mode')
|
||||
return;
|
||||
|
||||
if(this.inputs[0].type == '*'){
|
||||
const node = app.graph.getNodeById(link_info.origin_id);
|
||||
let origin_type = node.outputs[link_info.origin_slot].type;
|
||||
if(this.inputs[0].type == '*'){
|
||||
const node = app.graph.getNodeById(link_info.origin_id);
|
||||
let origin_type = node.outputs[link_info.origin_slot].type;
|
||||
|
||||
if(origin_type == '*') {
|
||||
this.disconnectInput(link_info.target_slot);
|
||||
return;
|
||||
}
|
||||
if(origin_type == '*') {
|
||||
this.disconnectInput(link_info.target_slot);
|
||||
return;
|
||||
}
|
||||
|
||||
for(let i in this.inputs) {
|
||||
let input_i = this.inputs[i];
|
||||
if(input_i.name != 'select' && input_i.name != 'sel_mode')
|
||||
input_i.type = origin_type;
|
||||
}
|
||||
for(let i in this.inputs) {
|
||||
let input_i = this.inputs[i];
|
||||
if(input_i.name != 'select' && input_i.name != 'sel_mode')
|
||||
input_i.type = origin_type;
|
||||
}
|
||||
|
||||
this.outputs[0].type = origin_type;
|
||||
this.outputs[0].label = origin_type;
|
||||
this.outputs[0].name = origin_type;
|
||||
}
|
||||
}
|
||||
this.outputs[0].type = origin_type;
|
||||
this.outputs[0].label = origin_type;
|
||||
this.outputs[0].name = origin_type;
|
||||
}
|
||||
}
|
||||
|
||||
let select_slot = this.inputs.find(x => x.name == "select");
|
||||
let mode_slot = this.inputs.find(x => x.name == "sel_mode");
|
||||
let select_slot = this.inputs.find(x => x.name == "select");
|
||||
let mode_slot = this.inputs.find(x => x.name == "sel_mode");
|
||||
|
||||
let converted_count = 0;
|
||||
converted_count += select_slot?1:0;
|
||||
converted_count += mode_slot?1:0;
|
||||
let converted_count = 0;
|
||||
converted_count += select_slot?1:0;
|
||||
converted_count += mode_slot?1:0;
|
||||
|
||||
if (!connected && (this.inputs.length > 1+converted_count)) {
|
||||
const stackTrace = new Error().stack;
|
||||
if (!connected && (this.inputs.length > 1+converted_count)) {
|
||||
const stackTrace = new Error().stack;
|
||||
|
||||
if(
|
||||
!stackTrace.includes('LGraphNode.prototype.connect') && // for touch device
|
||||
!stackTrace.includes('LGraphNode.connect') && // for mouse device
|
||||
!stackTrace.includes('loadGraphData') &&
|
||||
this.inputs[index].name != 'select') {
|
||||
this.removeInput(index);
|
||||
}
|
||||
}
|
||||
if(
|
||||
!stackTrace.includes('LGraphNode.prototype.connect') && // for touch device
|
||||
!stackTrace.includes('LGraphNode.connect') && // for mouse device
|
||||
!stackTrace.includes('loadGraphData') &&
|
||||
this.inputs[index].name != 'select') {
|
||||
this.removeInput(index);
|
||||
}
|
||||
}
|
||||
|
||||
let slot_i = 1;
|
||||
for (let i = 0; i < this.inputs.length; i++) {
|
||||
let input_i = this.inputs[i];
|
||||
if(input_i.name != 'select'&& input_i.name != 'sel_mode') {
|
||||
input_i.name = `${input_name}${slot_i}`
|
||||
slot_i++;
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < this.inputs.length; i++) {
|
||||
let input_i = this.inputs[i];
|
||||
if(input_i.name != 'select'&& input_i.name != 'sel_mode') {
|
||||
input_i.name = `${input_name}${slot_i}`
|
||||
slot_i++;
|
||||
}
|
||||
}
|
||||
|
||||
let last_slot = this.inputs[this.inputs.length - 1];
|
||||
if (
|
||||
(last_slot.name == 'select' && last_slot.name != 'sel_mode' && this.inputs[this.inputs.length - 2].link != undefined)
|
||||
|| (last_slot.name != 'select' && last_slot.name != 'sel_mode' && last_slot.link != undefined)) {
|
||||
this.addInput(`${input_name}${slot_i}`, this.outputs[0].type);
|
||||
}
|
||||
if (
|
||||
(last_slot.name == 'select' && last_slot.name != 'sel_mode' && this.inputs[this.inputs.length - 2].link != undefined)
|
||||
|| (last_slot.name != 'select' && last_slot.name != 'sel_mode' && last_slot.link != undefined)) {
|
||||
this.addInput(`${input_name}${slot_i}`, this.outputs[0].type);
|
||||
}
|
||||
|
||||
if(this.widgets) {
|
||||
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)
|
||||
this.widgets[0].value = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.widgets) {
|
||||
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)
|
||||
this.widgets[0].value = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
nodeCreated(node, app) {
|
||||
@@ -456,105 +527,132 @@ app.registerExtension({
|
||||
}
|
||||
|
||||
switch(node.comfyClass) {
|
||||
case "ToDetailerPipe":
|
||||
case "ToDetailerPipeSDXL":
|
||||
case "BasicPipeToDetailerPipe":
|
||||
case "BasicPipeToDetailerPipeSDXL":
|
||||
case "EditDetailerPipe":
|
||||
case "FaceDetailer":
|
||||
case "DetailerForEach":
|
||||
case "DetailerForEachDebug":
|
||||
case "DetailerForEachPipe":
|
||||
case "DetailerForEachDebugPipe":
|
||||
{
|
||||
for(let i in node.widgets) {
|
||||
let widget = node.widgets[i];
|
||||
if(widget.type === "customtext") {
|
||||
widget.dynamicPrompts = false;
|
||||
widget.inputEl.placeholder = "wildcard spec: if kept empty, this option will be ignored";
|
||||
widget.serializeValue = () => {
|
||||
return node.widgets[i].value;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "ToDetailerPipe":
|
||||
case "ToDetailerPipeSDXL":
|
||||
case "BasicPipeToDetailerPipe":
|
||||
case "BasicPipeToDetailerPipeSDXL":
|
||||
case "EditDetailerPipe":
|
||||
case "FaceDetailer":
|
||||
case "DetailerForEach":
|
||||
case "DetailerForEachDebug":
|
||||
case "DetailerForEachPipe":
|
||||
case "DetailerForEachDebugPipe":
|
||||
{
|
||||
for(let i in node.widgets) {
|
||||
let widget = node.widgets[i];
|
||||
if(widget.type === "customtext") {
|
||||
widget.dynamicPrompts = false;
|
||||
widget.inputEl.placeholder = "wildcard spec: if kept empty, this option will be ignored";
|
||||
widget.serializeValue = () => {
|
||||
return node.widgets[i].value;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(node.comfyClass == "ImpactSEGSLabelFilter") {
|
||||
if(node.comfyClass == "ImpactSEGSLabelFilter" || node.comfyClass == "SEGSLabelFilterDetailerHookProvider") {
|
||||
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 += ", "
|
||||
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.widgets[1].value += value;
|
||||
node.widgets_values[1] = node.widgets[1].value;
|
||||
}
|
||||
|
||||
node._value = value;
|
||||
},
|
||||
get: () => {
|
||||
return node._value;
|
||||
return node._value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(node.comfyClass == "UltralyticsDetectorProvider") {
|
||||
let model_name_widget = node.widgets.find((w) => w.name === "model_name");
|
||||
let orig_draw = node.onDrawForeground;
|
||||
node.onDrawForeground = function (ctx) {
|
||||
const r = orig_draw?.apply?.(this, arguments);
|
||||
|
||||
let is_seg = model_name_widget.value.startsWith('segm/') || model_name_widget.value.includes('-seg');
|
||||
if(!is_seg) {
|
||||
var slot_pos = new Float32Array(2);
|
||||
var pos = node.getConnectionPos(false, 1, slot_pos);
|
||||
|
||||
pos[0] -= node.pos[0] - 10;
|
||||
pos[1] -= node.pos[1];
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = "red";
|
||||
ctx.lineWidth = 4;
|
||||
ctx.moveTo(pos[0] - 5, pos[1] - 5);
|
||||
ctx.lineTo(pos[0] + 5, pos[1] + 5);
|
||||
ctx.moveTo(pos[0] + 5, pos[1] - 5);
|
||||
ctx.lineTo(pos[0] - 5, pos[1] + 5);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(
|
||||
node.comfyClass == "ImpactWildcardEncode" || node.comfyClass == "ImpactWildcardProcessor"
|
||||
|| node.comfyClass == "ToDetailerPipe" || node.comfyClass == "ToDetailerPipeSDXL"
|
||||
|| node.comfyClass == "EditDetailerPipe" || node.comfyClass == "BasicPipeToDetailerPipe" || node.comfyClass == "BasicPipeToDetailerPipeSDXL") {
|
||||
|| node.comfyClass == "EditDetailerPipe" || node.comfyClass == "EditDetailerPipeSDXL"
|
||||
|| node.comfyClass == "BasicPipeToDetailerPipe" || node.comfyClass == "BasicPipeToDetailerPipeSDXL") {
|
||||
node._value = "Select the LoRA to add to the text";
|
||||
node._wvalue = "Select the Wildcard to add to the text";
|
||||
|
||||
var tbox_id = 0;
|
||||
var combo_id = 3;
|
||||
var has_lora = true;
|
||||
var tbox_id = 0;
|
||||
var combo_id = 3;
|
||||
var has_lora = true;
|
||||
|
||||
switch(node.comfyClass){
|
||||
case "ImpactWildcardEncode":
|
||||
tbox_id = 0;
|
||||
combo_id = 3;
|
||||
break;
|
||||
switch(node.comfyClass){
|
||||
case "ImpactWildcardEncode":
|
||||
tbox_id = 0;
|
||||
combo_id = 3;
|
||||
break;
|
||||
|
||||
case "ImpactWildcardProcessor":
|
||||
tbox_id = 0;
|
||||
combo_id = 4;
|
||||
has_lora = false;
|
||||
break;
|
||||
case "ImpactWildcardProcessor":
|
||||
tbox_id = 0;
|
||||
combo_id = 4;
|
||||
has_lora = false;
|
||||
break;
|
||||
|
||||
case "ToDetailerPipe":
|
||||
case "ToDetailerPipeSDXL":
|
||||
case "EditDetailerPipe":
|
||||
case "EditDetailerPipeSDXL":
|
||||
case "BasicPipeToDetailerPipe":
|
||||
case "BasicPipeToDetailerPipeSDXL":
|
||||
tbox_id = 0;
|
||||
combo_id = 1;
|
||||
break;
|
||||
}
|
||||
case "ToDetailerPipe":
|
||||
case "ToDetailerPipeSDXL":
|
||||
case "EditDetailerPipe":
|
||||
case "EditDetailerPipeSDXL":
|
||||
case "BasicPipeToDetailerPipe":
|
||||
case "BasicPipeToDetailerPipeSDXL":
|
||||
tbox_id = 0;
|
||||
combo_id = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
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 += ', '
|
||||
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;
|
||||
}
|
||||
}
|
||||
node.widgets[tbox_id].value += value;
|
||||
}
|
||||
}
|
||||
},
|
||||
get: () => { return "Select the Wildcard to add to the text"; }
|
||||
});
|
||||
|
||||
Object.defineProperty(node.widgets[combo_id+1].options, "values", {
|
||||
set: (x) => {},
|
||||
get: () => {
|
||||
return wildcards_list;
|
||||
}
|
||||
set: (x) => {},
|
||||
get: () => {
|
||||
return wildcards_list;
|
||||
}
|
||||
});
|
||||
|
||||
if(has_lora) {
|
||||
@@ -577,9 +675,8 @@ app.registerExtension({
|
||||
|
||||
node._value = value;
|
||||
},
|
||||
get: () => {
|
||||
return node._value;
|
||||
}
|
||||
|
||||
get: () => { return "Select the LoRA to add to the text"; }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -594,42 +691,9 @@ app.registerExtension({
|
||||
node.widgets[0].inputEl.placeholder = "Wildcard Prompt (User input)";
|
||||
node.widgets[1].inputEl.placeholder = "Populated Prompt (Will be generated automatically)";
|
||||
node.widgets[1].inputEl.disabled = true;
|
||||
node.widgets[0].dynamicPrompts = false;
|
||||
node.widgets[1].dynamicPrompts = false;
|
||||
|
||||
let populate_getter = node.widgets[1].__lookupGetter__('value');
|
||||
let populate_setter = node.widgets[1].__lookupSetter__('value');
|
||||
|
||||
const wildcard_text_widget = node.widgets.find((w) => w.name == 'wildcard_text');
|
||||
const populated_text_widget = node.widgets.find((w) => w.name == 'populated_text');
|
||||
const mode_widget = node.widgets.find((w) => w.name == 'mode');
|
||||
const seed_widget = node.widgets.find((w) => w.name == 'seed');
|
||||
|
||||
let force_serializeValue = async (n,i) =>
|
||||
{
|
||||
if(!mode_widget.value) {
|
||||
return populated_text_widget.value;
|
||||
}
|
||||
else {
|
||||
let wildcard_text = await wildcard_text_widget.serializeValue();
|
||||
|
||||
let response = await api.fetchApi(`/impact/wildcards`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({text: wildcard_text, seed: seed_widget.value})
|
||||
});
|
||||
|
||||
let populated = await response.json();
|
||||
|
||||
if(n.widgets_values) {
|
||||
n.widgets_values[2] = false;
|
||||
n.widgets_values[1] = populated.text;
|
||||
}
|
||||
populate_setter.call(populated_text_widget, populated.text);
|
||||
|
||||
return populated.text;
|
||||
}
|
||||
};
|
||||
|
||||
// mode combo
|
||||
Object.defineProperty(mode_widget, "value", {
|
||||
@@ -644,39 +708,6 @@ app.registerExtension({
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// to avoid conflict with presetText.js of pythongosssss
|
||||
Object.defineProperty(populated_text_widget, "value", {
|
||||
set: (value) => {
|
||||
const stackTrace = new Error().stack;
|
||||
if(!stackTrace.includes('serializeValue'))
|
||||
populate_setter.call(populated_text_widget, value);
|
||||
},
|
||||
get: () => {
|
||||
return populate_getter.call(populated_text_widget);
|
||||
}
|
||||
});
|
||||
|
||||
wildcard_text_widget.serializeValue = (n,i) => {
|
||||
if(node.inputs) {
|
||||
let link_id = node.inputs.find(x => x.name=="wildcard_text")?.link;
|
||||
if(link_id != undefined) {
|
||||
let link = app.graph.links[link_id];
|
||||
let input_widget = app.graph._nodes_by_id[link.origin_id].widgets[link.origin_slot];
|
||||
if(input_widget.type == "customtext") {
|
||||
return input_widget.value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return wildcard_text_widget.value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return wildcard_text_widget.value;
|
||||
}
|
||||
};
|
||||
|
||||
populated_text_widget.serializeValue = force_serializeValue;
|
||||
}
|
||||
|
||||
if (node.comfyClass == "MaskPainter") {
|
||||
|
||||
@@ -617,7 +617,7 @@ app.registerExtension({
|
||||
},
|
||||
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.output.includes("MASK") && nodeData.output.includes("IMAGE")) {
|
||||
if (Array.isArray(nodeData.output) && (nodeData.output.includes("MASK") || nodeData.output.includes("IMAGE"))) {
|
||||
addMenuHandler(nodeType, function (_, options) {
|
||||
options.unshift({
|
||||
content: "Open in SAM Detector",
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
from nodes import MAX_RESOLUTION
|
||||
from impact.utils import *
|
||||
import impact.core as core
|
||||
from impact.core import SEG
|
||||
from impact.segs_nodes import SEGSPaste
|
||||
|
||||
|
||||
class SEGSDetailerForAnimateDiff:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"image_frames": ("IMAGE", ),
|
||||
"segs": ("SEGS", ),
|
||||
"guide_size": ("FLOAT", {"default": 256, "min": 64, "max": MAX_RESOLUTION, "step": 8}),
|
||||
"guide_size_for": ("BOOLEAN", {"default": True, "label_on": "bbox", "label_off": "crop_region"}),
|
||||
"max_size": ("FLOAT", {"default": 768, "min": 64, "max": MAX_RESOLUTION, "step": 8}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
|
||||
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
|
||||
"basic_pipe": ("BASIC_PIPE",),
|
||||
"refiner_ratio": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0})
|
||||
},
|
||||
"optional": {
|
||||
"refiner_basic_pipe_opt": ("BASIC_PIPE",),
|
||||
# TODO: "inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
# TODO: "noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("SEGS", "IMAGE")
|
||||
RETURN_NAMES = ("segs", "cnet_images")
|
||||
OUTPUT_IS_LIST = (False, True)
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Detailer"
|
||||
|
||||
@staticmethod
|
||||
def do_detail(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, basic_pipe, refiner_ratio=None, refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
model, clip, vae, positive, negative = basic_pipe
|
||||
if refiner_basic_pipe_opt is None:
|
||||
refiner_model, refiner_clip, refiner_positive, refiner_negative = None, None, None, None
|
||||
else:
|
||||
refiner_model, refiner_clip, _, refiner_positive, refiner_negative = refiner_basic_pipe_opt
|
||||
|
||||
segs = core.segs_scale_match(segs, image_frames.shape)
|
||||
|
||||
new_segs = []
|
||||
cnet_image_list = []
|
||||
|
||||
for seg in segs[1]:
|
||||
cropped_image_frames = None
|
||||
|
||||
for image in image_frames:
|
||||
image = image.unsqueeze(0)
|
||||
cropped_image = seg.cropped_image if seg.cropped_image is not None else crop_tensor4(image, seg.crop_region)
|
||||
cropped_image = to_tensor(cropped_image)
|
||||
if cropped_image_frames is None:
|
||||
cropped_image_frames = cropped_image
|
||||
else:
|
||||
cropped_image_frames = torch.concat((cropped_image_frames, cropped_image), dim=0)
|
||||
|
||||
cropped_image_frames = cropped_image_frames.numpy()
|
||||
enhanced_image_tensor, cnet_images = core.enhance_detail_for_animatediff(cropped_image_frames, model, clip, vae, guide_size, guide_size_for, max_size,
|
||||
seg.bbox, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, denoise, seg.cropped_mask,
|
||||
refiner_ratio=refiner_ratio, refiner_model=refiner_model,
|
||||
refiner_clip=refiner_clip, refiner_positive=refiner_positive,
|
||||
refiner_negative=refiner_negative, control_net_wrapper=seg.control_net_wrapper,
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
if cnet_images is not None:
|
||||
cnet_image_list.extend(cnet_images)
|
||||
|
||||
if enhanced_image_tensor is None:
|
||||
new_cropped_image = cropped_image_frames
|
||||
else:
|
||||
new_cropped_image = enhanced_image_tensor.numpy()
|
||||
|
||||
new_seg = SEG(new_cropped_image, seg.cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, None)
|
||||
new_segs.append(new_seg)
|
||||
|
||||
return (segs[0], new_segs), cnet_image_list
|
||||
|
||||
def doit(self, image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, basic_pipe, refiner_ratio=None, refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
segs, cnet_images = SEGSDetailerForAnimateDiff.do_detail(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name,
|
||||
scheduler, denoise, basic_pipe, refiner_ratio, refiner_basic_pipe_opt,
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
if len(cnet_images) == 0:
|
||||
cnet_images = [empty_pil_tensor()]
|
||||
|
||||
return (segs, cnet_images)
|
||||
|
||||
|
||||
class DetailerForEachPipeForAnimateDiff:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"image_frames": ("IMAGE", ),
|
||||
"segs": ("SEGS", ),
|
||||
"guide_size": ("FLOAT", {"default": 384, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"guide_size_for": ("BOOLEAN", {"default": True, "label_on": "bbox", "label_off": "crop_region"}),
|
||||
"max_size": ("FLOAT", {"default": 1024, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
|
||||
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
|
||||
"feather": ("INT", {"default": 5, "min": 0, "max": 100, "step": 1}),
|
||||
"basic_pipe": ("BASIC_PIPE", ),
|
||||
"refiner_ratio": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0}),
|
||||
},
|
||||
"optional": {
|
||||
"detailer_hook": ("DETAILER_HOOK",),
|
||||
"refiner_basic_pipe_opt": ("BASIC_PIPE",),
|
||||
# "inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
# "noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "SEGS", "BASIC_PIPE", "IMAGE")
|
||||
RETURN_NAMES = ("image", "segs", "basic_pipe", "cnet_images")
|
||||
OUTPUT_IS_LIST = (False, False, False, True)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Detailer"
|
||||
|
||||
@staticmethod
|
||||
def doit(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, feather, basic_pipe, refiner_ratio=None, detailer_hook=None, refiner_basic_pipe_opt=None,
|
||||
inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
enhanced_segs = []
|
||||
cnet_image_list = []
|
||||
|
||||
for sub_seg in segs[1]:
|
||||
single_seg = segs[0], [sub_seg]
|
||||
enhanced_seg, cnet_images = SEGSDetailerForAnimateDiff().do_detail(image_frames, single_seg, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, basic_pipe, refiner_ratio, refiner_basic_pipe_opt, inpaint_model, noise_mask_feather)
|
||||
|
||||
image_frames = SEGSPaste.doit(image_frames, enhanced_seg, feather, alpha=255)[0]
|
||||
|
||||
if cnet_images is not None:
|
||||
cnet_image_list.extend(cnet_images)
|
||||
|
||||
if detailer_hook is not None:
|
||||
detailer_hook.post_paste(image_frames)
|
||||
|
||||
enhanced_segs += enhanced_seg[1]
|
||||
|
||||
new_segs = segs[0], enhanced_segs
|
||||
return image_frames, new_segs, basic_pipe, cnet_image_list
|
||||
@@ -0,0 +1,258 @@
|
||||
import os
|
||||
from PIL import ImageOps
|
||||
from impact.utils import *
|
||||
|
||||
from . import core
|
||||
import random
|
||||
|
||||
class PreviewBridge:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"images": ("IMAGE",),
|
||||
"image": ("STRING", {"default": ""}),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "MASK", )
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
OUTPUT_NODE = True
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.output_dir = folder_paths.get_temp_directory()
|
||||
self.type = "temp"
|
||||
self.prev_hash = None
|
||||
|
||||
@staticmethod
|
||||
def load_image(pb_id):
|
||||
is_fail = False
|
||||
if pb_id not in core.preview_bridge_image_id_map:
|
||||
is_fail = True
|
||||
|
||||
image_path, ui_item = core.preview_bridge_image_id_map[pb_id]
|
||||
|
||||
if not os.path.isfile(image_path):
|
||||
is_fail = True
|
||||
|
||||
if not is_fail:
|
||||
i = Image.open(image_path)
|
||||
i = ImageOps.exif_transpose(i)
|
||||
image = i.convert("RGB")
|
||||
image = np.array(image).astype(np.float32) / 255.0
|
||||
image = torch.from_numpy(image)[None,]
|
||||
|
||||
if 'A' in i.getbands():
|
||||
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
|
||||
mask = 1. - torch.from_numpy(mask)
|
||||
else:
|
||||
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
|
||||
else:
|
||||
image = empty_pil_tensor()
|
||||
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
|
||||
ui_item = {
|
||||
"filename": 'empty.png',
|
||||
"subfolder": '',
|
||||
"type": 'temp'
|
||||
}
|
||||
|
||||
return image, mask.unsqueeze(0), ui_item
|
||||
|
||||
def doit(self, images, image, unique_id):
|
||||
need_refresh = False
|
||||
|
||||
if unique_id not in core.preview_bridge_cache:
|
||||
need_refresh = True
|
||||
|
||||
elif core.preview_bridge_cache[unique_id][0] is not images:
|
||||
need_refresh = True
|
||||
|
||||
if not need_refresh:
|
||||
pixels, mask, path_item = PreviewBridge.load_image(image)
|
||||
image = [path_item]
|
||||
else:
|
||||
res = nodes.PreviewImage().save_images(images, filename_prefix="PreviewBridge/PB-")
|
||||
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])
|
||||
core.preview_bridge_image_id_map[image] = (path, image2[0])
|
||||
core.preview_bridge_image_name_map[unique_id, path] = (image, image2[0])
|
||||
core.preview_bridge_cache[unique_id] = (images, image2)
|
||||
|
||||
image = image2
|
||||
|
||||
return {
|
||||
"ui": {"images": image},
|
||||
"result": (pixels, mask, ),
|
||||
}
|
||||
|
||||
|
||||
def decode_latent(latent_tensor, preview_method, vae_opt=None):
|
||||
if vae_opt is not None:
|
||||
image = nodes.VAEDecode().decode(vae_opt, latent_tensor)[0]
|
||||
return image
|
||||
|
||||
from comfy.cli_args import LatentPreviewMethod
|
||||
import comfy.latent_formats as latent_formats
|
||||
|
||||
if preview_method.startswith("TAE"):
|
||||
if preview_method == "TAESD15":
|
||||
decoder_name = "taesd"
|
||||
else:
|
||||
decoder_name = "taesdxl"
|
||||
|
||||
vae = nodes.VAELoader().load_vae(decoder_name)[0]
|
||||
image = nodes.VAEDecode().decode(vae, latent_tensor)[0]
|
||||
return image
|
||||
|
||||
else:
|
||||
if preview_method == "Latent2RGB-SD15":
|
||||
latent_format = latent_formats.SD15()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
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)
|
||||
pil_image = previewer.decode_latent_to_preview(latent_tensor['samples'])
|
||||
pixels_size = pil_image.size[0]*8, pil_image.size[1]*8
|
||||
resized_image = pil_image.resize(pixels_size, Image.NONE)
|
||||
|
||||
return to_tensor(resized_image).unsqueeze(0)
|
||||
|
||||
|
||||
class PreviewBridgeLatent:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"latent": ("LATENT",),
|
||||
"image": ("STRING", {"default": ""}),
|
||||
"preview_method": (["Latent2RGB-SDXL", "Latent2RGB-SD15", "TAESDXL", "TAESD15"],),
|
||||
},
|
||||
"optional": {
|
||||
"vae_opt": ("VAE", )
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("LATENT", "MASK", )
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
OUTPUT_NODE = True
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.output_dir = folder_paths.get_temp_directory()
|
||||
self.type = "temp"
|
||||
self.prev_hash = None
|
||||
self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5))
|
||||
|
||||
@staticmethod
|
||||
def load_image(pb_id):
|
||||
is_fail = False
|
||||
if pb_id not in core.preview_bridge_image_id_map:
|
||||
is_fail = True
|
||||
|
||||
image_path, ui_item = core.preview_bridge_image_id_map[pb_id]
|
||||
|
||||
if not os.path.isfile(image_path):
|
||||
is_fail = True
|
||||
|
||||
if not is_fail:
|
||||
i = Image.open(image_path)
|
||||
i = ImageOps.exif_transpose(i)
|
||||
image = i.convert("RGB")
|
||||
image = np.array(image).astype(np.float32) / 255.0
|
||||
image = torch.from_numpy(image)[None,]
|
||||
|
||||
if 'A' in i.getbands():
|
||||
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
|
||||
mask = 1. - torch.from_numpy(mask)
|
||||
else:
|
||||
mask = None
|
||||
else:
|
||||
image = empty_pil_tensor()
|
||||
mask = None
|
||||
ui_item = {
|
||||
"filename": 'empty.png',
|
||||
"subfolder": '',
|
||||
"type": 'temp'
|
||||
}
|
||||
|
||||
return image, mask, ui_item
|
||||
|
||||
def doit(self, latent, image, preview_method, vae_opt=None, unique_id=None):
|
||||
need_refresh = False
|
||||
|
||||
if unique_id not in core.preview_bridge_cache:
|
||||
need_refresh = True
|
||||
|
||||
elif (core.preview_bridge_cache[unique_id][0] is not latent
|
||||
or (vae_opt is None and core.preview_bridge_cache[unique_id][2] is not None)
|
||||
or (vae_opt is None and core.preview_bridge_cache[unique_id][1] != preview_method)
|
||||
or (vae_opt is not None and core.preview_bridge_cache[unique_id][2] is not vae_opt)):
|
||||
need_refresh = True
|
||||
|
||||
if not need_refresh:
|
||||
pixels, mask, path_item = PreviewBridge.load_image(image)
|
||||
|
||||
if mask is None:
|
||||
mask = torch.ones(latent['samples'].shape[2:], dtype=torch.float32, device="cpu").unsqueeze(0)
|
||||
if 'noise_mask' in latent:
|
||||
res_latent = latent.copy()
|
||||
del res_latent['noise_mask']
|
||||
else:
|
||||
res_latent = latent
|
||||
else:
|
||||
res_latent = latent.copy()
|
||||
res_latent['noise_mask'] = mask
|
||||
|
||||
res_image = [path_item]
|
||||
else:
|
||||
decoded_image = decode_latent(latent, preview_method, vae_opt)
|
||||
|
||||
if 'noise_mask' in latent:
|
||||
mask = latent['noise_mask']
|
||||
|
||||
decoded_pil = to_pil(decoded_image)
|
||||
|
||||
inverted_mask = 1 - mask # invert
|
||||
resized_mask = resize_mask(inverted_mask, (decoded_image.shape[1], decoded_image.shape[2]))
|
||||
result_pil = apply_mask_alpha_to_pil(decoded_pil, resized_mask)
|
||||
|
||||
full_output_folder, filename, counter, _, _ = folder_paths.get_save_image_path("PreviewBridge/PBL-"+self.prefix_append, folder_paths.get_temp_directory(), result_pil.size[0], result_pil.size[1])
|
||||
file = f"{filename}_{counter}.png"
|
||||
result_pil.save(os.path.join(full_output_folder, file), compress_level=4)
|
||||
res_image = [{
|
||||
'filename': file,
|
||||
'subfolder': 'PreviewBridge',
|
||||
'type': 'temp',
|
||||
}]
|
||||
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-")
|
||||
res_image = res['ui']['images']
|
||||
|
||||
path = os.path.join(folder_paths.get_temp_directory(), 'PreviewBridge', res_image[0]['filename'])
|
||||
core.set_previewbridge_image(unique_id, path, res_image[0])
|
||||
core.preview_bridge_image_id_map[image] = (path, res_image[0])
|
||||
core.preview_bridge_image_name_map[unique_id, path] = (image, res_image[0])
|
||||
core.preview_bridge_cache[unique_id] = (latent, preview_method, vae_opt, res_image)
|
||||
|
||||
res_latent = latent
|
||||
|
||||
return {
|
||||
"ui": {"images": res_image},
|
||||
"result": (res_latent, mask, ),
|
||||
}
|
||||
@@ -2,9 +2,10 @@ import configparser
|
||||
import os
|
||||
|
||||
|
||||
version = "V4.38.2"
|
||||
version_code = [4, 74]
|
||||
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
|
||||
|
||||
dependency_version = 19
|
||||
dependency_version = 20
|
||||
|
||||
my_path = os.path.dirname(__file__)
|
||||
old_config_path = os.path.join(my_path, "impact-pack.ini")
|
||||
|
||||
+407
-464
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
detection_labels = [
|
||||
'hand', 'face', 'mouth', 'eyes', 'eyebrows', 'pupils',
|
||||
'left_eyebrow', 'left_eye', 'left_pupil', 'right_eyebrow', 'right_eye', 'right_pupil',
|
||||
'short_sleeved_shirt', 'long_sleeved_shirt', 'short_sleeved_outwear', 'long_sleeved_outwear',
|
||||
'vest', 'sling', 'shorts', 'trousers', 'skirt', 'short_sleeved_dress', 'long_sleeved_dress', 'vest_dress', 'sling_dress',
|
||||
"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat",
|
||||
"traffic light", "fire hydrant", "stop sign", "parking meter", "bench",
|
||||
"bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe",
|
||||
"backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard",
|
||||
"sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
|
||||
"tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl",
|
||||
"banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza",
|
||||
"donut", "cake", "chair", "couch", "potted plant", "bed", "dining table", "toilet",
|
||||
"tv", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven",
|
||||
"toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear",
|
||||
"hair drier", "toothbrush"
|
||||
]
|
||||
+163
-32
@@ -1,8 +1,10 @@
|
||||
import impact.core as core
|
||||
from impact.config import MAX_RESOLUTION
|
||||
import impact.segs_nodes as segs_nodes
|
||||
import numpy as np
|
||||
import impact.utils as utils
|
||||
import torch
|
||||
from impact.core import SEG
|
||||
|
||||
|
||||
class SAMDetectorCombined:
|
||||
@classmethod
|
||||
@@ -84,6 +86,9 @@ class BboxDetectorForEach:
|
||||
CATEGORY = "ImpactPack/Detector"
|
||||
|
||||
def doit(self, bbox_detector, image, threshold, dilation, crop_factor, drop_size, labels=None, detailer_hook=None):
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: BboxDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
|
||||
|
||||
segs = bbox_detector.detect(image, threshold, dilation, crop_factor, drop_size, detailer_hook)
|
||||
|
||||
if labels is not None and labels != '':
|
||||
@@ -115,6 +120,9 @@ class SegmDetectorForEach:
|
||||
CATEGORY = "ImpactPack/Detector"
|
||||
|
||||
def doit(self, segm_detector, image, threshold, dilation, crop_factor, drop_size, labels=None, detailer_hook=None):
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: SegmDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
|
||||
|
||||
segs = segm_detector.detect(image, threshold, dilation, crop_factor, drop_size, detailer_hook)
|
||||
|
||||
if labels is not None and labels != '':
|
||||
@@ -170,21 +178,22 @@ class SimpleDetectorForEach:
|
||||
"image": ("IMAGE", ),
|
||||
|
||||
"bbox_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"bbox_dilation": ("INT", {"default": 0, "min": -255, "max": 255, "step": 1}),
|
||||
"bbox_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
|
||||
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
|
||||
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
|
||||
|
||||
"sub_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"sub_dilation": ("INT", {"default": 0, "min": -255, "max": 255, "step": 1}),
|
||||
"sub_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
"sub_bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
|
||||
|
||||
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
},
|
||||
"optional": {
|
||||
"post_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
"sam_model_opt": ("SAM_MODEL", ),
|
||||
"segm_detector_opt": ("SEGM_DETECTOR", ),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("SEGS",)
|
||||
@@ -194,29 +203,35 @@ class SimpleDetectorForEach:
|
||||
|
||||
@staticmethod
|
||||
def detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion,
|
||||
sam_mask_hint_threshold, sam_model_opt=None, segm_detector_opt=None):
|
||||
segs = bbox_detector.detect(image, bbox_threshold, bbox_dilation, crop_factor, drop_size)
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion,
|
||||
sam_mask_hint_threshold, post_dilation=0, sam_model_opt=None, segm_detector_opt=None,
|
||||
detailer_hook=None):
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: SimpleDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
|
||||
|
||||
segs = bbox_detector.detect(image, bbox_threshold, bbox_dilation, crop_factor, drop_size, detailer_hook=detailer_hook)
|
||||
|
||||
if sam_model_opt is not None:
|
||||
mask = core.make_sam_mask(sam_model_opt, segs, image, "center-1", sub_dilation,
|
||||
sub_threshold, sub_bbox_expansion, sam_mask_hint_threshold, False)
|
||||
segs = core.segs_bitwise_and_mask(segs, mask)
|
||||
elif segm_detector_opt is not None:
|
||||
segm_segs = segm_detector_opt.detect(image, sub_threshold, sub_dilation, crop_factor, drop_size)
|
||||
segm_segs = segm_detector_opt.detect(image, sub_threshold, sub_dilation, crop_factor, drop_size, detailer_hook=detailer_hook)
|
||||
mask = core.segs_to_combined_mask(segm_segs)
|
||||
segs = core.segs_bitwise_and_mask(segs, mask)
|
||||
|
||||
return (segs,)
|
||||
segs = core.dilate_segs(segs, post_dilation)
|
||||
|
||||
return (segs,)
|
||||
|
||||
def doit(self, bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion,
|
||||
sam_mask_hint_threshold, sam_model_opt=None, segm_detector_opt=None):
|
||||
sam_mask_hint_threshold, post_dilation=0, sam_model_opt=None, segm_detector_opt=None):
|
||||
|
||||
return SimpleDetectorForEach.detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion,
|
||||
sam_mask_hint_threshold, sam_model_opt, segm_detector_opt)
|
||||
sam_mask_hint_threshold, post_dilation=post_dilation,
|
||||
sam_model_opt=sam_model_opt, segm_detector_opt=segm_detector_opt)
|
||||
|
||||
|
||||
class SimpleDetectorForEachPipe:
|
||||
@@ -227,17 +242,20 @@ class SimpleDetectorForEachPipe:
|
||||
"image": ("IMAGE", ),
|
||||
|
||||
"bbox_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"bbox_dilation": ("INT", {"default": 0, "min": 0, "max": 255, "step": 1}),
|
||||
"bbox_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
|
||||
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
|
||||
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
|
||||
|
||||
"sub_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"sub_dilation": ("INT", {"default": 0, "min": 0, "max": 255, "step": 1}),
|
||||
"sub_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
"sub_bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
|
||||
|
||||
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
},
|
||||
"optional": {
|
||||
"post_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("SEGS",)
|
||||
@@ -246,13 +264,17 @@ class SimpleDetectorForEachPipe:
|
||||
CATEGORY = "ImpactPack/Detector"
|
||||
|
||||
def doit(self, detailer_pipe, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold):
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold, post_dilation=0):
|
||||
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: SimpleDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
|
||||
|
||||
model, clip, vae, positive, negative, wildcard, bbox_detector, segm_detector_opt, sam_model_opt, detailer_hook, refiner_model, refiner_clip, refiner_positive, refiner_negative = detailer_pipe
|
||||
|
||||
return SimpleDetectorForEach.detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion,
|
||||
sam_mask_hint_threshold, sam_model_opt, segm_detector_opt)
|
||||
sam_mask_hint_threshold, post_dilation=post_dilation, sam_model_opt=sam_model_opt, segm_detector_opt=segm_detector_opt,
|
||||
detailer_hook=detailer_hook)
|
||||
|
||||
|
||||
class SimpleDetectorForAnimateDiff:
|
||||
@@ -275,6 +297,8 @@ class SimpleDetectorForAnimateDiff:
|
||||
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
},
|
||||
"optional": {
|
||||
"masking_mode": (["Pivot SEGS", "Combine neighboring frames", "Don't combine"],),
|
||||
"segs_pivot": (["Combined mask", "1st frame mask"],),
|
||||
"sam_model_opt": ("SAM_MODEL", ),
|
||||
"segm_detector_opt": ("SEGM_DETECTOR", ),
|
||||
}
|
||||
@@ -287,11 +311,14 @@ class SimpleDetectorForAnimateDiff:
|
||||
|
||||
@staticmethod
|
||||
def detect(bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion,
|
||||
sam_mask_hint_threshold, sam_model_opt=None, segm_detector_opt=None):
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
|
||||
masking_mode="Pivot SEGS", segs_pivot="Combined mask", sam_model_opt=None, segm_detector_opt=None):
|
||||
|
||||
h = image_frames.shape[1]
|
||||
w = image_frames.shape[2]
|
||||
|
||||
# gather segs for all frames
|
||||
all_segs = []
|
||||
segs_by_frames = []
|
||||
for image in image_frames:
|
||||
image = image.unsqueeze(0)
|
||||
segs = bbox_detector.detect(image, bbox_threshold, bbox_dilation, crop_factor, drop_size)
|
||||
@@ -305,25 +332,129 @@ class SimpleDetectorForAnimateDiff:
|
||||
mask = core.segs_to_combined_mask(segm_segs)
|
||||
segs = core.segs_bitwise_and_mask(segs, mask)
|
||||
|
||||
all_segs.append(segs)
|
||||
segs_by_frames.append(segs)
|
||||
|
||||
# create merged masks
|
||||
all_masks = []
|
||||
for segs in all_segs:
|
||||
all_masks += segs_nodes.SEGSToMaskList().doit(segs)[0]
|
||||
def get_masked_frames():
|
||||
masks_by_frame = []
|
||||
for i, segs in enumerate(segs_by_frames):
|
||||
masks_in_frame = segs_nodes.SEGSToMaskList().doit(segs)[0]
|
||||
current_frame_mask = (masks_in_frame[0] * 255).to(torch.uint8)
|
||||
|
||||
result_mask = all_masks[0]
|
||||
for mask in all_masks[1:]:
|
||||
result_mask += mask
|
||||
for mask in masks_in_frame[1:]:
|
||||
current_frame_mask |= (mask * 255).to(torch.uint8)
|
||||
|
||||
result_mask = utils.to_binary_mask(result_mask, 0.1)
|
||||
current_frame_mask = (current_frame_mask/255.0).to(torch.float32)
|
||||
current_frame_mask = utils.to_binary_mask(current_frame_mask, 0.1)[0]
|
||||
|
||||
return segs_nodes.MaskToSEGS().doit(result_mask, False, crop_factor, False, drop_size)
|
||||
masks_by_frame.append(current_frame_mask)
|
||||
|
||||
return masks_by_frame
|
||||
|
||||
def get_empty_mask():
|
||||
return torch.zeros((h, w), dtype=torch.float32, device="cpu")
|
||||
|
||||
def get_neighboring_mask_at(i, masks_by_frame):
|
||||
prv = masks_by_frame[i-1] if i > 1 else get_empty_mask()
|
||||
cur = masks_by_frame[i]
|
||||
nxt = masks_by_frame[i-1] if i > 1 else get_empty_mask()
|
||||
|
||||
prv = prv if prv is not None else get_empty_mask()
|
||||
cur = cur.clone() if cur is not None else get_empty_mask()
|
||||
nxt = nxt if nxt is not None else get_empty_mask()
|
||||
|
||||
return prv, cur, nxt
|
||||
|
||||
def get_merged_neighboring_mask(masks_by_frame):
|
||||
if len(masks_by_frame) <= 1:
|
||||
return masks_by_frame
|
||||
|
||||
result = []
|
||||
for i in range(0, len(masks_by_frame)):
|
||||
prv, cur, nxt = get_neighboring_mask_at(i, masks_by_frame)
|
||||
cur = (cur * 255).to(torch.uint8)
|
||||
cur |= (prv * 255).to(torch.uint8)
|
||||
cur |= (nxt * 255).to(torch.uint8)
|
||||
cur = (cur / 255.0).to(torch.float32)
|
||||
cur = utils.to_binary_mask(cur, 0.1)[0]
|
||||
result.append(cur)
|
||||
|
||||
return result
|
||||
|
||||
def get_whole_merged_mask():
|
||||
all_masks = []
|
||||
for segs in segs_by_frames:
|
||||
all_masks += segs_nodes.SEGSToMaskList().doit(segs)[0]
|
||||
|
||||
merged_mask = (all_masks[0] * 255).to(torch.uint8)
|
||||
for mask in all_masks[1:]:
|
||||
merged_mask |= (mask * 255).to(torch.uint8)
|
||||
|
||||
merged_mask = (merged_mask / 255.0).to(torch.float32)
|
||||
merged_mask = utils.to_binary_mask(merged_mask, 0.1)[0]
|
||||
return merged_mask
|
||||
|
||||
def get_pivot_segs():
|
||||
if segs_pivot == "1st frame mask":
|
||||
return segs_by_frames[0][1]
|
||||
else:
|
||||
merged_mask = get_whole_merged_mask()
|
||||
return segs_nodes.MaskToSEGS().doit(merged_mask, False, crop_factor, False, drop_size, contour_fill=True)[0]
|
||||
|
||||
def get_merged_neighboring_segs():
|
||||
pivot_segs = get_pivot_segs()
|
||||
|
||||
masks_by_frame = get_masked_frames()
|
||||
masks_by_frame = get_merged_neighboring_mask(masks_by_frame)
|
||||
|
||||
new_segs = []
|
||||
for seg in pivot_segs[1]:
|
||||
cropped_mask = torch.zeros(seg.cropped_mask.shape, dtype=torch.float32, device="cpu").unsqueeze(0)
|
||||
pivot_mask = torch.from_numpy(seg.cropped_mask)
|
||||
x1, y1, x2, y2 = seg.crop_region
|
||||
for mask in masks_by_frame:
|
||||
cropped_mask_at_frame = (mask[y1:y2, x1:x2] * pivot_mask).unsqueeze(0)
|
||||
cropped_mask = torch.cat((cropped_mask, cropped_mask_at_frame), dim=0)
|
||||
|
||||
if len(cropped_mask) > 1:
|
||||
cropped_mask = cropped_mask[1:]
|
||||
|
||||
new_seg = SEG(seg.cropped_image, cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, seg.control_net_wrapper)
|
||||
new_segs.append(new_seg)
|
||||
|
||||
return pivot_segs[0], new_segs
|
||||
|
||||
def get_separated_segs():
|
||||
pivot_segs = get_pivot_segs()
|
||||
|
||||
masks_by_frame = get_masked_frames()
|
||||
|
||||
new_segs = []
|
||||
for seg in pivot_segs[1]:
|
||||
cropped_mask = torch.zeros(seg.cropped_mask.shape, dtype=torch.float32, device="cpu").unsqueeze(0)
|
||||
x1, y1, x2, y2 = seg.crop_region
|
||||
for mask in masks_by_frame:
|
||||
cropped_mask_at_frame = mask[y1:y2, x1:x2]
|
||||
cropped_mask = torch.cat((cropped_mask, cropped_mask_at_frame), dim=0)
|
||||
|
||||
new_seg = SEG(seg.cropped_image, cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, seg.control_net_wrapper)
|
||||
new_segs.append(new_seg)
|
||||
|
||||
return pivot_segs[0], new_segs
|
||||
|
||||
# create result mask
|
||||
if masking_mode == "Pivot SEGS":
|
||||
return (get_pivot_segs(), )
|
||||
|
||||
elif masking_mode == "Combine neighboring frames":
|
||||
return (get_merged_neighboring_segs(), )
|
||||
|
||||
else: # elif masking_mode == "Don't combine":
|
||||
return (get_separated_segs(), )
|
||||
|
||||
def doit(self, bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion,
|
||||
sam_mask_hint_threshold, sam_model_opt=None, segm_detector_opt=None):
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
|
||||
masking_mode="Pivot SEGS", segs_pivot="Combined mask", sam_model_opt=None, segm_detector_opt=None):
|
||||
|
||||
return SimpleDetectorForAnimateDiff.detect(bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion,
|
||||
sam_mask_hint_threshold, sam_model_opt, segm_detector_opt)
|
||||
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
|
||||
masking_mode, segs_pivot, sam_model_opt, segm_detector_opt)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from transformers import pipeline
|
||||
import comfy
|
||||
import re
|
||||
from impact.utils import *
|
||||
@@ -31,6 +30,8 @@ class HF_TransformersClassifierProvider:
|
||||
CATEGORY = "ImpactPack/HuggingFace"
|
||||
|
||||
def doit(self, preset_repo_id, manual_repo_id, device_mode):
|
||||
from transformers import pipeline
|
||||
|
||||
if preset_repo_id == 'Manual repo id':
|
||||
url = manual_repo_id
|
||||
else:
|
||||
@@ -138,7 +139,7 @@ class SEGS_Classify:
|
||||
cropped_image = crop_image(ref_image_opt, seg.crop_region)
|
||||
|
||||
if cropped_image is not None:
|
||||
cropped_image = Image.fromarray(np.clip(255. * cropped_image.squeeze(), 0, 255).astype(np.uint8))
|
||||
cropped_image = to_pil(cropped_image)
|
||||
res = classifier(cropped_image)
|
||||
classified.append((seg, res))
|
||||
else:
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import sys
|
||||
from . import hooks
|
||||
from . import defs
|
||||
|
||||
|
||||
class SEGSOrderedFilterDetailerHookProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"target": (["area(=w*h)", "width", "height", "x1", "y1", "x2", "y2"],),
|
||||
"order": ("BOOLEAN", {"default": True, "label_on": "descending", "label_off": "ascending"}),
|
||||
"take_start": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
|
||||
"take_count": ("INT", {"default": 1, "min": 0, "max": sys.maxsize, "step": 1}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DETAILER_HOOK", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, target, order, take_start, take_count):
|
||||
hook = hooks.SEGSOrderedFilterDetailerHook(target, order, take_start, take_count)
|
||||
return (hook, )
|
||||
|
||||
|
||||
class SEGSRangeFilterDetailerHookProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"target": (["area(=w*h)", "width", "height", "x1", "y1", "x2", "y2", "length_percent"],),
|
||||
"mode": ("BOOLEAN", {"default": True, "label_on": "inside", "label_off": "outside"}),
|
||||
"min_value": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
|
||||
"max_value": ("INT", {"default": 67108864, "min": 0, "max": sys.maxsize, "step": 1}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DETAILER_HOOK", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, target, mode, min_value, max_value):
|
||||
hook = hooks.SEGSRangeFilterDetailerHook(target, mode, min_value, max_value)
|
||||
return (hook, )
|
||||
|
||||
|
||||
class SEGSLabelFilterDetailerHookProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"segs": ("SEGS", ),
|
||||
"preset": (['all'] + defs.detection_labels,),
|
||||
"labels": ("STRING", {"multiline": True, "placeholder": "List the types of segments to be allowed, separated by commas"}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DETAILER_HOOK", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, preset, labels):
|
||||
hook = hooks.SEGSLabelFilterDetailerHook(labels)
|
||||
return (hook, )
|
||||
|
||||
|
||||
class PreviewDetailerHookProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {"quality": ("INT", {"default": 95, "min": 20, "max": 100})},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DETAILER_HOOK", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, quality, unique_id):
|
||||
hook = hooks.PreviewDetailerHook(unique_id, quality)
|
||||
return (hook, )
|
||||
@@ -0,0 +1,450 @@
|
||||
import copy
|
||||
import nodes
|
||||
|
||||
from impact import utils
|
||||
from . import segs_nodes
|
||||
from thirdparty import noise_nodes
|
||||
from server import PromptServer
|
||||
import asyncio
|
||||
import folder_paths
|
||||
import os
|
||||
|
||||
class PixelKSampleHook:
|
||||
cur_step = 0
|
||||
total_step = 0
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def set_steps(self, info):
|
||||
self.cur_step, self.total_step = info
|
||||
|
||||
def post_decode(self, pixels):
|
||||
return pixels
|
||||
|
||||
def post_upscale(self, pixels):
|
||||
return pixels
|
||||
|
||||
def post_encode(self, samples):
|
||||
return samples
|
||||
|
||||
def pre_decode(self, samples):
|
||||
return samples
|
||||
|
||||
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent,
|
||||
denoise):
|
||||
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise
|
||||
|
||||
def post_crop_region(self, w, h, item_bbox, crop_region):
|
||||
return crop_region
|
||||
|
||||
def touch_scaled_size(self, w, h):
|
||||
return w, h
|
||||
|
||||
|
||||
class PixelKSampleHookCombine(PixelKSampleHook):
|
||||
hook1 = None
|
||||
hook2 = None
|
||||
|
||||
def __init__(self, hook1, hook2):
|
||||
super().__init__()
|
||||
self.hook1 = hook1
|
||||
self.hook2 = hook2
|
||||
|
||||
def set_steps(self, info):
|
||||
self.hook1.set_steps(info)
|
||||
self.hook2.set_steps(info)
|
||||
|
||||
def pre_decode(self, samples):
|
||||
return self.hook2.pre_decode(self.hook1.pre_decode(samples))
|
||||
|
||||
def post_decode(self, pixels):
|
||||
return self.hook2.post_decode(self.hook1.post_decode(pixels))
|
||||
|
||||
def post_upscale(self, pixels):
|
||||
return self.hook2.post_upscale(self.hook1.post_upscale(pixels))
|
||||
|
||||
def post_encode(self, samples):
|
||||
return self.hook2.post_encode(self.hook1.post_encode(samples))
|
||||
|
||||
def post_crop_region(self, w, h, item_bbox, crop_region):
|
||||
crop_region = self.hook1.post_crop_region(w, h, item_bbox, crop_region)
|
||||
return self.hook2.post_crop_region(w, h, item_bbox, crop_region)
|
||||
|
||||
def touch_scaled_size(self, w, h):
|
||||
w, h = self.hook1.touch_scaled_size(w, h)
|
||||
return self.hook2.touch_scaled_size(w, h)
|
||||
|
||||
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent,
|
||||
denoise):
|
||||
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
|
||||
self.hook1.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
|
||||
upscaled_latent, denoise)
|
||||
|
||||
return self.hook2.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
|
||||
upscaled_latent, denoise)
|
||||
|
||||
|
||||
class DetailerHookCombine(PixelKSampleHookCombine):
|
||||
def cycle_latent(self, latent):
|
||||
latent = self.hook1.cycle_latent(latent)
|
||||
latent = self.hook2.cycle_latent(latent)
|
||||
return latent
|
||||
|
||||
def post_detection(self, segs):
|
||||
segs = self.hook1.post_detection(segs)
|
||||
segs = self.hook2.post_detection(segs)
|
||||
return segs
|
||||
|
||||
def post_paste(self, image):
|
||||
image = self.hook1.post_paste(image)
|
||||
image = self.hook2.post_paste(image)
|
||||
return image
|
||||
|
||||
|
||||
class SimpleCfgScheduleHook(PixelKSampleHook):
|
||||
target_cfg = 0
|
||||
|
||||
def __init__(self, target_cfg):
|
||||
super().__init__()
|
||||
self.target_cfg = target_cfg
|
||||
|
||||
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent,
|
||||
denoise):
|
||||
progress = self.cur_step / self.total_step
|
||||
gap = self.target_cfg - cfg
|
||||
current_cfg = cfg + gap * progress
|
||||
return model, seed, steps, current_cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise
|
||||
|
||||
|
||||
class SimpleDenoiseScheduleHook(PixelKSampleHook):
|
||||
def __init__(self, target_denoise):
|
||||
super().__init__()
|
||||
self.target_denoise = target_denoise
|
||||
|
||||
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent,
|
||||
denoise):
|
||||
progress = self.cur_step / self.total_step
|
||||
gap = self.target_denoise - denoise
|
||||
current_denoise = denoise + gap * progress
|
||||
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, current_denoise
|
||||
|
||||
|
||||
class DetailerHook(PixelKSampleHook):
|
||||
def cycle_latent(self, latent):
|
||||
return latent
|
||||
|
||||
def post_detection(self, segs):
|
||||
return segs
|
||||
|
||||
def post_paste(self, image):
|
||||
return image
|
||||
|
||||
|
||||
class SimpleDetailerDenoiseSchedulerHook(DetailerHook):
|
||||
def __init__(self, target_denoise):
|
||||
super().__init__()
|
||||
self.target_denoise = target_denoise
|
||||
|
||||
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, denoise):
|
||||
progress = self.cur_step / self.total_step
|
||||
gap = self.target_denoise - denoise
|
||||
current_denoise = denoise + gap * progress
|
||||
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, current_denoise
|
||||
|
||||
|
||||
class CoreMLHook(DetailerHook):
|
||||
def __init__(self, mode):
|
||||
super().__init__()
|
||||
resolution = mode.split('x')
|
||||
|
||||
self.w = int(resolution[0])
|
||||
self.h = int(resolution[1])
|
||||
|
||||
self.override_bbox_by_segm = False
|
||||
|
||||
def pre_decode(self, samples):
|
||||
new_samples = copy.deepcopy(samples)
|
||||
new_samples['samples'] = samples['samples'][0].unsqueeze(0)
|
||||
return new_samples
|
||||
|
||||
def post_encode(self, samples):
|
||||
new_samples = copy.deepcopy(samples)
|
||||
new_samples['samples'] = samples['samples'].repeat(2, 1, 1, 1)
|
||||
return new_samples
|
||||
|
||||
def post_crop_region(self, w, h, item_bbox, crop_region):
|
||||
x1, y1, x2, y2 = crop_region
|
||||
bx1, by1, bx2, by2 = item_bbox
|
||||
crop_w = x2-x1
|
||||
crop_h = y2-y1
|
||||
|
||||
crop_ratio = crop_w/crop_h
|
||||
target_ratio = self.w/self.h
|
||||
if crop_ratio < target_ratio:
|
||||
# shrink height
|
||||
top_gap = by1 - y1
|
||||
bottom_gap = y2 - by2
|
||||
|
||||
gap_ratio = top_gap / bottom_gap
|
||||
|
||||
target_height = 1/target_ratio*crop_w
|
||||
delta_height = crop_h - target_height
|
||||
|
||||
new_y1 = int(y1 + delta_height*gap_ratio)
|
||||
new_y2 = int(new_y1 + target_height)
|
||||
crop_region = x1, new_y1, x2, new_y2
|
||||
|
||||
elif crop_ratio > target_ratio:
|
||||
# shrink width
|
||||
left_gap = bx1 - x1
|
||||
right_gap = x2 - bx2
|
||||
|
||||
gap_ratio = left_gap / right_gap
|
||||
|
||||
target_width = target_ratio*crop_h
|
||||
delta_width = crop_w - target_width
|
||||
|
||||
new_x1 = int(x1 + delta_width*gap_ratio)
|
||||
new_x2 = int(new_x1 + target_width)
|
||||
crop_region = new_x1, y1, new_x2, y2
|
||||
|
||||
return crop_region
|
||||
|
||||
def touch_scaled_size(self, w, h):
|
||||
return self.w, self.h
|
||||
|
||||
|
||||
# REQUIREMENTS: BlenderNeko/ComfyUI Noise
|
||||
class InjectNoiseHook(PixelKSampleHook):
|
||||
def __init__(self, source, seed, start_strength, end_strength):
|
||||
super().__init__()
|
||||
self.source = source
|
||||
self.seed = seed
|
||||
self.start_strength = start_strength
|
||||
self.end_strength = end_strength
|
||||
|
||||
def post_encode(self, samples):
|
||||
cur_step = self.cur_step
|
||||
|
||||
size = samples['samples'].shape
|
||||
seed = cur_step + self.seed + cur_step
|
||||
|
||||
if "BNK_NoisyLatentImage" in nodes.NODE_CLASS_MAPPINGS and "BNK_InjectNoise" in nodes.NODE_CLASS_MAPPINGS:
|
||||
NoisyLatentImage = nodes.NODE_CLASS_MAPPINGS["BNK_NoisyLatentImage"]
|
||||
InjectNoise = nodes.NODE_CLASS_MAPPINGS["BNK_InjectNoise"]
|
||||
else:
|
||||
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_Noise',
|
||||
"To use 'NoiseInjectionHookProvider', 'ComfyUI Noise' extension is required.")
|
||||
raise Exception("'BNK_NoisyLatentImage', 'BNK_InjectNoise' nodes are not installed.")
|
||||
|
||||
noise = NoisyLatentImage().create_noisy_latents(self.source, seed, size[3] * 8, size[2] * 8, size[0])[0]
|
||||
|
||||
# inj noise
|
||||
mask = None
|
||||
if 'noise_mask' in samples:
|
||||
mask = samples['noise_mask']
|
||||
|
||||
strength = self.start_strength + (self.end_strength - self.start_strength) * cur_step / self.total_step
|
||||
samples = InjectNoise().inject_noise(samples, strength, noise, mask)[0]
|
||||
print(f"[Impact Pack] InjectNoiseHook: strength = {strength}")
|
||||
|
||||
if mask is not None:
|
||||
samples['noise_mask'] = mask
|
||||
|
||||
return samples
|
||||
|
||||
|
||||
class UnsamplerHook(PixelKSampleHook):
|
||||
def __init__(self, model, steps, start_end_at_step, end_end_at_step, cfg, sampler_name,
|
||||
scheduler, normalize, positive, negative):
|
||||
super().__init__()
|
||||
self.model = model
|
||||
self.cfg = cfg
|
||||
self.sampler_name = sampler_name
|
||||
self.steps = steps
|
||||
self.start_end_at_step = start_end_at_step
|
||||
self.end_end_at_step = end_end_at_step
|
||||
self.scheduler = scheduler
|
||||
self.normalize = normalize
|
||||
self.positive = positive
|
||||
self.negative = negative
|
||||
|
||||
def post_encode(self, samples):
|
||||
cur_step = self.cur_step
|
||||
|
||||
Unsampler = noise_nodes.Unsampler
|
||||
|
||||
end_at_step = self.start_end_at_step + (self.end_end_at_step - self.start_end_at_step) * cur_step / self.total_step
|
||||
end_at_step = int(end_at_step)
|
||||
|
||||
print(f"[Impact Pack] UnsamplerHook: end_at_step = {end_at_step}")
|
||||
|
||||
# inj noise
|
||||
mask = None
|
||||
if 'noise_mask' in samples:
|
||||
mask = samples['noise_mask']
|
||||
|
||||
samples = Unsampler().unsampler(self.model, self.cfg, self.sampler_name, self.steps, end_at_step,
|
||||
self.scheduler, self.normalize, self.positive, self.negative, samples)[0]
|
||||
|
||||
if mask is not None:
|
||||
samples['noise_mask'] = mask
|
||||
|
||||
return samples
|
||||
|
||||
|
||||
class InjectNoiseHookForDetailer(DetailerHook):
|
||||
def __init__(self, source, seed, start_strength, end_strength, from_start=False):
|
||||
super().__init__()
|
||||
self.source = source
|
||||
self.seed = seed
|
||||
self.start_strength = start_strength
|
||||
self.end_strength = end_strength
|
||||
self.from_start = from_start
|
||||
|
||||
def inject_noise(self, samples):
|
||||
cur_step = self.cur_step if self.from_start else self.cur_step - 1
|
||||
total_step = self.total_step if self.from_start else self.total_step - 1
|
||||
|
||||
size = samples['samples'].shape
|
||||
seed = cur_step + self.seed + cur_step
|
||||
|
||||
if "BNK_NoisyLatentImage" in nodes.NODE_CLASS_MAPPINGS and "BNK_InjectNoise" in nodes.NODE_CLASS_MAPPINGS:
|
||||
NoisyLatentImage = nodes.NODE_CLASS_MAPPINGS["BNK_NoisyLatentImage"]
|
||||
InjectNoise = nodes.NODE_CLASS_MAPPINGS["BNK_InjectNoise"]
|
||||
else:
|
||||
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_Noise',
|
||||
"To use 'NoiseInjectionDetailerHookProvider', 'ComfyUI Noise' extension is required.")
|
||||
raise Exception("'BNK_NoisyLatentImage', 'BNK_InjectNoise' nodes are not installed.")
|
||||
|
||||
noise = NoisyLatentImage().create_noisy_latents(self.source, seed, size[3] * 8, size[2] * 8, size[0])[0]
|
||||
|
||||
# inj noise
|
||||
mask = None
|
||||
if 'noise_mask' in samples:
|
||||
mask = samples['noise_mask']
|
||||
|
||||
strength = self.start_strength + (self.end_strength - self.start_strength) * cur_step / total_step
|
||||
samples = InjectNoise().inject_noise(samples, strength, noise, mask)[0]
|
||||
|
||||
if mask is not None:
|
||||
samples['noise_mask'] = mask
|
||||
|
||||
return samples
|
||||
|
||||
def cycle_latent(self, latent):
|
||||
if self.cur_step == 0 and not self.from_start:
|
||||
return latent
|
||||
else:
|
||||
return self.inject_noise(latent)
|
||||
|
||||
|
||||
class UnsamplerDetailerHook(DetailerHook):
|
||||
def __init__(self, model, steps, start_end_at_step, end_end_at_step, cfg, sampler_name,
|
||||
scheduler, normalize, positive, negative, from_start=False):
|
||||
super().__init__()
|
||||
self.model = model
|
||||
self.cfg = cfg
|
||||
self.sampler_name = sampler_name
|
||||
self.steps = steps
|
||||
self.start_end_at_step = start_end_at_step
|
||||
self.end_end_at_step = end_end_at_step
|
||||
self.scheduler = scheduler
|
||||
self.normalize = normalize
|
||||
self.positive = positive
|
||||
self.negative = negative
|
||||
self.from_start = from_start
|
||||
|
||||
def unsample(self, samples):
|
||||
cur_step = self.cur_step if self.from_start else self.cur_step - 1
|
||||
total_step = self.total_step if self.from_start else self.total_step - 1
|
||||
|
||||
Unsampler = noise_nodes.Unsampler
|
||||
|
||||
end_at_step = self.start_end_at_step + (self.end_end_at_step - self.start_end_at_step) * cur_step / total_step
|
||||
end_at_step = int(end_at_step)
|
||||
|
||||
# inj noise
|
||||
mask = None
|
||||
if 'noise_mask' in samples:
|
||||
mask = samples['noise_mask']
|
||||
|
||||
samples = Unsampler().unsampler(self.model, self.cfg, self.sampler_name, self.steps, end_at_step,
|
||||
self.scheduler, self.normalize, self.positive, self.negative, samples)[0]
|
||||
|
||||
if mask is not None:
|
||||
samples['noise_mask'] = mask
|
||||
|
||||
return samples
|
||||
|
||||
def cycle_latent(self, latent):
|
||||
if self.cur_step == 0 and not self.from_start:
|
||||
return latent
|
||||
else:
|
||||
return self.unsample(latent)
|
||||
|
||||
|
||||
class SEGSOrderedFilterDetailerHook(DetailerHook):
|
||||
def __init__(self, target, order, take_start, take_count):
|
||||
super().__init__()
|
||||
self.target = target
|
||||
self.order = order
|
||||
self.take_start = take_start
|
||||
self.take_count = take_count
|
||||
|
||||
def post_detection(self, segs):
|
||||
return segs_nodes.SEGSOrderedFilter().doit(segs, self.target, self.order, self.take_start, self.take_count)[0]
|
||||
|
||||
|
||||
class SEGSRangeFilterDetailerHook(DetailerHook):
|
||||
def __init__(self, target, mode, min_value, max_value):
|
||||
super().__init__()
|
||||
self.target = target
|
||||
self.mode = mode
|
||||
self.min_value = min_value
|
||||
self.max_value = max_value
|
||||
|
||||
def post_detection(self, segs):
|
||||
return segs_nodes.SEGSRangeFilter().doit(segs, self.target, self.mode, self.min_value, self.max_value)[0]
|
||||
|
||||
|
||||
class SEGSLabelFilterDetailerHook(DetailerHook):
|
||||
def __init__(self, labels):
|
||||
super().__init__()
|
||||
self.labels = labels
|
||||
|
||||
def post_detection(self, segs):
|
||||
return segs_nodes.SEGSLabelFilter().doit(segs, "", self.labels)[0]
|
||||
|
||||
|
||||
class PreviewDetailerHook(DetailerHook):
|
||||
def __init__(self, node_id, quality):
|
||||
super().__init__()
|
||||
self.node_id = node_id
|
||||
self.quality = quality
|
||||
|
||||
async def send(self, image):
|
||||
if len(image) > 0:
|
||||
image = image[0].unsqueeze(0)
|
||||
img = utils.tensor2pil(image)
|
||||
|
||||
temp_path = os.path.join(folder_paths.get_temp_directory(), 'pvhook')
|
||||
|
||||
if not os.path.exists(temp_path):
|
||||
os.makedirs(temp_path)
|
||||
|
||||
fullpath = os.path.join(temp_path, f"{self.node_id}.webp")
|
||||
img.save(fullpath, quality=self.quality)
|
||||
|
||||
item = {
|
||||
"filename": f"{self.node_id}.webp",
|
||||
"subfolder": 'pvhook',
|
||||
"type": 'temp'
|
||||
}
|
||||
|
||||
PromptServer.instance.send_sync("impact-preview", {'node_id': self.node_id, 'item': item})
|
||||
|
||||
def post_paste(self, image):
|
||||
asyncio.run(self.send(image))
|
||||
return image
|
||||
+430
-611
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,231 @@
|
||||
import nodes
|
||||
from comfy.k_diffusion import sampling as k_diffusion_sampling
|
||||
from comfy import samplers
|
||||
from comfy_extras import nodes_custom_sampler
|
||||
|
||||
import torch
|
||||
import math
|
||||
|
||||
|
||||
def calculate_sigmas(model, sampler, scheduler, steps):
|
||||
discard_penultimate_sigma = False
|
||||
if sampler in ['dpm_2', 'dpm_2_ancestral', 'uni_pc', 'uni_pc_bh2']:
|
||||
steps += 1
|
||||
discard_penultimate_sigma = True
|
||||
|
||||
sigmas = samplers.calculate_sigmas_scheduler(model.model, scheduler, steps)
|
||||
|
||||
if discard_penultimate_sigma:
|
||||
sigmas = torch.cat([sigmas[:-2], sigmas[-1:]])
|
||||
return sigmas
|
||||
|
||||
|
||||
def get_noise_sampler(x, cpu, total_sigmas, **kwargs):
|
||||
if 'extra_args' in kwargs and 'seed' in kwargs['extra_args']:
|
||||
sigma_min, sigma_max = total_sigmas[total_sigmas > 0].min(), total_sigmas.max()
|
||||
seed = kwargs['extra_args'].get("seed", None)
|
||||
return k_diffusion_sampling.BrownianTreeNoiseSampler(x, sigma_min, sigma_max, seed=seed, cpu=cpu)
|
||||
return None
|
||||
|
||||
|
||||
def ksampler(sampler_name, total_sigmas, extra_options={}, inpaint_options={}):
|
||||
if sampler_name == "dpmpp_sde":
|
||||
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
|
||||
noise_sampler = get_noise_sampler(x, True, total_sigmas, **kwargs)
|
||||
if noise_sampler is not None:
|
||||
kwargs['noise_sampler'] = noise_sampler
|
||||
|
||||
return k_diffusion_sampling.sample_dpmpp_sde(model, x, sigmas, **kwargs)
|
||||
|
||||
sampler_function = sample_dpmpp_sde
|
||||
|
||||
elif sampler_name == "dpmpp_sde_gpu":
|
||||
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
|
||||
noise_sampler = get_noise_sampler(x, False, total_sigmas, **kwargs)
|
||||
if noise_sampler is not None:
|
||||
kwargs['noise_sampler'] = noise_sampler
|
||||
|
||||
return k_diffusion_sampling.sample_dpmpp_sde_gpu(model, x, sigmas, **kwargs)
|
||||
|
||||
sampler_function = sample_dpmpp_sde
|
||||
|
||||
elif sampler_name == "dpmpp_2m_sde":
|
||||
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
|
||||
noise_sampler = get_noise_sampler(x, True, total_sigmas, **kwargs)
|
||||
if noise_sampler is not None:
|
||||
kwargs['noise_sampler'] = noise_sampler
|
||||
|
||||
return k_diffusion_sampling.sample_dpmpp_2m_sde(model, x, sigmas, **kwargs)
|
||||
|
||||
sampler_function = sample_dpmpp_sde
|
||||
|
||||
elif sampler_name == "dpmpp_2m_sde_gpu":
|
||||
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
|
||||
noise_sampler = get_noise_sampler(x, False, total_sigmas, **kwargs)
|
||||
if noise_sampler is not None:
|
||||
kwargs['noise_sampler'] = noise_sampler
|
||||
|
||||
return k_diffusion_sampling.sample_dpmpp_2m_sde_gpu(model, x, sigmas, **kwargs)
|
||||
|
||||
sampler_function = sample_dpmpp_sde
|
||||
|
||||
elif sampler_name == "dpmpp_3m_sde":
|
||||
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
|
||||
noise_sampler = get_noise_sampler(x, True, total_sigmas, **kwargs)
|
||||
if noise_sampler is not None:
|
||||
kwargs['noise_sampler'] = noise_sampler
|
||||
|
||||
return k_diffusion_sampling.sample_dpmpp_2m_sde(model, x, sigmas, **kwargs)
|
||||
|
||||
sampler_function = sample_dpmpp_sde
|
||||
|
||||
elif sampler_name == "dpmpp_3m_sde_gpu":
|
||||
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
|
||||
noise_sampler = get_noise_sampler(x, False, total_sigmas, **kwargs)
|
||||
if noise_sampler is not None:
|
||||
kwargs['noise_sampler'] = noise_sampler
|
||||
|
||||
return k_diffusion_sampling.sample_dpmpp_2m_sde_gpu(model, x, sigmas, **kwargs)
|
||||
|
||||
sampler_function = sample_dpmpp_sde
|
||||
else:
|
||||
return samplers.ksampler(sampler_name, extra_options, inpaint_options)
|
||||
|
||||
return samplers.KSAMPLER(sampler_function, extra_options, inpaint_options)
|
||||
|
||||
|
||||
def separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler, positive, negative,
|
||||
latent_image, start_at_step, end_at_step, return_with_leftover_noise, sigma_ratio=1.0, sampler_opt=None):
|
||||
if sampler_opt is None:
|
||||
total_sigmas = calculate_sigmas(model, sampler_name, scheduler, steps)
|
||||
else:
|
||||
total_sigmas = calculate_sigmas(model, "", scheduler, steps)
|
||||
|
||||
sigmas = total_sigmas[start_at_step:end_at_step+1] * sigma_ratio
|
||||
if sampler_opt is None:
|
||||
impact_sampler = ksampler(sampler_name, total_sigmas)
|
||||
else:
|
||||
impact_sampler = sampler_opt
|
||||
|
||||
if len(sigmas) == 0 or (len(sigmas) == 1 and sigmas[0] == 0):
|
||||
return latent_image
|
||||
|
||||
res = nodes_custom_sampler.SamplerCustom().sample(model, add_noise, seed, cfg, positive, negative, impact_sampler, sigmas, latent_image)
|
||||
|
||||
if return_with_leftover_noise:
|
||||
return res[0]
|
||||
else:
|
||||
return res[1]
|
||||
|
||||
|
||||
def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise,
|
||||
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None, refiner_negative=None):
|
||||
|
||||
if refiner_ratio is None or refiner_model is None or refiner_clip is None or refiner_positive is None or refiner_negative is None:
|
||||
refined_latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)[0]
|
||||
else:
|
||||
advanced_steps = math.floor(steps / denoise)
|
||||
start_at_step = advanced_steps - steps
|
||||
end_at_step = start_at_step + math.floor(steps * (1.0 - refiner_ratio))
|
||||
|
||||
print(f"pre: {start_at_step} .. {end_at_step} / {advanced_steps}")
|
||||
temp_latent = separated_sample(model, True, seed, advanced_steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, latent_image, start_at_step, end_at_step, True)
|
||||
|
||||
if 'noise_mask' in latent_image:
|
||||
# noise_latent = \
|
||||
# impact_sampling.separated_sample(refiner_model, "enable", seed, advanced_steps, cfg, sampler_name,
|
||||
# scheduler, refiner_positive, refiner_negative, latent_image, end_at_step,
|
||||
# end_at_step, "enable")
|
||||
|
||||
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
|
||||
temp_latent = latent_compositor.composite(latent_image, temp_latent, 0, 0, False, latent_image['noise_mask'])[0]
|
||||
|
||||
print(f"post: {end_at_step} .. {advanced_steps + 1} / {advanced_steps}")
|
||||
refined_latent = separated_sample(refiner_model, False, seed, advanced_steps, cfg, sampler_name, scheduler,
|
||||
refiner_positive, refiner_negative, temp_latent, end_at_step, advanced_steps + 1, False)
|
||||
|
||||
return refined_latent
|
||||
|
||||
|
||||
class KSamplerAdvancedWrapper:
|
||||
params = None
|
||||
|
||||
def __init__(self, model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=None):
|
||||
self.params = model, cfg, sampler_name, scheduler, positive, negative
|
||||
self.sampler_opt = sampler_opt
|
||||
|
||||
def clone_with_conditionings(self, positive, negative):
|
||||
model, cfg, sampler_name, scheduler, _, _ = self.params
|
||||
return KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, self.sampler_opt)
|
||||
|
||||
def sample_advanced(self, add_noise, seed, steps, latent_image, start_at_step, end_at_step, return_with_leftover_noise, hook=None,
|
||||
recovery_mode="ratio additional", recovery_sampler="AUTO", recovery_sigma_ratio=1.0):
|
||||
|
||||
model, cfg, sampler_name, scheduler, positive, negative = self.params
|
||||
|
||||
if hook is not None:
|
||||
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent = hook.pre_ksample_advanced(model, add_noise, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, latent_image, start_at_step, end_at_step,
|
||||
return_with_leftover_noise)
|
||||
|
||||
if recovery_mode != 'DISABLE' and sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu']:
|
||||
base_image = latent_image.copy()
|
||||
if recovery_mode == "ratio between":
|
||||
sigma_ratio = 1.0 - recovery_sigma_ratio
|
||||
else:
|
||||
sigma_ratio = 1.0
|
||||
else:
|
||||
base_image = None
|
||||
sigma_ratio = 1.0
|
||||
|
||||
try:
|
||||
if sigma_ratio > 0:
|
||||
latent_image = separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, latent_image, start_at_step, end_at_step,
|
||||
return_with_leftover_noise, sigma_ratio=sigma_ratio, sampler_opt=self.sampler_opt)
|
||||
except ValueError as e:
|
||||
if str(e) == 'sigma_min and sigma_max must not be 0':
|
||||
print(f"\nWARN: sampling skipped - sigma_min and sigma_max are 0")
|
||||
return latent_image
|
||||
|
||||
if (recovery_sigma_ratio > 0 and recovery_mode != 'DISABLE' and
|
||||
sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu']):
|
||||
compensate = 0 if sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu'] else 2
|
||||
if recovery_sampler == "AUTO":
|
||||
recovery_sampler = 'dpm_fast' if sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu'] else 'dpmpp_2m'
|
||||
|
||||
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
|
||||
|
||||
noise_mask = latent_image['noise_mask']
|
||||
|
||||
if len(noise_mask.shape) == 4:
|
||||
noise_mask = noise_mask.squeeze(0).squeeze(0)
|
||||
|
||||
latent_image = latent_compositor.composite(base_image, latent_image, 0, 0, False, noise_mask)[0]
|
||||
|
||||
try:
|
||||
latent_image = separated_sample(model, add_noise, seed, steps, cfg, recovery_sampler, scheduler,
|
||||
positive, negative, latent_image, start_at_step-compensate, end_at_step,
|
||||
return_with_leftover_noise, sigma_ratio=recovery_sigma_ratio, sampler_opt=self.sampler_opt)
|
||||
except ValueError as e:
|
||||
if str(e) == 'sigma_min and sigma_max must not be 0':
|
||||
print(f"\nWARN: sampling skipped - sigma_min and sigma_max are 0")
|
||||
|
||||
return latent_image
|
||||
|
||||
|
||||
class KSamplerWrapper:
|
||||
params = None
|
||||
|
||||
def __init__(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise):
|
||||
self.params = model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise
|
||||
|
||||
def sample(self, latent_image, hook=None):
|
||||
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise = self.params
|
||||
|
||||
if hook is not None:
|
||||
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
|
||||
hook.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)
|
||||
|
||||
return nodes.common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)[0]
|
||||
+130
-30
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
@@ -7,8 +8,11 @@ import impact
|
||||
import server
|
||||
import folder_paths
|
||||
|
||||
import torchvision
|
||||
|
||||
import impact.core as core
|
||||
import impact.impact_pack as impact_pack
|
||||
from impact.utils import to_tensor
|
||||
from segment_anything import SamPredictor, sam_model_registry
|
||||
import numpy as np
|
||||
import nodes
|
||||
@@ -221,12 +225,12 @@ async def segs_picker(request):
|
||||
idx = int(request.rel_url.query.get('idx', ''))
|
||||
|
||||
if node_id in segs_picker_map and idx < len(segs_picker_map[node_id]):
|
||||
pil = segs_picker_map[node_id][idx]
|
||||
img = to_tensor(segs_picker_map[node_id][idx]).permute(0, 3, 1, 2).squeeze(0)
|
||||
pil = torchvision.transforms.ToPILImage('RGB')(img)
|
||||
|
||||
image_bytes = BytesIO()
|
||||
pil.save(image_bytes, format="PNG")
|
||||
image_bytes.seek(0)
|
||||
|
||||
return web.Response(status=200, body=image_bytes, content_type='image/png', headers={"Content-Disposition": f"filename={node_id}{idx}.png"})
|
||||
|
||||
return web.Response(status=400)
|
||||
@@ -270,33 +274,36 @@ async def view_validate(request):
|
||||
|
||||
@server.PromptServer.instance.routes.get("/impact/set/pb_id_image")
|
||||
async def set_previewbridge_image(request):
|
||||
if "filename" in request.rel_url.query:
|
||||
node_id = request.rel_url.query["node_id"]
|
||||
filename = request.rel_url.query["filename"]
|
||||
path_type = request.rel_url.query["type"]
|
||||
subfolder = request.rel_url.query["subfolder"]
|
||||
filename, output_dir = folder_paths.annotated_filepath(filename)
|
||||
try:
|
||||
if "filename" in request.rel_url.query:
|
||||
node_id = request.rel_url.query["node_id"]
|
||||
filename = request.rel_url.query["filename"]
|
||||
path_type = request.rel_url.query["type"]
|
||||
subfolder = request.rel_url.query["subfolder"]
|
||||
filename, output_dir = folder_paths.annotated_filepath(filename)
|
||||
|
||||
if filename == '' or filename[0] == '/' or '..' in filename:
|
||||
return web.Response(status=400)
|
||||
if filename == '' or filename[0] == '/' or '..' in filename:
|
||||
return web.Response(status=400)
|
||||
|
||||
if output_dir is None:
|
||||
if path_type == 'input':
|
||||
output_dir = folder_paths.get_input_directory()
|
||||
elif path_type == 'output':
|
||||
output_dir = folder_paths.get_output_directory()
|
||||
else:
|
||||
output_dir = folder_paths.get_temp_directory()
|
||||
if output_dir is None:
|
||||
if path_type == 'input':
|
||||
output_dir = folder_paths.get_input_directory()
|
||||
elif path_type == 'output':
|
||||
output_dir = folder_paths.get_output_directory()
|
||||
else:
|
||||
output_dir = folder_paths.get_temp_directory()
|
||||
|
||||
file = os.path.join(output_dir, subfolder, filename)
|
||||
item = {
|
||||
'filename': filename,
|
||||
'type': path_type,
|
||||
'subfolder': subfolder,
|
||||
}
|
||||
pb_id = core.set_previewbridge_image(node_id, file, item)
|
||||
file = os.path.join(output_dir, subfolder, filename)
|
||||
item = {
|
||||
'filename': filename,
|
||||
'type': path_type,
|
||||
'subfolder': subfolder,
|
||||
}
|
||||
pb_id = core.set_previewbridge_image(node_id, file, item)
|
||||
|
||||
return web.Response(status=200, text=pb_id)
|
||||
return web.Response(status=200, text=pb_id)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
return web.Response(status=400)
|
||||
|
||||
@@ -331,6 +338,7 @@ async def view_previewbridge_image(request):
|
||||
def onprompt_for_switch(json_data):
|
||||
inversed_switch_info = {}
|
||||
onprompt_switch_info = {}
|
||||
onprompt_cond_branch_info = {}
|
||||
|
||||
for k, v in json_data['prompt'].items():
|
||||
if 'class_type' not in v:
|
||||
@@ -347,7 +355,7 @@ def onprompt_for_switch(json_data):
|
||||
inversed_switch_info[k] = select_input
|
||||
|
||||
elif cls in ['ImpactSwitch', 'LatentSwitch', 'SEGSSwitch', 'ImpactMakeImageList']:
|
||||
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode']:
|
||||
if 'sel_mode' 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]]
|
||||
@@ -361,6 +369,21 @@ def onprompt_for_switch(json_data):
|
||||
else:
|
||||
onprompt_switch_info[k] = select_input
|
||||
|
||||
elif cls == 'ImpactConditionalBranchSelMode':
|
||||
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'cond' in v['inputs']:
|
||||
cond_input = v['inputs']['cond']
|
||||
if isinstance(cond_input, list) and len(cond_input) == 2:
|
||||
input_node = json_data['prompt'][cond_input[0]]
|
||||
if (input_node['class_type'] == 'ImpactValueReceiver' and 'inputs' in input_node
|
||||
and 'value' in input_node['inputs'] and 'typ' in input_node['inputs']):
|
||||
if 'BOOLEAN' == input_node['inputs']['typ']:
|
||||
try:
|
||||
onprompt_cond_branch_info[k] = input_node['inputs']['value'].lower() == "true"
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
onprompt_cond_branch_info[k] = cond_input
|
||||
|
||||
for k, v in json_data['prompt'].items():
|
||||
disable_targets = set()
|
||||
|
||||
@@ -376,12 +399,15 @@ def onprompt_for_switch(json_data):
|
||||
if kk != selected_slot_name and kk.startswith('input'):
|
||||
disable_targets.add(kk)
|
||||
|
||||
if k in onprompt_cond_branch_info:
|
||||
selected_slot_name = "tt_value" if onprompt_cond_branch_info[k] else "ff_value"
|
||||
for kk, vv in v['inputs'].items():
|
||||
if kk in ['tt_value', 'ff_value'] and kk != selected_slot_name:
|
||||
disable_targets.add(kk)
|
||||
|
||||
for kk in disable_targets:
|
||||
del v['inputs'][kk]
|
||||
|
||||
return json_data
|
||||
|
||||
|
||||
def onprompt_for_pickers(json_data):
|
||||
detected_pickers = set()
|
||||
|
||||
@@ -440,10 +466,84 @@ def regional_sampler_seed_update(json_data):
|
||||
server.PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "seed_2nd", "type": "INT", "value": new_seed})
|
||||
|
||||
|
||||
def onprompt_populate_wildcards(json_data):
|
||||
prompt = json_data['prompt']
|
||||
|
||||
updated_widget_values = {}
|
||||
for k, v in prompt.items():
|
||||
if 'class_type' in v and (v['class_type'] == 'ImpactWildcardEncode' or v['class_type'] == 'ImpactWildcardProcessor'):
|
||||
inputs = v['inputs']
|
||||
if inputs['mode'] and isinstance(inputs['populated_text'], str):
|
||||
if isinstance(inputs['seed'], list):
|
||||
try:
|
||||
input_node = prompt[inputs['seed'][0]]
|
||||
if input_node['class_type'] == 'ImpactInt':
|
||||
input_seed = int(input_node['inputs']['value'])
|
||||
if not isinstance(input_seed, int):
|
||||
continue
|
||||
if input_node['class_type'] == 'Seed (rgthree)':
|
||||
input_seed = int(input_node['inputs']['seed'])
|
||||
if not isinstance(input_seed, int):
|
||||
continue
|
||||
else:
|
||||
print(f"[Impact Pack] Only `ImpactInt`, `Seed (rgthree)` and `Primitive` Node are allowed as the seed for '{v['class_type']}'. It will be ignored. ")
|
||||
continue
|
||||
except:
|
||||
continue
|
||||
else:
|
||||
input_seed = int(inputs['seed'])
|
||||
|
||||
inputs['populated_text'] = wildcards.process(inputs['wildcard_text'], input_seed)
|
||||
inputs['mode'] = False
|
||||
|
||||
server.PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "populated_text", "type": "STRING", "value": inputs['populated_text']})
|
||||
updated_widget_values[k] = inputs['populated_text']
|
||||
|
||||
if 'extra_data' in json_data and 'extra_pnginfo' in json_data['extra_data']:
|
||||
for node in json_data['extra_data']['extra_pnginfo']['workflow']['nodes']:
|
||||
key = str(node['id'])
|
||||
if key in updated_widget_values:
|
||||
node['widgets_values'][1] = updated_widget_values[key]
|
||||
node['widgets_values'][2] = False
|
||||
|
||||
|
||||
def onprompt_for_remote(json_data):
|
||||
prompt = json_data['prompt']
|
||||
|
||||
for v in prompt.values():
|
||||
if 'class_type' in v:
|
||||
cls = v['class_type']
|
||||
if cls == 'ImpactRemoteBoolean' or cls == 'ImpactRemoteInt':
|
||||
inputs = v['inputs']
|
||||
node_id = str(inputs['node_id'])
|
||||
|
||||
if node_id not in prompt:
|
||||
continue
|
||||
|
||||
target_inputs = prompt[node_id]['inputs']
|
||||
|
||||
widget_name = inputs['widget_name']
|
||||
if widget_name in target_inputs:
|
||||
widget_type = None
|
||||
if cls == 'ImpactRemoteBoolean' and isinstance(target_inputs[widget_name], bool):
|
||||
widget_type = 'BOOLEAN'
|
||||
|
||||
elif cls == 'ImpactRemoteInt' and (isinstance(target_inputs[widget_name], int) or isinstance(target_inputs[widget_name], float)):
|
||||
widget_type = 'INT'
|
||||
|
||||
if widget_type is None:
|
||||
break
|
||||
|
||||
target_inputs[widget_name] = inputs['value']
|
||||
server.PromptServer.instance.send_sync("impact-node-feedback", {"node_id": node_id, "widget_name": widget_name, "type": widget_type, "value": inputs['value']})
|
||||
|
||||
|
||||
def onprompt(json_data):
|
||||
try:
|
||||
json_data = onprompt_for_switch(json_data)
|
||||
onprompt_for_remote(json_data) # NOTE: top priority
|
||||
onprompt_for_switch(json_data)
|
||||
onprompt_for_pickers(json_data)
|
||||
onprompt_populate_wildcards(json_data)
|
||||
gc_preview_bridge_cache(json_data)
|
||||
workflow_imagereceiver_update(json_data)
|
||||
regional_sampler_seed_update(json_data)
|
||||
|
||||
+231
-22
@@ -7,6 +7,7 @@ import impact.impact_server
|
||||
from server import PromptServer
|
||||
from impact.utils import any_typ
|
||||
import impact.core as core
|
||||
import re
|
||||
|
||||
|
||||
class ImpactCompare:
|
||||
@@ -63,7 +64,7 @@ class ImpactConditionalBranch:
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"cond": ("BOOLEAN", {"forceInput": True}),
|
||||
"cond": ("BOOLEAN",),
|
||||
"tt_value": (any_typ,),
|
||||
"ff_value": (any_typ,),
|
||||
},
|
||||
@@ -81,6 +82,111 @@ class ImpactConditionalBranch:
|
||||
return (ff_value,)
|
||||
|
||||
|
||||
class ImpactConditionalBranchSelMode:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"cond": ("BOOLEAN",),
|
||||
"sel_mode": ("BOOLEAN", {"default": True, "label_on": "select_on_prompt", "label_off": "select_on_execution"}),
|
||||
},
|
||||
"optional": {
|
||||
"tt_value": (any_typ,),
|
||||
"ff_value": (any_typ,),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "doit"
|
||||
CATEGORY = "ImpactPack/Logic"
|
||||
|
||||
RETURN_TYPES = (any_typ, )
|
||||
|
||||
def doit(self, cond, sel_mode, tt_value=None, ff_value=None):
|
||||
print(f'tt={tt_value is None}\nff={ff_value is None}')
|
||||
if cond:
|
||||
return (tt_value,)
|
||||
else:
|
||||
return (ff_value,)
|
||||
|
||||
|
||||
class ImpactConvertDataType:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {"value": (any_typ,)}}
|
||||
|
||||
RETURN_TYPES = ("STRING", "FLOAT", "INT", "BOOLEAN")
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Logic"
|
||||
|
||||
@staticmethod
|
||||
def is_number(string):
|
||||
pattern = re.compile(r'^[-+]?[0-9]*\.?[0-9]+$')
|
||||
return bool(pattern.match(string))
|
||||
|
||||
def doit(self, value):
|
||||
if self.is_number(str(value)):
|
||||
num = value
|
||||
else:
|
||||
if str.lower(str(value)) != "false":
|
||||
num = 1
|
||||
else:
|
||||
num = 0
|
||||
return (str(value), float(num), int(float(num)), bool(float(num)), )
|
||||
|
||||
|
||||
class ImpactIfNone:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {},
|
||||
"optional": {"signal": (any_typ,), "any_input": (any_typ,), }
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ, "BOOLEAN", )
|
||||
RETURN_NAMES = ("signal_opt", "bool")
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Logic"
|
||||
|
||||
def doit(self, signal=None, any_input=None):
|
||||
if any_input is None:
|
||||
return (signal, False, )
|
||||
else:
|
||||
return (signal, True, )
|
||||
|
||||
|
||||
class ImpactLogicalOperators:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"operator": (['and', 'or', 'xor'],),
|
||||
"bool_a": ("BOOLEAN", {"forceInput": True}),
|
||||
"bool_b": ("BOOLEAN", {"forceInput": True}),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "doit"
|
||||
CATEGORY = "ImpactPack/Logic"
|
||||
|
||||
RETURN_TYPES = ("BOOLEAN", )
|
||||
|
||||
def doit(self, operator, bool_a, bool_b):
|
||||
if operator == "and":
|
||||
return (bool_a and bool_b, )
|
||||
elif operator == "or":
|
||||
return (bool_a or bool_b, )
|
||||
else:
|
||||
return (bool_a != bool_b, )
|
||||
|
||||
|
||||
class ImpactConditionalStopIteration:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
@@ -224,7 +330,7 @@ class ImpactValueReceiver:
|
||||
elif typ == "FLOAT":
|
||||
return (float(value), )
|
||||
elif typ == "BOOLEAN":
|
||||
return (bool(value), )
|
||||
return (value.lower() == "true", )
|
||||
else:
|
||||
return (value, )
|
||||
|
||||
@@ -248,6 +354,26 @@ class ImpactImageInfo:
|
||||
return (value.shape[0], value.shape[1], value.shape[2], value.shape[3])
|
||||
|
||||
|
||||
class ImpactLatentInfo:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"value": ("LATENT", ),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Logic/_for_test"
|
||||
|
||||
RETURN_TYPES = ("INT", "INT", "INT", "INT")
|
||||
RETURN_NAMES = ("batch", "height", "width", "channel")
|
||||
|
||||
def doit(self, value):
|
||||
shape = value['samples'].shape
|
||||
return (shape[0], shape[2] * 8, shape[3] * 8, shape[1])
|
||||
|
||||
|
||||
class ImpactMinMax:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
@@ -299,7 +425,9 @@ class ImpactQueueTriggerCountdown:
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"signal": (any_typ,),
|
||||
"count": ("INT", {"default": 10, "min": 0, "max": 0xffffffffffffffff})
|
||||
"count": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"total": ("INT", {"default": 10, "min": 1, "max": 0xffffffffffffffff}),
|
||||
"mode": ("BOOLEAN", {"default": True, "label_on": "Trigger", "label_off": "Don't trigger"}),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"}
|
||||
}
|
||||
@@ -307,17 +435,21 @@ class ImpactQueueTriggerCountdown:
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Logic/_for_test"
|
||||
RETURN_TYPES = (any_typ, "INT")
|
||||
RETURN_NAMES = ("signal_opt", "count")
|
||||
RETURN_TYPES = (any_typ, "INT", "INT")
|
||||
RETURN_NAMES = ("signal_opt", "count", "total")
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def doit(self, signal, count, unique_id):
|
||||
if count > 0:
|
||||
def doit(self, signal, count, total, mode, unique_id):
|
||||
if count < total - 1 and (mode):
|
||||
PromptServer.instance.send_sync("impact-node-feedback",
|
||||
{"node_id": unique_id, "widget_name": "count", "type": "int", "value": count-1})
|
||||
{"node_id": unique_id, "widget_name": "count", "type": "int", "value": count+1})
|
||||
PromptServer.instance.send_sync("impact-add-queue", {})
|
||||
if count >= total - 1:
|
||||
PromptServer.instance.send_sync("impact-node-feedback",
|
||||
{"node_id": unique_id, "widget_name": "count", "type": "int", "value": 0})
|
||||
|
||||
return (signal, count, total)
|
||||
|
||||
return (signal, count)
|
||||
|
||||
|
||||
class ImpactSetWidgetValue:
|
||||
@@ -412,7 +544,7 @@ class ImpactSleep:
|
||||
|
||||
error_skip_flag = False
|
||||
try:
|
||||
import sys
|
||||
import cm_global
|
||||
def filter_message(str):
|
||||
global error_skip_flag
|
||||
|
||||
@@ -424,7 +556,7 @@ try:
|
||||
else:
|
||||
return False
|
||||
|
||||
sys.__comfyui_manager_register_message_collapse(filter_message)
|
||||
cm_global.try_call(api='cm.register_message_collapse', f=filter_message)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[WARN] ComfyUI-Impact-Pack: `ComfyUI` or `ComfyUI-Manager` is an outdated version.")
|
||||
@@ -442,12 +574,50 @@ def workflow_to_map(workflow):
|
||||
return nodes, links
|
||||
|
||||
|
||||
class ImpactRemoteBoolean:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"node_id": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"widget_name": ("STRING", {"multiline": False}),
|
||||
"value": ("BOOLEAN", {"default": True, "label_on": "True", "label_off": "False"}),
|
||||
}}
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Logic/_for_test"
|
||||
RETURN_TYPES = ()
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def doit(self, **kwargs):
|
||||
return {}
|
||||
|
||||
|
||||
class ImpactRemoteInt:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"node_id": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"widget_name": ("STRING", {"multiline": False}),
|
||||
"value": ("INT", {"default": 0, "min": -0xffffffffffffffff, "max": 0xffffffffffffffff}),
|
||||
}}
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Logic/_for_test"
|
||||
RETURN_TYPES = ()
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def doit(self, **kwargs):
|
||||
return {}
|
||||
|
||||
class ImpactControlBridge:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"value": (any_typ,),
|
||||
"mode": ("BOOLEAN", {"default": True, "label_on": "pass", "label_off": "block"}),
|
||||
"mode": ("BOOLEAN", {"default": True, "label_on": "Active", "label_off": "Mute/Bypass"}),
|
||||
"behavior": ("BOOLEAN", {"default": True, "label_on": "Mute", "label_off": "Bypass"}),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID", "prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}
|
||||
}
|
||||
@@ -459,26 +629,65 @@ class ImpactControlBridge:
|
||||
RETURN_NAMES = ("value",)
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def doit(self, value, mode, unique_id, prompt, extra_pnginfo):
|
||||
@classmethod
|
||||
def IS_CHANGED(self, value, mode, behavior=True, unique_id=None, prompt=None, extra_pnginfo=None):
|
||||
nodes, links = workflow_to_map(extra_pnginfo['workflow'])
|
||||
|
||||
next_nodes = []
|
||||
|
||||
for link in nodes[unique_id]['outputs'][0]['links']:
|
||||
node_id = str(links[link][2])
|
||||
impact.utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)
|
||||
|
||||
return next_nodes
|
||||
|
||||
|
||||
def doit(self, value, mode, behavior=True, unique_id=None, prompt=None, extra_pnginfo=None):
|
||||
global error_skip_flag
|
||||
|
||||
nodes, links = workflow_to_map(extra_pnginfo['workflow'])
|
||||
|
||||
outputs = [str(links[link][2]) for link in nodes[unique_id]['outputs'][0]['links']]
|
||||
active_nodes = []
|
||||
mute_nodes = []
|
||||
bypass_nodes = []
|
||||
|
||||
prompt_set = set(prompt.keys())
|
||||
output_set = set(outputs)
|
||||
for link in nodes[unique_id]['outputs'][0]['links']:
|
||||
node_id = str(links[link][2])
|
||||
|
||||
next_nodes = []
|
||||
impact.utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)
|
||||
|
||||
for next_node_id in next_nodes:
|
||||
node_mode = 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:
|
||||
should_active_but_muted = output_set - prompt_set
|
||||
if len(should_active_but_muted) > 0:
|
||||
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'actives': list(should_active_but_muted)})
|
||||
# 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)})
|
||||
error_skip_flag = True
|
||||
raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")
|
||||
|
||||
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)})
|
||||
error_skip_flag = True
|
||||
raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")
|
||||
|
||||
else:
|
||||
should_muted_but_active = prompt_set.intersection(output_set)
|
||||
if len(should_muted_but_active) > 0:
|
||||
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'mutes': list(should_muted_but_active)})
|
||||
# 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)})
|
||||
error_skip_flag = True
|
||||
raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")
|
||||
|
||||
|
||||
@@ -178,7 +178,12 @@ class SegmDetector(BBoxDetector):
|
||||
item = SEG(cropped_image, cropped_mask, confidence, crop_region, item_bbox, None, None)
|
||||
items.append(item)
|
||||
|
||||
return image.shape, items
|
||||
segs = image.shape, items
|
||||
|
||||
if detailer_hook is not None and hasattr(detailer_hook, "post_detection"):
|
||||
segs = detailer_hook.post_detection(segs)
|
||||
|
||||
return segs
|
||||
|
||||
def detect_combined(self, image, threshold, dilation):
|
||||
mmdet_results = inference_bbox(self.bbox_model, image, threshold)
|
||||
|
||||
@@ -13,7 +13,7 @@ class ToDetailerPipe:
|
||||
"bbox_detector": ("BBOX_DETECTOR", ),
|
||||
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
|
||||
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"], ),
|
||||
},
|
||||
"optional": {
|
||||
"sam_model_opt": ("SAM_MODEL",),
|
||||
@@ -51,7 +51,7 @@ class ToDetailerPipeSDXL(ToDetailerPipe):
|
||||
"bbox_detector": ("BBOX_DETECTOR", ),
|
||||
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
|
||||
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
|
||||
},
|
||||
"optional": {
|
||||
"sam_model_opt": ("SAM_MODEL",),
|
||||
@@ -170,7 +170,7 @@ class BasicPipeToDetailerPipe:
|
||||
"bbox_detector": ("BBOX_DETECTOR", ),
|
||||
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
|
||||
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
|
||||
},
|
||||
"optional": {
|
||||
"sam_model_opt": ("SAM_MODEL", ),
|
||||
@@ -206,7 +206,7 @@ class BasicPipeToDetailerPipeSDXL:
|
||||
"bbox_detector": ("BBOX_DETECTOR", ),
|
||||
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
|
||||
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
|
||||
},
|
||||
"optional": {
|
||||
"sam_model_opt": ("SAM_MODEL", ),
|
||||
@@ -305,7 +305,7 @@ class EditDetailerPipe:
|
||||
"detailer_pipe": ("DETAILER_PIPE",),
|
||||
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
|
||||
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
|
||||
},
|
||||
"optional": {
|
||||
"model": ("MODEL",),
|
||||
@@ -402,7 +402,7 @@ class EditDetailerPipeSDXL(EditDetailerPipe):
|
||||
"detailer_pipe": ("DETAILER_PIPE",),
|
||||
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
|
||||
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"] + impact.wildcards.get_wildcard_list(),),
|
||||
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
|
||||
},
|
||||
"optional": {
|
||||
"model": ("MODEL",),
|
||||
|
||||
+648
-152
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,10 @@
|
||||
import time
|
||||
|
||||
import comfy
|
||||
import math
|
||||
import impact.core as core
|
||||
from impact.utils import *
|
||||
from nodes import MAX_RESOLUTION
|
||||
import nodes
|
||||
from impact.impact_sampling import KSamplerWrapper, KSamplerAdvancedWrapper
|
||||
|
||||
|
||||
class TiledKSamplerProvider:
|
||||
@classmethod
|
||||
@@ -57,7 +56,7 @@ class KSamplerProvider:
|
||||
|
||||
def doit(self, seed, steps, cfg, sampler_name, scheduler, denoise, basic_pipe):
|
||||
model, _, _, positive, negative = basic_pipe
|
||||
sampler = core.KSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise)
|
||||
sampler = KSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise)
|
||||
return (sampler, )
|
||||
|
||||
|
||||
@@ -70,6 +69,9 @@ class KSamplerAdvancedProvider:
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"basic_pipe": ("BASIC_PIPE", )
|
||||
},
|
||||
"optional": {
|
||||
"sampler_opt": ("SAMPLER", )
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("KSAMPLER_ADVANCED",)
|
||||
@@ -77,9 +79,9 @@ class KSamplerAdvancedProvider:
|
||||
|
||||
CATEGORY = "ImpactPack/Sampler"
|
||||
|
||||
def doit(self, cfg, sampler_name, scheduler, basic_pipe):
|
||||
def doit(self, cfg, sampler_name, scheduler, basic_pipe, sampler_opt=None):
|
||||
model, _, _, positive, negative = basic_pipe
|
||||
sampler = core.KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative)
|
||||
sampler = KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=sampler_opt)
|
||||
return (sampler, )
|
||||
|
||||
|
||||
@@ -167,10 +169,10 @@ class TwoAdvancedSamplersForMask:
|
||||
return_with_leftover_noise = "enable" if i+1 != adv_steps else "disable"
|
||||
|
||||
new_latent_image['noise_mask'] = inv_mask
|
||||
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image, i, i + 1, "enable", recover_special_sampler=True)
|
||||
new_latent_image = 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, recover_special_sampler=True)
|
||||
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']
|
||||
|
||||
@@ -236,8 +238,42 @@ class CombineConditionings:
|
||||
res += v
|
||||
|
||||
return (res, )
|
||||
|
||||
|
||||
class ConcatConditionings:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"conditioning1": ("CONDITIONING", ),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("CONDITIONING", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, **kwargs):
|
||||
conditioning_to = list(kwargs.values())[0]
|
||||
|
||||
for k, conditioning_from in list(kwargs.items())[1:]:
|
||||
out = []
|
||||
if len(conditioning_from) > 1:
|
||||
print("Warning: ConcatConditionings {k} contains more than 1 cond, only the first one will actually be applied to conditioning1.")
|
||||
|
||||
cond_from = conditioning_from[0][0]
|
||||
|
||||
for i in range(len(conditioning_to)):
|
||||
t1 = conditioning_to[i][0]
|
||||
tw = torch.cat((t1, cond_from), 1)
|
||||
n = [tw, conditioning_to[i][1].copy()]
|
||||
out.append(n)
|
||||
|
||||
conditioning_to = out
|
||||
|
||||
return (out, )
|
||||
|
||||
|
||||
class RegionalSampler:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -253,6 +289,9 @@ class RegionalSampler:
|
||||
"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}),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
@@ -280,7 +319,8 @@ class RegionalSampler:
|
||||
|
||||
return mask_erosion[:, :, :w, :h].round()
|
||||
|
||||
def doit(self, seed, seed_2nd, seed_2nd_mode, steps, base_only_steps, denoise, samples, base_sampler, regional_prompts, overlap_factor, restore_latent, unique_id=None):
|
||||
def doit(self, 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):
|
||||
if restore_latent:
|
||||
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
|
||||
else:
|
||||
@@ -298,12 +338,12 @@ class RegionalSampler:
|
||||
region_len = len(regional_prompts)
|
||||
total = steps*region_len
|
||||
|
||||
leftover_noise = 'disable'
|
||||
leftover_noise = False
|
||||
if base_only_steps > 0:
|
||||
if seed_2nd_mode == 'ignore':
|
||||
leftover_noise = 'enable'
|
||||
leftover_noise = True
|
||||
|
||||
samples = base_sampler.sample_advanced("enable", seed, adv_steps, samples, start_at_step, start_at_step + base_only_steps, leftover_noise, recover_special_sampler=False)
|
||||
samples = base_sampler.sample_advanced(True, seed, adv_steps, samples, start_at_step, start_at_step + base_only_steps, leftover_noise, recovery_mode="DISABLE")
|
||||
|
||||
if seed_2nd_mode == "seed+seed_2nd":
|
||||
seed += seed_2nd
|
||||
@@ -319,16 +359,17 @@ class RegionalSampler:
|
||||
new_latent_image = samples.copy()
|
||||
base_latent_image = None
|
||||
|
||||
if leftover_noise != 'enable':
|
||||
add_noise = "enable"
|
||||
if not leftover_noise:
|
||||
add_noise = True
|
||||
else:
|
||||
add_noise = "disable"
|
||||
add_noise = False
|
||||
|
||||
for i in range(start_at_step+base_only_steps, adv_steps):
|
||||
core.update_node_status(unique_id, f"{i}/{steps} steps | ", ((i-start_at_step)*region_len)/total)
|
||||
|
||||
new_latent_image['noise_mask'] = inv_mask
|
||||
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image, i, i + 1, "enable", recover_special_sampler=True)
|
||||
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image, i, i + 1, True,
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
|
||||
|
||||
if restore_latent:
|
||||
if 'noise_mask' in new_latent_image:
|
||||
@@ -345,8 +386,8 @@ class RegionalSampler:
|
||||
region_mask = regional_prompt.get_mask_erosion(overlap_factor).squeeze(0).squeeze(0)
|
||||
|
||||
new_latent_image['noise_mask'] = region_mask
|
||||
new_latent_image = regional_prompt.sampler.sample_advanced("disable", seed, adv_steps, new_latent_image,
|
||||
i, i + 1, "enable", recover_special_sampler=True)
|
||||
new_latent_image = regional_prompt.sampler.sample_advanced(False, seed, adv_steps, new_latent_image, i, i + 1, True,
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
|
||||
|
||||
if restore_latent:
|
||||
del new_latent_image['noise_mask']
|
||||
@@ -355,7 +396,7 @@ class RegionalSampler:
|
||||
|
||||
j += 1
|
||||
|
||||
add_noise = 'disable'
|
||||
add_noise = False
|
||||
|
||||
# finalize
|
||||
core.update_node_status(unique_id, f"finalize")
|
||||
@@ -365,7 +406,8 @@ class RegionalSampler:
|
||||
base_latent_image = new_latent_image
|
||||
|
||||
new_latent_image['noise_mask'] = inv_mask
|
||||
new_latent_image = base_sampler.sample_advanced("disable", seed, adv_steps, new_latent_image, adv_steps, adv_steps+1, "disable", recover_special_sampler=False)
|
||||
new_latent_image = base_sampler.sample_advanced(False, seed, adv_steps, new_latent_image, adv_steps, adv_steps+1, False,
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
|
||||
|
||||
core.update_node_status(unique_id, f"{steps}/{steps} steps", total)
|
||||
core.update_node_status(unique_id, "", None)
|
||||
@@ -394,6 +436,9 @@ class RegionalSamplerAdvanced:
|
||||
"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}),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
@@ -403,8 +448,9 @@ class RegionalSamplerAdvanced:
|
||||
|
||||
CATEGORY = "ImpactPack/Regional"
|
||||
|
||||
def doit(self, add_noise, noise_seed, steps, start_at_step, end_at_step, overlap_factor, restore_latent,
|
||||
return_with_leftover_noise, latent_image, base_sampler, regional_prompts, unique_id):
|
||||
def doit(self, add_noise, noise_seed, steps, start_at_step, end_at_step, overlap_factor, restore_latent, return_with_leftover_noise, latent_image, base_sampler, regional_prompts,
|
||||
additional_mode, additional_sampler, additional_sigma_ratio, unique_id):
|
||||
|
||||
if restore_latent:
|
||||
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
|
||||
else:
|
||||
@@ -424,13 +470,14 @@ class RegionalSamplerAdvanced:
|
||||
base_latent_image = None
|
||||
region_masks = {}
|
||||
|
||||
for i in range(start_at_step, end_at_step):
|
||||
for i in range(start_at_step, end_at_step-1):
|
||||
core.update_node_status(unique_id, f"{start_at_step+i}/{end_at_step} steps | ", ((i-start_at_step)*region_len)/total)
|
||||
|
||||
cur_add_noise = "enable" if i == start_at_step and add_noise else "disable"
|
||||
cur_add_noise = True if i == start_at_step and add_noise else False
|
||||
|
||||
new_latent_image['noise_mask'] = inv_mask
|
||||
new_latent_image = base_sampler.sample_advanced(cur_add_noise, noise_seed, steps, new_latent_image, i, i + 1, "enable", recover_special_sampler=True)
|
||||
new_latent_image = base_sampler.sample_advanced(cur_add_noise, noise_seed, steps, new_latent_image, i, i + 1, True,
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
|
||||
|
||||
if restore_latent:
|
||||
del new_latent_image['noise_mask']
|
||||
@@ -450,8 +497,8 @@ class RegionalSamplerAdvanced:
|
||||
region_mask = region_masks[j]
|
||||
|
||||
new_latent_image['noise_mask'] = region_mask
|
||||
new_latent_image = regional_prompt.sampler.sample_advanced("disable", noise_seed, steps, new_latent_image,
|
||||
i, i + 1, "enable", recover_special_sampler=True)
|
||||
new_latent_image = regional_prompt.sampler.sample_advanced(False, noise_seed, steps, new_latent_image, i, i + 1, True,
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
|
||||
|
||||
if restore_latent:
|
||||
del new_latent_image['noise_mask']
|
||||
@@ -468,7 +515,8 @@ class RegionalSamplerAdvanced:
|
||||
base_latent_image = new_latent_image
|
||||
|
||||
new_latent_image['noise_mask'] = inv_mask
|
||||
new_latent_image = base_sampler.sample_advanced("disable", noise_seed, steps, new_latent_image, end_at_step, end_at_step+1, return_with_leftover_noise, recover_special_sampler=False)
|
||||
new_latent_image = base_sampler.sample_advanced(False, noise_seed, steps, new_latent_image, end_at_step-1, end_at_step, return_with_leftover_noise,
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
|
||||
|
||||
core.update_node_status(unique_id, f"{end_at_step}/{end_at_step} steps", total)
|
||||
core.update_node_status(unique_id, "", None)
|
||||
@@ -505,7 +553,7 @@ class KSamplerBasicPipe:
|
||||
def sample(self, basic_pipe, seed, steps, cfg, sampler_name, scheduler, latent_image, denoise=1.0):
|
||||
model, clip, vae, positive, negative = basic_pipe
|
||||
latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)[0]
|
||||
return (basic_pipe, latent, vae)
|
||||
return basic_pipe, latent, vae
|
||||
|
||||
|
||||
class KSamplerAdvancedBasicPipe:
|
||||
@@ -545,4 +593,5 @@ class KSamplerAdvancedBasicPipe:
|
||||
return_with_leftover_noise = "disable"
|
||||
|
||||
latent = nodes.KSamplerAdvanced().sample(model, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise)[0]
|
||||
return (basic_pipe, latent, vae)
|
||||
return basic_pipe, latent, vae
|
||||
|
||||
|
||||
+301
-15
@@ -1,6 +1,11 @@
|
||||
from impact.utils import any_typ
|
||||
from impact.utils import any_typ, ByPassTypeTuple, make_3d_mask
|
||||
import comfy_extras.nodes_mask
|
||||
from nodes import MAX_RESOLUTION
|
||||
import torch
|
||||
import comfy
|
||||
import sys
|
||||
import nodes
|
||||
|
||||
|
||||
class GeneralSwitch:
|
||||
@classmethod
|
||||
@@ -45,31 +50,31 @@ class GeneralSwitch:
|
||||
return (None, "", selected_index)
|
||||
|
||||
|
||||
class GeneralInversedSwitch:
|
||||
class LatentSwitch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
|
||||
"input": (any_typ,),
|
||||
"select": ("INT", {"default": 1, "min": 1, "max": 99999, "step": 1}),
|
||||
"latent1": ("LATENT",),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = tuple([any_typ] * 100)
|
||||
RETURN_TYPES = ("LATENT", )
|
||||
|
||||
OUTPUT_NODE = True
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, select, input, unique_id):
|
||||
res = []
|
||||
def doit(self, *args, **kwargs):
|
||||
input_name = f"latent{int(kwargs['select'])}"
|
||||
|
||||
for i in range(0, select):
|
||||
if select == i+1:
|
||||
res.append(input)
|
||||
else:
|
||||
res.append(None)
|
||||
|
||||
return res
|
||||
if input_name in kwargs:
|
||||
return (kwargs[input_name],)
|
||||
else:
|
||||
print(f"LatentSwitch: invalid select index ('latent1' is selected)")
|
||||
return (kwargs['latent1'],)
|
||||
|
||||
|
||||
class ImageMaskSwitch:
|
||||
@@ -92,6 +97,9 @@ class ImageMaskSwitch:
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "MASK",)
|
||||
|
||||
OUTPUT_NODE = True
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
@@ -108,6 +116,33 @@ class ImageMaskSwitch:
|
||||
return images4_opt, mask4_opt,
|
||||
|
||||
|
||||
class GeneralInversedSwitch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
|
||||
"input": (any_typ,),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ByPassTypeTuple((any_typ, ))
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, select, input, unique_id):
|
||||
res = []
|
||||
|
||||
for i in range(0, select):
|
||||
if select == i+1:
|
||||
res.append(input)
|
||||
else:
|
||||
res.append(None)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
class RemoveNoiseMask:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -199,3 +234,254 @@ class ImpactDummyInput:
|
||||
|
||||
def doit(self):
|
||||
return ("DUMMY",)
|
||||
|
||||
|
||||
class MasksToMaskList:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"masks": ("MASK", ),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MASK", )
|
||||
OUTPUT_IS_LIST = (True, )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Operation"
|
||||
|
||||
def doit(self, masks):
|
||||
if masks is None:
|
||||
empty_mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
|
||||
return ([empty_mask], )
|
||||
|
||||
res = []
|
||||
|
||||
for mask in masks:
|
||||
res.append(mask)
|
||||
|
||||
print(f"mask len: {len(res)}")
|
||||
|
||||
res = [make_3d_mask(x) for x in res]
|
||||
|
||||
return (res, )
|
||||
|
||||
|
||||
class MaskListToMaskBatch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"mask": ("MASK", ),
|
||||
}
|
||||
}
|
||||
|
||||
INPUT_IS_LIST = True
|
||||
|
||||
RETURN_TYPES = ("MASK", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Operation"
|
||||
|
||||
def doit(self, mask):
|
||||
if len(mask) == 1:
|
||||
mask = make_3d_mask(mask[0])
|
||||
return (mask,)
|
||||
elif len(mask) > 1:
|
||||
mask1 = make_3d_mask(mask[0])
|
||||
|
||||
for mask2 in mask[1:]:
|
||||
mask2 = make_3d_mask(mask2)
|
||||
if mask1.shape[1:] != mask2.shape[1:]:
|
||||
mask2 = comfy.utils.common_upscale(mask2.movedim(-1, 1), mask1.shape[2], mask1.shape[1], "lanczos", "center").movedim(1, -1)
|
||||
mask1 = torch.cat((mask1, mask2), dim=0)
|
||||
|
||||
return (mask1,)
|
||||
else:
|
||||
empty_mask = torch.zeros((1, 64, 64), dtype=torch.float32, device="cpu").unsqueeze(0)
|
||||
return (empty_mask,)
|
||||
|
||||
|
||||
class ImageListToImageBatch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"images": ("IMAGE", ),
|
||||
}
|
||||
}
|
||||
|
||||
INPUT_IS_LIST = True
|
||||
|
||||
RETURN_TYPES = ("IMAGE", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Operation"
|
||||
|
||||
def doit(self, images):
|
||||
if len(images) <= 1:
|
||||
return (images,)
|
||||
else:
|
||||
image1 = images[0]
|
||||
for image2 in images[1:]:
|
||||
if image1.shape[1:] != image2.shape[1:]:
|
||||
image2 = comfy.utils.common_upscale(image2.movedim(-1, 1), image1.shape[2], image1.shape[1], "lanczos", "center").movedim(1, -1)
|
||||
image1 = torch.cat((image1, image2), dim=0)
|
||||
return (image1,)
|
||||
|
||||
|
||||
class ImageBatchToImageList:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {"image": ("IMAGE",), }}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
OUTPUT_IS_LIST = (True,)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, image):
|
||||
images = [image[i:i + 1, ...] for i in range(image.shape[0])]
|
||||
return (images, )
|
||||
|
||||
|
||||
class MakeImageList:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {"image1": ("IMAGE",), }}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
OUTPUT_IS_LIST = (True,)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, **kwargs):
|
||||
images = []
|
||||
|
||||
for k, v in kwargs.items():
|
||||
images.append(v)
|
||||
|
||||
return (images, )
|
||||
|
||||
|
||||
class MakeImageBatch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {"image1": ("IMAGE",), }}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, **kwargs):
|
||||
image1 = kwargs['image1']
|
||||
del kwargs['image1']
|
||||
images = [value for value in kwargs.values()]
|
||||
|
||||
if len(images) == 0:
|
||||
return (image1,)
|
||||
else:
|
||||
for image2 in images:
|
||||
if image1.shape[1:] != image2.shape[1:]:
|
||||
image2 = comfy.utils.common_upscale(image2.movedim(-1, 1), image1.shape[2], image1.shape[1], "lanczos", "center").movedim(1, -1)
|
||||
image1 = torch.cat((image1, image2), dim=0)
|
||||
return (image1,)
|
||||
|
||||
|
||||
class ReencodeLatent:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"samples": ("LATENT", ),
|
||||
"tile_mode": (["None", "Both", "Decode(input) only", "Encode(output) only"],),
|
||||
"input_vae": ("VAE", ),
|
||||
"output_vae": ("VAE", ),
|
||||
"tile_size": ("INT", {"default": 512, "min": 320, "max": 4096, "step": 64}),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
RETURN_TYPES = ("LATENT", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
def doit(self, samples, tile_mode, input_vae, output_vae, tile_size=512):
|
||||
if tile_mode in ["Both", "Decode(input) only"]:
|
||||
pixels = nodes.VAEDecodeTiled().decode(input_vae, samples, tile_size)[0]
|
||||
else:
|
||||
pixels = nodes.VAEDecode().decode(input_vae, samples)[0]
|
||||
|
||||
if tile_mode in ["Both", "Encode(output) only"]:
|
||||
return nodes.VAEEncodeTiled().encode(output_vae, pixels, tile_size)
|
||||
else:
|
||||
return nodes.VAEEncode().encode(output_vae, pixels)
|
||||
|
||||
|
||||
class ReencodeLatentPipe:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"samples": ("LATENT", ),
|
||||
"tile_mode": (["None", "Both", "Decode(input) only", "Encode(output) only"],),
|
||||
"input_basic_pipe": ("BASIC_PIPE", ),
|
||||
"output_basic_pipe": ("BASIC_PIPE", ),
|
||||
},
|
||||
}
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
RETURN_TYPES = ("LATENT", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
def doit(self, samples, tile_mode, input_basic_pipe, output_basic_pipe):
|
||||
_, _, input_vae, _, _ = input_basic_pipe
|
||||
_, _, output_vae, _, _ = output_basic_pipe
|
||||
return ReencodeLatent().doit(samples, tile_mode, input_vae, output_vae)
|
||||
|
||||
|
||||
class StringSelector:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"strings": ("STRING", {"multiline": True}),
|
||||
"multiline": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"select": ("INT", {"min": 0, "max": sys.maxsize, "step": 1, "default": 0}),
|
||||
}}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, strings, multiline, select):
|
||||
lines = strings.split('\n')
|
||||
|
||||
if multiline:
|
||||
result = []
|
||||
current_string = ""
|
||||
|
||||
for line in lines:
|
||||
if line.startswith("#"):
|
||||
if current_string:
|
||||
result.append(current_string.strip())
|
||||
current_string = ""
|
||||
current_string += line + "\n"
|
||||
|
||||
if current_string:
|
||||
result.append(current_string.strip())
|
||||
|
||||
if len(result) == 0:
|
||||
selected = strings
|
||||
else:
|
||||
selected = result[select % len(result)]
|
||||
|
||||
if selected.startswith('#'):
|
||||
selected = selected[1:]
|
||||
else:
|
||||
if len(lines) == 0:
|
||||
selected = strings
|
||||
else:
|
||||
selected = lines[select % len(lines)]
|
||||
|
||||
return (selected, )
|
||||
|
||||
+345
-35
@@ -1,23 +1,208 @@
|
||||
import torch
|
||||
import torchvision
|
||||
import cv2
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFilter
|
||||
import folder_paths
|
||||
import nodes
|
||||
from . import config
|
||||
from PIL import Image, ImageFilter
|
||||
from scipy.ndimage import zoom
|
||||
import comfy
|
||||
|
||||
|
||||
class TensorBatchBuilder:
|
||||
def __init__(self):
|
||||
self.tensor = None
|
||||
|
||||
def concat(self, new_tensor):
|
||||
if self.tensor is None:
|
||||
self.tensor = new_tensor
|
||||
else:
|
||||
self.tensor = torch.concat((self.tensor, new_tensor), dim=0)
|
||||
|
||||
|
||||
def tensor_convert_rgba(image, prefer_copy=True):
|
||||
"""Assumes NHWC format tensor with 1, 3 or 4 channels."""
|
||||
_tensor_check_image(image)
|
||||
n_channel = image.shape[-1]
|
||||
if n_channel == 4:
|
||||
return image
|
||||
|
||||
if n_channel == 3:
|
||||
alpha = torch.ones((*image.shape[:-1], 1))
|
||||
return torch.cat((image, alpha), axis=-1)
|
||||
|
||||
if n_channel == 1:
|
||||
if prefer_copy:
|
||||
image = image.repeat(1, -1, -1, 4)
|
||||
else:
|
||||
image = image.expand(1, -1, -1, 3)
|
||||
return image
|
||||
|
||||
# NOTE: Similar error message as in PIL, for easier googling :P
|
||||
raise ValueError(f"illegal conversion (channels: {n_channel} -> 4)")
|
||||
|
||||
|
||||
def tensor_convert_rgb(image, prefer_copy=True):
|
||||
"""Assumes NHWC format tensor with 1, 3 or 4 channels."""
|
||||
_tensor_check_image(image)
|
||||
n_channel = image.shape[-1]
|
||||
if n_channel == 3:
|
||||
return image
|
||||
|
||||
if n_channel == 4:
|
||||
image = image[..., :3]
|
||||
if prefer_copy:
|
||||
image = image.copy()
|
||||
return image
|
||||
|
||||
if n_channel == 1:
|
||||
if prefer_copy:
|
||||
image = image.repeat(1, -1, -1, 4)
|
||||
else:
|
||||
image = image.expand(1, -1, -1, 3)
|
||||
return image
|
||||
|
||||
# NOTE: Same error message as in PIL, for easier googling :P
|
||||
raise ValueError(f"illegal conversion (channels: {n_channel} -> 3)")
|
||||
|
||||
|
||||
def general_tensor_resize(image, w: int, h: int):
|
||||
_tensor_check_image(image)
|
||||
image = image.permute(0, 3, 1, 2)
|
||||
image = torch.nn.functional.interpolate(image, size=(h, w), mode="bilinear")
|
||||
image = image.permute(0, 2, 3, 1)
|
||||
return image
|
||||
|
||||
|
||||
# TODO: Sadly, we need LANCZOS
|
||||
LANCZOS = (Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS)
|
||||
def tensor_resize(image, w: int, h: int):
|
||||
_tensor_check_image(image)
|
||||
if image.shape[3] >= 3:
|
||||
scaled_images = TensorBatchBuilder()
|
||||
for single_image in image:
|
||||
single_image = single_image.unsqueeze(0)
|
||||
single_pil = tensor2pil(single_image)
|
||||
scaled_pil = single_pil.resize((w, h), resample=LANCZOS)
|
||||
|
||||
single_image = pil2tensor(scaled_pil)
|
||||
scaled_images.concat(single_image)
|
||||
|
||||
return scaled_images.tensor
|
||||
else:
|
||||
return general_tensor_resize(image, w, h)
|
||||
|
||||
|
||||
def pil2numpy(image):
|
||||
return (np.array(image).astype(np.float32) / 255.0)[np.newaxis, :, :, :]
|
||||
def tensor_get_size(image):
|
||||
"""Mimicking `PIL.Image.size`"""
|
||||
_tensor_check_image(image)
|
||||
_, h, w, _ = image.shape
|
||||
return (w, h)
|
||||
|
||||
|
||||
def tensor2pil(image):
|
||||
_tensor_check_image(image)
|
||||
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(0), 0, 255).astype(np.uint8))
|
||||
|
||||
|
||||
def pil2tensor(image):
|
||||
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)
|
||||
|
||||
|
||||
def tensor2pil(image):
|
||||
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))
|
||||
def numpy2pil(image):
|
||||
return Image.fromarray(np.clip(255. * image.squeeze(0), 0, 255).astype(np.uint8))
|
||||
|
||||
|
||||
def to_pil(image):
|
||||
if isinstance(image, Image.Image):
|
||||
return image
|
||||
if isinstance(image, torch.Tensor):
|
||||
return tensor2pil(image)
|
||||
if isinstance(image, np.ndarray):
|
||||
return numpy2pil(image)
|
||||
raise ValueError(f"Cannot convert {type(image)} to PIL.Image")
|
||||
|
||||
|
||||
def to_tensor(image):
|
||||
if isinstance(image, Image.Image):
|
||||
return torch.from_numpy(np.array(image))
|
||||
if isinstance(image, torch.Tensor):
|
||||
return image
|
||||
if isinstance(image, np.ndarray):
|
||||
return torch.from_numpy(image)
|
||||
raise ValueError(f"Cannot convert {type(image)} to torch.Tensor")
|
||||
|
||||
|
||||
def to_numpy(image):
|
||||
if isinstance(image, Image.Image):
|
||||
return np.array(image)
|
||||
if isinstance(image, torch.Tensor):
|
||||
return image.numpy()
|
||||
if isinstance(image, np.ndarray):
|
||||
return image
|
||||
raise ValueError(f"Cannot convert {type(image)} to numpy.ndarray")
|
||||
|
||||
|
||||
|
||||
def tensor_putalpha(image, mask):
|
||||
_tensor_check_image(image)
|
||||
_tensor_check_mask(mask)
|
||||
image[..., -1] = mask[..., 0]
|
||||
|
||||
|
||||
def _tensor_check_image(image):
|
||||
if image.ndim != 4:
|
||||
raise ValueError(f"Expected NHWC tensor, but found {image.ndim} dimensions")
|
||||
if image.shape[-1] not in (1, 3, 4):
|
||||
raise ValueError(f"Expected 1, 3 or 4 channels for image, but found {image.shape[-1]} channels")
|
||||
return
|
||||
|
||||
|
||||
def _tensor_check_mask(mask):
|
||||
if mask.ndim != 4:
|
||||
raise ValueError(f"Expected NHWC tensor, but found {mask.ndim} dimensions")
|
||||
if mask.shape[-1] != 1:
|
||||
raise ValueError(f"Expected 1 channel for mask, but found {mask.shape[-1]} channels")
|
||||
return
|
||||
|
||||
|
||||
def tensor_crop(image, crop_region):
|
||||
_tensor_check_image(image)
|
||||
return crop_ndarray4(image, crop_region)
|
||||
|
||||
|
||||
def tensor2numpy(image):
|
||||
_tensor_check_image(image)
|
||||
return image.numpy()
|
||||
|
||||
|
||||
def tensor_paste(image1, image2, left_top, mask):
|
||||
"""Mask and image2 has to be the same size"""
|
||||
_tensor_check_image(image1)
|
||||
_tensor_check_image(image2)
|
||||
_tensor_check_mask(mask)
|
||||
if image2.shape[1:3] != mask.shape[1:3]:
|
||||
raise ValueError(f"Inconsistent size: Image ({image2.shape[1:3]}) != Mask ({mask.shape[1:3]})")
|
||||
|
||||
x, y = left_top
|
||||
_, h1, w1, _ = image1.shape
|
||||
_, h2, w2, _ = image2.shape
|
||||
|
||||
# calculate image patch size
|
||||
w = min(w1, x + w2) - x
|
||||
h = min(h1, y + h2) - y
|
||||
|
||||
# If the patch is out of bound, nothing to do!
|
||||
if w <= 0 or h <= 0:
|
||||
return
|
||||
|
||||
mask = mask[:, :h, :w, :]
|
||||
image1[:, y:y+h, x:x+w, :] = (
|
||||
(1 - mask) * image1[:, y:y+h, x:x+w, :] +
|
||||
mask * image2[:, :h, :w, :]
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
def center_of_bbox(bbox):
|
||||
@@ -80,8 +265,7 @@ def bitwise_and_masks(mask1, mask2):
|
||||
|
||||
|
||||
def to_binary_mask(mask, threshold=0):
|
||||
if len(mask.shape) == 3:
|
||||
mask = mask.squeeze(0)
|
||||
mask = make_3d_mask(mask)
|
||||
|
||||
mask = mask.clone().cpu()
|
||||
mask[mask > threshold] = 1.
|
||||
@@ -95,10 +279,9 @@ def use_gpu_opencv():
|
||||
|
||||
def dilate_mask(mask, dilation_factor, iter=1):
|
||||
if dilation_factor == 0:
|
||||
return mask
|
||||
return make_2d_mask(mask)
|
||||
|
||||
if len(mask.shape) == 3:
|
||||
mask = mask.squeeze(0)
|
||||
mask = make_2d_mask(mask)
|
||||
|
||||
kernel = np.ones((abs(dilation_factor), abs(dilation_factor)), np.uint8)
|
||||
|
||||
@@ -146,15 +329,65 @@ def dilate_masks(segmasks, dilation_factor, iter=1):
|
||||
|
||||
return dilated_masks
|
||||
|
||||
import torch.nn.functional as F
|
||||
def feather_mask(mask, thickness):
|
||||
mask = mask.permute(0, 3, 1, 2)
|
||||
|
||||
def feather_mask(mask, thickness, base_alpha=255):
|
||||
pil_mask = Image.fromarray(np.uint8(mask * base_alpha))
|
||||
# Gaussian kernel for blurring
|
||||
kernel_size = 2 * int(thickness) + 1
|
||||
sigma = thickness / 3 # Adjust the sigma value as needed
|
||||
blur_kernel = _gaussian_kernel(kernel_size, sigma).to(mask.device, mask.dtype)
|
||||
|
||||
# Create a feathered mask by applying a Gaussian blur to the mask
|
||||
blurred_mask = pil_mask.filter(ImageFilter.GaussianBlur(thickness))
|
||||
feathered_mask = Image.new("L", pil_mask.size, 0)
|
||||
feathered_mask.paste(blurred_mask, (0, 0), blurred_mask)
|
||||
return feathered_mask
|
||||
# Apply blur to the mask
|
||||
blurred_mask = F.conv2d(mask, blur_kernel.unsqueeze(0).unsqueeze(0), padding=thickness)
|
||||
|
||||
blurred_mask = blurred_mask.permute(0, 2, 3, 1)
|
||||
|
||||
return blurred_mask
|
||||
|
||||
def _gaussian_kernel(kernel_size, sigma):
|
||||
# Generate a 1D Gaussian kernel
|
||||
kernel = torch.exp(-(torch.arange(kernel_size) - kernel_size // 2)**2 / (2 * sigma**2))
|
||||
return kernel / kernel.sum()
|
||||
|
||||
|
||||
def tensor_gaussian_blur_mask(mask, kernel_size, sigma=10.0):
|
||||
"""Return NHWC torch.Tenser from ndim == 2 or 4 `np.ndarray` or `torch.Tensor`"""
|
||||
if isinstance(mask, np.ndarray):
|
||||
mask = torch.from_numpy(mask)
|
||||
|
||||
if mask.ndim == 2:
|
||||
mask = mask[None, ..., None]
|
||||
elif mask.ndim == 3:
|
||||
mask = mask[..., None]
|
||||
|
||||
_tensor_check_mask(mask)
|
||||
|
||||
if kernel_size <= 0:
|
||||
return mask
|
||||
|
||||
kernel_size = kernel_size*2+1
|
||||
|
||||
shortest = min(mask.shape[1], mask.shape[2])
|
||||
if shortest <= kernel_size:
|
||||
kernel_size = int(shortest/2)
|
||||
if kernel_size % 2 == 0:
|
||||
kernel_size += 1
|
||||
if kernel_size < 3:
|
||||
return mask # skip feathering
|
||||
|
||||
prev_device = mask.device
|
||||
device = comfy.model_management.get_torch_device()
|
||||
mask.to(device)
|
||||
|
||||
# apply gaussian blur
|
||||
mask = mask[:, None, ..., 0]
|
||||
blurred_mask = torchvision.transforms.GaussianBlur(kernel_size=kernel_size, sigma=sigma)(mask)
|
||||
blurred_mask = blurred_mask[:, 0, ..., None]
|
||||
|
||||
blurred_mask.to(prev_device)
|
||||
|
||||
return blurred_mask
|
||||
|
||||
|
||||
def subtract_masks(mask1, mask2):
|
||||
@@ -239,6 +472,9 @@ def crop_ndarray4(npimg, crop_region):
|
||||
return cropped
|
||||
|
||||
|
||||
crop_tensor4 = crop_ndarray4
|
||||
|
||||
|
||||
def crop_ndarray2(npimg, crop_region):
|
||||
x1 = crop_region[0]
|
||||
y1 = crop_region[1]
|
||||
@@ -251,7 +487,7 @@ def crop_ndarray2(npimg, crop_region):
|
||||
|
||||
|
||||
def crop_image(image, crop_region):
|
||||
return crop_ndarray4(np.array(image), crop_region)
|
||||
return crop_tensor4(image, crop_region)
|
||||
|
||||
|
||||
def to_latent_image(pixels, vae):
|
||||
@@ -259,26 +495,101 @@ def to_latent_image(pixels, vae):
|
||||
y = pixels.shape[2]
|
||||
if pixels.shape[1] != x or pixels.shape[2] != y:
|
||||
pixels = pixels[:, :x, :y, :]
|
||||
pixels = nodes.VAEEncode.vae_encode_crop_pixels(pixels)
|
||||
t = vae.encode(pixels[:, :, :, :3])
|
||||
return {"samples": t}
|
||||
|
||||
|
||||
def scale_tensor(w, h, image):
|
||||
image = tensor2pil(image)
|
||||
scaled_image = image.resize((w, h), resample=LANCZOS)
|
||||
return pil2tensor(scaled_image)
|
||||
|
||||
|
||||
def scale_tensor_and_to_pil(w, h, image):
|
||||
image = tensor2pil(image)
|
||||
return image.resize((w, h), resample=LANCZOS)
|
||||
|
||||
|
||||
def empty_pil_tensor(w=64, h=64):
|
||||
image = Image.new("RGB", (w, h))
|
||||
draw = ImageDraw.Draw(image)
|
||||
draw.rectangle((0, 0, w-1, h-1), fill=(0, 0, 0))
|
||||
return pil2tensor(image)
|
||||
return torch.zeros((1, h, w, 3), dtype=torch.float32)
|
||||
|
||||
|
||||
def make_2d_mask(mask):
|
||||
if len(mask.shape) == 4:
|
||||
return mask.squeeze(0).squeeze(0)
|
||||
|
||||
elif len(mask.shape) == 3:
|
||||
return mask.squeeze(0)
|
||||
|
||||
return mask
|
||||
|
||||
|
||||
def make_3d_mask(mask):
|
||||
if len(mask.shape) == 4:
|
||||
return mask.squeeze(0)
|
||||
|
||||
elif len(mask.shape) == 2:
|
||||
return mask.unsqueeze(0)
|
||||
|
||||
return mask
|
||||
|
||||
|
||||
def get_mask_size(mask):
|
||||
if len(mask.shape) == 2:
|
||||
return mask.shape[1], mask.shape[0]
|
||||
elif len(mask.shape) == 3:
|
||||
return mask.shape[2], mask.shape[1]
|
||||
elif len(mask.shape) == 4:
|
||||
return mask.shape[3], mask.shape[2]
|
||||
|
||||
raise Exception("unexpected mask dimension")
|
||||
|
||||
|
||||
def is_same_device(a, b):
|
||||
a_device = torch.device(a) if isinstance(a, str) else a
|
||||
b_device = torch.device(b) if isinstance(b, str) else b
|
||||
return a_device.type == b_device.type and a_device.index == b_device.index
|
||||
|
||||
|
||||
def collect_non_reroute_nodes(node_map, links, res, node_id):
|
||||
if node_map[node_id]['type'] != 'Reroute' and node_map[node_id]['type'] != 'Reroute (rgthree)':
|
||||
res.append(node_id)
|
||||
else:
|
||||
for link in node_map[node_id]['outputs'][0]['links']:
|
||||
next_node_id = str(links[link][2])
|
||||
collect_non_reroute_nodes(node_map, links, res, next_node_id)
|
||||
|
||||
|
||||
from torchvision.transforms.functional import to_pil_image
|
||||
|
||||
|
||||
def resize_mask(mask, size):
|
||||
resized_mask = torch.nn.functional.interpolate(mask.unsqueeze(0), size=size, mode='bilinear', align_corners=False)
|
||||
return resized_mask.squeeze(0)
|
||||
|
||||
|
||||
def apply_mask_alpha_to_pil(decoded_pil, mask):
|
||||
decoded_rgba = decoded_pil.convert('RGBA')
|
||||
mask_pil = to_pil_image(mask)
|
||||
decoded_rgba.putalpha(mask_pil)
|
||||
|
||||
return decoded_rgba
|
||||
|
||||
|
||||
def try_install_custom_node(custom_node_url, msg):
|
||||
try:
|
||||
import cm_global
|
||||
cm_global.try_call(api='cm.try-install-custom-node',
|
||||
sender="Impact Pack", custom_node_url=custom_node_url, msg=msg)
|
||||
except Exception:
|
||||
print(msg)
|
||||
print(f"[Impact Pack] ComfyUI-Manager is outdated. The custom node installation feature is not available.")
|
||||
|
||||
|
||||
# author: Trung0246 --->
|
||||
class TautologyStr(str):
|
||||
def __ne__(self, other):
|
||||
return False
|
||||
|
||||
|
||||
class ByPassTypeTuple(tuple):
|
||||
def __getitem__(self, index):
|
||||
if index > 0:
|
||||
index = 0
|
||||
item = super().__getitem__(index)
|
||||
if isinstance(item, str):
|
||||
return TautologyStr(item)
|
||||
return item
|
||||
|
||||
|
||||
class NonListIterable:
|
||||
@@ -289,7 +600,6 @@ class NonListIterable:
|
||||
return self.data[index]
|
||||
|
||||
|
||||
# author: Trung0246
|
||||
def add_folder_path_and_extensions(folder_name, full_folder_paths, extensions):
|
||||
# Iterate over the list of full folder paths
|
||||
for full_folder_path in full_folder_paths:
|
||||
@@ -309,7 +619,7 @@ def add_folder_path_and_extensions(folder_name, full_folder_paths, extensions):
|
||||
# Now we just need to update the set of extensions as it would be an empty set
|
||||
# Also ensure that all paths are included (since add_model_folder_path adds only one path at a time)
|
||||
folder_paths.folder_names_and_paths[folder_name] = (full_folder_paths, extensions)
|
||||
|
||||
# <---
|
||||
|
||||
# wildcard trick is taken from pythongossss's
|
||||
class AnyType(str):
|
||||
|
||||
+87
-37
@@ -4,12 +4,24 @@ import os
|
||||
import nodes
|
||||
import folder_paths
|
||||
import yaml
|
||||
import numpy as np
|
||||
import threading
|
||||
from impact import utils
|
||||
|
||||
|
||||
wildcard_lock = threading.Lock()
|
||||
wildcard_dict = {}
|
||||
|
||||
|
||||
def get_wildcard_list():
|
||||
return [f"__{x}__" for x in wildcard_dict.keys()]
|
||||
with wildcard_lock:
|
||||
return [f"__{x}__" for x in wildcard_dict.keys()]
|
||||
|
||||
|
||||
def get_wildcard_dict():
|
||||
global wildcard_dict
|
||||
with wildcard_lock:
|
||||
return wildcard_dict
|
||||
|
||||
|
||||
def wildcard_normalize(x):
|
||||
@@ -58,6 +70,7 @@ def read_wildcard_dict(wildcard_path):
|
||||
def process(text, seed=None):
|
||||
if seed is not None:
|
||||
random.seed(seed)
|
||||
random_gen = np.random.default_rng(seed)
|
||||
|
||||
def replace_options(string):
|
||||
replacements_found = False
|
||||
@@ -81,10 +94,9 @@ def process(text, seed=None):
|
||||
b = r.group(1).strip()
|
||||
else:
|
||||
a = r.group(1).strip()
|
||||
try:
|
||||
b = r.group(3).strip()
|
||||
except:
|
||||
b = None
|
||||
b = r.group(3)
|
||||
if b is not None:
|
||||
b = b.strip()
|
||||
|
||||
if r is not None:
|
||||
if b is not None and is_numeric_string(a) and is_numeric_string(b):
|
||||
@@ -122,20 +134,13 @@ def process(text, seed=None):
|
||||
if select_range is None:
|
||||
select_count = 1
|
||||
else:
|
||||
select_count = random.randint(select_range[0], select_range[1])
|
||||
select_count = random_gen.integers(low=select_range[0], high=select_range[1]+1, size=1)
|
||||
|
||||
if select_count > len(options):
|
||||
random_gen.shuffle(options)
|
||||
selected_items = options
|
||||
else:
|
||||
selected_items = random.choices(options, weights=normalized_probabilities, k=select_count)
|
||||
selected_items = set(selected_items)
|
||||
|
||||
try_count = 0
|
||||
while len(selected_items) < select_count and try_count < 10:
|
||||
remaining_count = select_count - len(selected_items)
|
||||
additional_items = random.choices(options, weights=normalized_probabilities, k=remaining_count)
|
||||
selected_items |= set(additional_items)
|
||||
try_count += 1
|
||||
selected_items = random_gen.choice(options, p=normalized_probabilities, size=select_count, replace=False)
|
||||
|
||||
selected_items2 = [re.sub(r'^\s*[0-9.]+::', '', x, 1) for x in selected_items]
|
||||
replacement = select_sep.join(selected_items2)
|
||||
@@ -151,7 +156,7 @@ def process(text, seed=None):
|
||||
return replaced_string, replacements_found
|
||||
|
||||
def replace_wildcard(string):
|
||||
global wildcard_dict
|
||||
local_wildcard_dict = get_wildcard_dict()
|
||||
pattern = r"__([\w.\-+/*\\]+)__"
|
||||
matches = re.findall(pattern, string)
|
||||
|
||||
@@ -160,21 +165,21 @@ def process(text, seed=None):
|
||||
for match in matches:
|
||||
keyword = match.lower()
|
||||
keyword = wildcard_normalize(keyword)
|
||||
if keyword in wildcard_dict:
|
||||
replacement = random.choice(wildcard_dict[keyword])
|
||||
if keyword in local_wildcard_dict:
|
||||
replacement = random_gen.choice(local_wildcard_dict[keyword])
|
||||
replacements_found = True
|
||||
string = string.replace(f"__{match}__", replacement, 1)
|
||||
elif '*' in keyword:
|
||||
subpattern = keyword.replace('*', '.*').replace('+','\+')
|
||||
total_patterns = []
|
||||
found = False
|
||||
for k, v in wildcard_dict.items():
|
||||
for k, v in local_wildcard_dict.items():
|
||||
if re.match(subpattern, k) is not None:
|
||||
total_patterns += v
|
||||
found = True
|
||||
|
||||
if found:
|
||||
replacement = random.choice(total_patterns)
|
||||
replacement = random_gen.choice(total_patterns)
|
||||
replacements_found = True
|
||||
string = string.replace(f"__{match}__", replacement, 1)
|
||||
elif '/' not in keyword:
|
||||
@@ -254,7 +259,7 @@ def extract_lora_values(string):
|
||||
if a is None:
|
||||
a = 1.0
|
||||
if b is None:
|
||||
b = 1.0
|
||||
b = a
|
||||
|
||||
if lora is not None and lora not in added:
|
||||
result.append((lora, a, b, lbw, lbw_a, lbw_b))
|
||||
@@ -290,12 +295,17 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None):
|
||||
pass2 = remove_lora_tags(pass1)
|
||||
|
||||
for lora_name, model_weight, clip_weight, lbw, lbw_a, lbw_b in loras:
|
||||
if (lora_name.split('.')[-1]) not in folder_paths.supported_pt_extensions:
|
||||
lora_name_ext = lora_name.split('.')
|
||||
if ('.'+lora_name_ext[-1]) not in folder_paths.supported_pt_extensions:
|
||||
lora_name = lora_name+".safetensors"
|
||||
|
||||
orig_lora_name = lora_name
|
||||
lora_name = resolve_lora_name(lora_name_cache, lora_name)
|
||||
|
||||
path = folder_paths.get_full_path("loras", lora_name)
|
||||
if lora_name is not None:
|
||||
path = folder_paths.get_full_path("loras", lora_name)
|
||||
else:
|
||||
path = None
|
||||
|
||||
if path is not None:
|
||||
print(f"LOAD LORA: {lora_name}: {model_weight}, {clip_weight}, LBW={lbw}, A={lbw_a}, B={lbw_b}")
|
||||
@@ -305,6 +315,10 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None):
|
||||
|
||||
if lbw is not None:
|
||||
if 'LoraLoaderBlockWeight //Inspire' not in nodes.NODE_CLASS_MAPPINGS:
|
||||
utils.try_install_custom_node(
|
||||
'https://github.com/ltdrdata/ComfyUI-Inspire-Pack',
|
||||
"To use 'LBW=' syntax in wildcards, 'Inspire Pack' extension is required.")
|
||||
|
||||
print(f"'LBW(Lora Block Weight)' is given, but the 'Inspire Pack' is not installed. The LBW= attribute is being ignored.")
|
||||
model, clip = default_lora()
|
||||
else:
|
||||
@@ -313,14 +327,31 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None):
|
||||
else:
|
||||
model, clip = default_lora()
|
||||
else:
|
||||
print(f"LORA NOT FOUND: {lora_name}")
|
||||
print(f"LORA NOT FOUND: {orig_lora_name}")
|
||||
|
||||
print(f"CLIP: {pass2}")
|
||||
pass3 = [x.strip() for x in pass2.split("BREAK")]
|
||||
pass3 = [x for x in pass3 if x != '']
|
||||
|
||||
if clip_encoder is None:
|
||||
return model, clip, nodes.CLIPTextEncode().encode(clip, pass2)[0]
|
||||
else:
|
||||
return model, clip, clip_encoder.encode(clip, pass2)[0]
|
||||
if len(pass3) == 0:
|
||||
pass3 = ['']
|
||||
|
||||
pass3_str = [f'[{x}]' for x in pass3]
|
||||
print(f"CLIP: {str.join(' + ', pass3_str)}")
|
||||
|
||||
result = None
|
||||
|
||||
for prompt in pass3:
|
||||
if clip_encoder is None:
|
||||
cur = nodes.CLIPTextEncode().encode(clip, prompt)[0]
|
||||
else:
|
||||
cur = clip_encoder.encode(clip, prompt)[0]
|
||||
|
||||
if result is not None:
|
||||
result = nodes.ConditioningConcat().concat(result, cur)[0]
|
||||
else:
|
||||
result = cur
|
||||
|
||||
return model, clip, result
|
||||
|
||||
|
||||
def starts_with_regex(pattern, text):
|
||||
@@ -370,6 +401,31 @@ class WildcardChooserDict:
|
||||
return text
|
||||
|
||||
|
||||
def split_string_with_sep(input_string):
|
||||
sep_pattern = r'\[SEP(?:\:\w+)?\]'
|
||||
|
||||
substrings = re.split(sep_pattern, input_string)
|
||||
|
||||
result_list = [None]
|
||||
matches = re.findall(sep_pattern, input_string)
|
||||
for i, substring in enumerate(substrings):
|
||||
result_list.append(substring)
|
||||
if i < len(matches):
|
||||
if matches[i] == '[SEP]':
|
||||
result_list.append(None)
|
||||
elif matches[i] == '[SEP:R]':
|
||||
result_list.append(random.randint(0, 1125899906842624))
|
||||
else:
|
||||
try:
|
||||
seed = int(matches[i][5:-1])
|
||||
except:
|
||||
seed = None
|
||||
result_list.append(seed)
|
||||
|
||||
iterable = iter(result_list)
|
||||
return list(zip(iterable, iterable))
|
||||
|
||||
|
||||
def process_wildcard_for_segs(wildcard):
|
||||
if wildcard.startswith('[LAB]'):
|
||||
raw_items = split_to_dict(wildcard)
|
||||
@@ -384,13 +440,7 @@ def process_wildcard_for_segs(wildcard):
|
||||
|
||||
elif starts_with_regex(r"\[(ASC|DSC|RND)\]", wildcard):
|
||||
mode = wildcard[1:4]
|
||||
raw_items = wildcard[5:].split('[SEP]')
|
||||
|
||||
items = []
|
||||
for x in raw_items:
|
||||
x = x.strip()
|
||||
if x != '':
|
||||
items.append(x)
|
||||
items = split_string_with_sep(wildcard[5:])
|
||||
|
||||
if mode == 'RND':
|
||||
random.shuffle(items)
|
||||
@@ -399,4 +449,4 @@ def process_wildcard_for_segs(wildcard):
|
||||
return mode, WildcardChooser(items, False)
|
||||
|
||||
else:
|
||||
return None, WildcardChooser([wildcard], False)
|
||||
return None, WildcardChooser([(None, wildcard)], False)
|
||||
|
||||
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
# Due to the current lack of maintenance for the `ComfyUI_Noise` extension,
|
||||
# I have copied the code from the applied PR.
|
||||
# https://github.com/BlenderNeko/ComfyUI_Noise/pull/13/files
|
||||
|
||||
import comfy
|
||||
import torch
|
||||
|
||||
class Unsampler:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required":
|
||||
{"model": ("MODEL",),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"end_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
|
||||
"normalize": (["disable", "enable"],),
|
||||
"positive": ("CONDITIONING",),
|
||||
"negative": ("CONDITIONING",),
|
||||
"latent_image": ("LATENT",),
|
||||
}}
|
||||
|
||||
RETURN_TYPES = ("LATENT",)
|
||||
FUNCTION = "unsampler"
|
||||
|
||||
CATEGORY = "sampling"
|
||||
|
||||
def unsampler(self, model, cfg, sampler_name, steps, end_at_step, scheduler, normalize, positive, negative,
|
||||
latent_image):
|
||||
normalize = normalize == "enable"
|
||||
device = comfy.model_management.get_torch_device()
|
||||
latent = latent_image
|
||||
latent_image = latent["samples"]
|
||||
|
||||
end_at_step = min(end_at_step, steps - 1)
|
||||
end_at_step = steps - end_at_step
|
||||
|
||||
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
|
||||
noise_mask = None
|
||||
if "noise_mask" in latent:
|
||||
noise_mask = comfy.sample.prepare_mask(latent["noise_mask"], noise.shape, device)
|
||||
|
||||
real_model = None
|
||||
real_model = model.model
|
||||
|
||||
noise = noise.to(device)
|
||||
latent_image = latent_image.to(device)
|
||||
|
||||
positive = comfy.sample.convert_cond(positive)
|
||||
negative = comfy.sample.convert_cond(negative)
|
||||
|
||||
models, inference_memory = comfy.sample.get_additional_models(positive, negative, model.model_dtype())
|
||||
|
||||
comfy.model_management.load_models_gpu([model] + models, model.memory_required(noise.shape) + inference_memory)
|
||||
|
||||
sampler = comfy.samplers.KSampler(real_model, steps=steps, device=device, sampler=sampler_name,
|
||||
scheduler=scheduler, denoise=1.0, model_options=model.model_options)
|
||||
|
||||
sigmas = sigmas = sampler.sigmas.flip(0) + 0.0001
|
||||
|
||||
pbar = comfy.utils.ProgressBar(steps)
|
||||
|
||||
def callback(step, x0, x, total_steps):
|
||||
pbar.update_absolute(step + 1, total_steps)
|
||||
|
||||
samples = sampler.sample(noise, positive, negative, cfg=cfg, latent_image=latent_image,
|
||||
force_full_denoise=False, denoise_mask=noise_mask, sigmas=sigmas, start_step=0,
|
||||
last_step=end_at_step, callback=callback)
|
||||
if normalize:
|
||||
# technically doesn't normalize because unsampling is not guaranteed to end at a std given by the schedule
|
||||
samples -= samples.mean()
|
||||
samples /= samples.std()
|
||||
samples = samples.cpu()
|
||||
|
||||
comfy.sample.cleanup_additional_models(models)
|
||||
|
||||
out = latent.copy()
|
||||
out["samples"] = samples
|
||||
return (out,)
|
||||
@@ -3,3 +3,4 @@ scikit-image
|
||||
piexif
|
||||
transformers
|
||||
opencv-python-headless
|
||||
GitPython
|
||||
|
||||
Reference in New Issue
Block a user