Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c48161bc0d | ||
|
|
860fead58e | ||
|
|
64c834609f | ||
|
|
8f1a4accf1 | ||
|
|
2072e8b4f1 | ||
|
|
df8d82e2a7 | ||
|
|
11c65a04f9 |
@@ -1,21 +0,0 @@
|
||||
name: Publish to Comfy registry
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "pyproject.toml"
|
||||
|
||||
jobs:
|
||||
publish-node:
|
||||
name: Publish Custom Node to registry
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish Custom Node
|
||||
uses: Comfy-Org/publish-node-action@main
|
||||
with:
|
||||
## Add your own personal access token to your Github Repository secrets and reference it here.
|
||||
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
||||
@@ -7,11 +7,6 @@ This custom node helps to conveniently enhance images through Detector, Detailer
|
||||
|
||||
|
||||
## NOTICE
|
||||
* V7.0: Supports Switch based on Execution Model Inversion.
|
||||
* V6.0: Supports FLUX.1 model in Impact KSampler, Detailers, PreviewBridgeLatent
|
||||
* V5.0: It is no longer compatible with versions of ComfyUI before 2024.04.08.
|
||||
* V4.87.4: Update to a version of ComfyUI after 2024.04.08 for proper functionality.
|
||||
* V4.85: Incompatible with the outdated **ComfyUI IPAdapter Plus**. (A version dated March 24th or later is required.)
|
||||
* V4.77: Compatibility patch applied. Requires ComfyUI version (Oct. 8th) or later.
|
||||
* V4.73.3: ControlNetApply (SEGS) supports AnimateDiff
|
||||
* V4.20.1: Due to the feature update in `RegionalSampler`, the parameter order has changed, causing malfunctions in previously created `RegionalSamplers`. Please adjust the parameters accordingly.
|
||||
@@ -30,238 +25,220 @@ This custom node helps to conveniently enhance images through Detector, Detailer
|
||||
|
||||
|
||||
## Custom Nodes
|
||||
### [Detector nodes](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/detectors.md)
|
||||
* `SAMLoader` - Loads the SAM model.
|
||||
* `UltralyticsDetectorProvider` - Loads the Ultralystics model to provide SEGM_DETECTOR, BBOX_DETECTOR.
|
||||
* [Detectors](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/detectors.md)
|
||||
* SAMLoader - Loads the SAM model.
|
||||
* UltralyticsDetectorProvider - Loads the Ultralystics model to provide SEGM_DETECTOR, BBOX_DETECTOR.
|
||||
- Unlike `MMDetDetectorProvider`, for segm models, `BBOX_DETECTOR` is also provided.
|
||||
- The various models available in UltralyticsDetectorProvider can be downloaded through **ComfyUI-Manager**.
|
||||
* `ONNXDetectorProvider` - Loads the ONNX model to provide BBOX_DETECTOR.
|
||||
* `CLIPSegDetectorProvider` - Wrapper for CLIPSeg to provide BBOX_DETECTOR.
|
||||
* ONNXDetectorProvider - Loads the ONNX model to provide BBOX_DETECTOR.
|
||||
* CLIPSegDetectorProvider - Wrapper for CLIPSeg to provide BBOX_DETECTOR.
|
||||
* You need to install the ComfyUI-CLIPSeg node extension.
|
||||
* `SEGM Detector (combined)` - Detects segmentation and returns a mask from the input image.
|
||||
* `BBOX Detector (combined)` - Detects bounding boxes and returns a mask from the input image.
|
||||
* `SAMDetector (combined)` - Utilizes the SAM technology to extract the segment at the location indicated by the input SEGS on the input image and outputs it as a unified mask.
|
||||
* `SAMDetector (Segmented)` - It is similar to `SAMDetector (combined)`, but it separates and outputs the detected segments. Multiple segments can be found for the same detected area, and currently, a policy is in place to group them arbitrarily in sets of three. This aspect is expected to be improved in the future.
|
||||
* SEGM Detector (combined) - Detects segmentation and returns a mask from the input image.
|
||||
* BBOX Detector (combined) - Detects bounding boxes and returns a mask from the input image.
|
||||
* SAMDetector (combined) - Utilizes the SAM technology to extract the segment at the location indicated by the input SEGS on the input image and outputs it as a unified mask.
|
||||
* SAMDetector (Segmented) - It is similar to `SAMDetector (combined)`, but it separates and outputs the detected segments. Multiple segments can be found for the same detected area, and currently, a policy is in place to group them arbitrarily in sets of three. This aspect is expected to be improved in the future.
|
||||
* As a result, it outputs the `combined_mask`, which is a unified mask, and `batch_masks`, which are multiple masks grouped together in batch form.
|
||||
* While `batch_masks` may not be completely separated, it provides functionality to perform some level of segmentation.
|
||||
* `Simple Detector (SEGS)` - Operating primarily with `BBOX_DETECTOR`, and with the additional provision of `SAM_MODEL` or `SEGM_DETECTOR`, this node internally generates improved SEGS through mask operations on both *bbox* and *silhouette*. It serves as a convenient tool to simplify a somewhat intricate workflow.
|
||||
* Simple Detector (SEGS) - Operating primarily with `BBOX_DETECTOR`, and with the additional provision of `SAM_MODEL` or `SEGM_DETECTOR`, this node internally generates improved SEGS through mask operations on both *bbox* and *silhouette*. It serves as a convenient tool to simplify a somewhat intricate workflow.
|
||||
|
||||
### ControlNet, IPAdapter
|
||||
* `ControlNetApply (SEGS)` - To apply ControlNet in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
|
||||
* ControlNet, IPAdapter
|
||||
* ControlNetApply (SEGS) - To apply ControlNet in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
|
||||
* `segs_preprocessor` and `control_image` can be selectively applied. If an `control_image` is given, `segs_preprocessor` will be ignored.
|
||||
* If set to `control_image`, you can preview the cropped cnet image through `SEGSPreview (CNET Image)`. Images generated by `segs_preprocessor` should be verified through the `cnet_images` output of each Detailer.
|
||||
* The `segs_preprocessor` operates by applying preprocessing on-the-fly based on the cropped image during the detailing process, while `control_image` will be cropped and used as input to `ControlNetApply (SEGS)`.
|
||||
* `ControlNetClear (SEGS)` - Clear applied ControlNet in SEGS
|
||||
* `IPAdapterApply (SEGS)` - To apply IPAdapter in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
|
||||
* ControlNetClear (SEGS) - Clear applied ControlNet in SEGS
|
||||
* IPAdapterApply (SEGS) - To apply IPAdapter in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
|
||||
|
||||
### Mask operation
|
||||
* `Pixelwise(SEGS & SEGS)` - Performs a 'pixelwise and' operation between two SEGS.
|
||||
* `Pixelwise(SEGS - SEGS)` - Subtracts one SEGS from another.
|
||||
* `Pixelwise(SEGS & MASK)` - Performs a pixelwise AND operation between SEGS and MASK.
|
||||
* `Pixelwise(SEGS & MASKS ForEach)` - Performs a pixelwise AND operation between SEGS and MASKS.
|
||||
* Please note that this operation is performed with batches of MASKS, not just a single MASK.
|
||||
* `Pixelwise(MASK & MASK)` - Performs a 'pixelwise and' operation between two masks.
|
||||
* `Pixelwise(MASK - MASK)` - Subtracts one mask from another.
|
||||
* `Pixelwise(MASK + MASK)` - Combine two masks.
|
||||
* `SEGM Detector (SEGS)` - Detects segmentation and returns SEGS from the input image.
|
||||
* `BBOX Detector (SEGS)` - Detects bounding boxes and returns SEGS from the input image.
|
||||
* `Dilate Mask` - Dilate Mask.
|
||||
* Support erosion for negative value.
|
||||
* `Gaussian Blur Mask` - Apply Gaussian Blur to Mask. You can utilize this for mask feathering.
|
||||
* Bitwise(SEGS & SEGS) - Performs a 'bitwise and' operation between two SEGS.
|
||||
* Bitwise(SEGS - SEGS) - Subtracts one SEGS from another.
|
||||
* Bitwise(SEGS & MASK) - Performs a bitwise AND operation between SEGS and MASK.
|
||||
* Bitwise(SEGS & MASKS ForEach) - Performs a bitwise AND operation between SEGS and MASKS.
|
||||
* Please note that this operation is performed with batches of MASKS, not just a single MASK.
|
||||
* Bitwise(MASK & MASK) - Performs a 'bitwise and' operation between two masks.
|
||||
* Bitwise(MASK - MASK) - Subtracts one mask from another.
|
||||
* Bitwise(MASK + MASK) - Combine two masks.
|
||||
* SEGM Detector (SEGS) - Detects segmentation and returns SEGS from the input image.
|
||||
* BBOX Detector (SEGS) - Detects bounding boxes and returns SEGS from the input image.
|
||||
|
||||
### [Detailer nodes](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/detailers.md)
|
||||
* `Detailer (SEGS)` - Refines the image based on SEGS.
|
||||
* `DetailerDebug (SEGS)` - Refines the image based on SEGS. Additionally, it provides the ability to monitor the cropped image and the refined image of the cropped image.
|
||||
* Detailer
|
||||
* Detailer (SEGS) - Refines the image based on SEGS.
|
||||
* DetailerDebug (SEGS) - Refines the image based on SEGS. Additionally, it provides the ability to monitor the cropped image and the refined image of the cropped image.
|
||||
* To prevent regeneration caused by the seed that does not change every time when using 'external_seed', please disable the 'seed random generate' option in the 'Detailer...' node.
|
||||
* `MASK to SEGS` - Generates SEGS based on the mask.
|
||||
* `MASK to SEGS For AnimateDiff` - Generates SEGS based on the mask for AnimateDiff.
|
||||
* When using a single mask, convert it to SEGS to apply it to the entire frame.
|
||||
* When using a batch mask, the contour fill feature is disabled.
|
||||
* `MediaPipe FaceMesh to SEGS` - Separate each landmark from the mediapipe facemesh image to create labeled SEGS.
|
||||
* MASK to SEGS - Generates SEGS based on the mask.
|
||||
* MASK to SEGS For AnimateDiff - Generates SEGS based on the mask for AnimateDiff.
|
||||
* MediaPipe FaceMesh to SEGS - Separate each landmark from the mediapipe facemesh image to create labeled SEGS.
|
||||
* Usually, the size of images created through the MediaPipe facemesh preprocessor is downscaled. It resizes the MediaPipe facemesh image to the original size given as reference_image_opt for matching sizes during processing.
|
||||
* `ToBinaryMask` - Separates the mask generated with alpha values between 0 and 255 into 0 and 255. The non-zero parts are always set to 255.
|
||||
* `Masks to Mask List` - This node converts the MASKS in batch form to a list of individual masks.
|
||||
* `Mask List to Masks` - This node converts the MASK list to MASK batch form.
|
||||
* `EmptySEGS` - Provides an empty SEGS.
|
||||
* `MaskPainter` - Provides a feature to draw masks.
|
||||
* `FaceDetailer` - Easily detects faces and improves them.
|
||||
* `FaceDetailer (pipe)` - Easily detects faces and improves them (for multipass).
|
||||
* `MaskDetailer (pipe)` - This is a simple inpaint node that applies the Detailer to the mask area.
|
||||
* ToBinaryMask - Separates the mask generated with alpha values between 0 and 255 into 0 and 255. The non-zero parts are always set to 255.
|
||||
* Masks to Mask List - This node converts the MASKS in batch form to a list of individual masks.
|
||||
* Mask List to Masks - This node converts the MASK list to MASK batch form.
|
||||
* EmptySEGS - Provides an empty SEGS.
|
||||
* MaskPainter - Provides a feature to draw masks.
|
||||
* FaceDetailer - Easily detects faces and improves them.
|
||||
* FaceDetailer (pipe) - Easily detects faces and improves them (for multipass).
|
||||
* MaskDetailer (pipe) - This is a simple inpaint node that applies the Detailer to the mask area.
|
||||
|
||||
* `FromDetailer (SDXL/pipe)`, `BasicPipe -> DetailerPipe (SDXL)`, `Edit DetailerPipe (SDXL)` - These are pipe functions used in Detailer for utilizing the refiner model of SDXL.
|
||||
* `FromDetailer (SDXL/pipe), BasicPipe -> DetailerPipe (SDXL), Edit DetailerPipe (SDXL)` - These are pipe functions used in Detailer for utilizing the refiner model of SDXL.
|
||||
|
||||
### SEGS Manipulation nodes
|
||||
* `SEGSDetailer` - Performs detailed work on SEGS without pasting it back onto the original image.
|
||||
* `SEGSPaste` - Pastes the results of SEGS onto the original image.
|
||||
* SEGS Manipulation nodes
|
||||
* SEGSDetailer - Performs detailed work on SEGS without pasting it back onto the original image.
|
||||
* SEGSPaste - Pastes the results of SEGS onto the original image.
|
||||
* If `ref_image_opt` is present, the images contained within SEGS are ignored. Instead, the image within `ref_image_opt` corresponding to the crop area of SEGS is taken and pasted. The size of the image in `ref_image_opt` should be the same as the original image size.
|
||||
* This node can be used in conjunction with the processing results of AnimateDiff.
|
||||
* `SEGSPreview` - Provides a preview of SEGS.
|
||||
* SEGSPreview - Provides a preview of SEGS.
|
||||
* This option is used to preview the improved image through `SEGSDetailer` before merging it into the original. Prior to going through ```SEGSDetailer```, SEGS only contains mask information without image information. If fallback_image_opt is connected to the original image, SEGS without image information will generate a preview using the original image. However, if SEGS already contains image information, fallback_image_opt will be ignored.
|
||||
* This node can be used in conjunction with the processing results of AnimateDiff.
|
||||
* `SEGSPreview (CNET Image)` - Show images configured with `ControlNetApply (SEGS)` for debugging purposes.
|
||||
* `SEGSToImageList` - Convert SEGS To Image List
|
||||
* `SEGSToMaskList` - Convert SEGS To Mask List
|
||||
* `SEGS Filter (label)` - This node filters SEGS based on the label of the detected areas.
|
||||
* `SEGS Filter (ordered)` - This node sorts SEGS based on size and position and retrieves SEGs within a certain range.
|
||||
* `SEGS Filter (range)` - This node retrieves only SEGs from SEGS that have a size and position within a certain range.
|
||||
* `SEGS Assign (label)` - Assign labels sequentially to SEGS. This node is useful when used with `[LAB]` of FaceDetailer.
|
||||
* `SEGSConcat` - Concatenate segs1 and segs2. If source shape of segs1 and segs2 are different from segs2 will be ignored.
|
||||
* `Picker (SEGS)` - Among the input SEGS, you can select a specific SEG through a dialog. If no SEG is selected, it outputs an empty SEGS. Increasing the batch_size of SEGSDetailer can be used for the purpose of selecting from the candidates.
|
||||
* `Set Default Image For SEGS` - Set a default image for SEGS. SEGS with images set this way do not need to have a fallback image set. When override is set to false, the original image is preserved.
|
||||
* `Remove Image from SEGS` - Remove the image set for the SEGS that has been configured by "Set Default Image for SEGS" or SEGSDetailer. When the image for the SEGS is removed, the Detailer node will operate based on the currently processed image instead of the SEGS.
|
||||
* `Make Tile SEGS` - [experimental] Create SEGS in the form of tiles from an image to facilitate experiments for Tiled Upscale using the Detailer.
|
||||
* SEGSPreview (CNET Image) - Show images configured with `ControlNetApply (SEGS)` for debugging purposes.
|
||||
* SEGSToImageList - Convert SEGS To Image List
|
||||
* SEGSToMaskList - Convert SEGS To Mask List
|
||||
* SEGS Filter (label) - This node filters SEGS based on the label of the detected areas.
|
||||
* SEGS Filter (ordered) - This node sorts SEGS based on size and position and retrieves SEGs within a certain range.
|
||||
* SEGS Filter (range) - This node retrieves only SEGs from SEGS that have a size and position within a certain range.
|
||||
* SEGS Assign (label) - Assign labels sequentially to SEGS. This node is useful when used with `[LAB]` of FaceDetailer.
|
||||
* SEGSConcat - Concatenate segs1 and segs2. If source shape of segs1 and segs2 are different from segs2 will be ignored.
|
||||
* Picker (SEGS) - Among the input SEGS, you can select a specific SEG through a dialog. If no SEG is selected, it outputs an empty SEGS. Increasing the batch_size of SEGSDetailer can be used for the purpose of selecting from the candidates.
|
||||
* Set Default Image For SEGS - Set a default image for SEGS. SEGS with images set this way do not need to have a fallback image set. When override is set to false, the original image is preserved.
|
||||
* Remove Image from SEGS - Remove the image set for the SEGS that has been configured by "Set Default Image for SEGS" or SEGSDetailer. When the image for the SEGS is removed, the Detailer node will operate based on the currently processed image instead of the SEGS.
|
||||
* Make Tile SEGS - [experimental] Create SEGS in the form of tiles from an image to facilitate experiments for Tiled Upscale using the Detailer.
|
||||
* The `filter_in_segs_opt` and `filter_out_segs_opt` are optional inputs. If these inputs are provided, when creating the tiles, the mask for each tile is generated by overlapping with the mask of `filter_in_segs_opt` and excluding the overlap with the mask of `filter_out_segs_opt`. Tiles with an empty mask will not be created as SEGS.
|
||||
* `Dilate Mask (SEGS)` - Dilate/Erosion Mask in SEGS
|
||||
* `Gaussian Blur Mask (SEGS)` - Apply Gaussian Blur to Mask in SEGS
|
||||
* `SEGS_ELT Manipulation` - experimental nodes
|
||||
* `DecomposeSEGS` - Decompose SEGS to allow for detailed manipulation.
|
||||
* `AssembleSEGS` - Reassemble the decomposed SEGS.
|
||||
* `From SEG_ELT` - Extract detailed information from SEG_ELT.
|
||||
* `Edit SEG_ELT` - Modify some of the information in SEG_ELT.
|
||||
* `Dilate SEG_ELT` - Dilate the mask of SEG_ELT.
|
||||
* `From SEG_ELT` bbox - Extract coordinate from bbox in SEG_ELT
|
||||
* `From SEG_ELT` crop_region - Extract coordinate from crop_region in SEG_ELT
|
||||
* `Count Elt in SEGS` - Number of Elts ins SEGS
|
||||
* 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.
|
||||
|
||||
* 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.
|
||||
* `ToBasicPipe`, `FromBasicPipe` - These nodes are used to bundle model, clip, vae, positive conditioning, and negative conditioning into a single BASIC_PIPE, or extract each element from the BASIC_PIPE.
|
||||
* `EditBasicPipe`, `EditDetailerPipe` - These nodes are used to replace some elements in BASIC_PIPE or DETAILER_PIPE.
|
||||
* `FromDetailerPipe_v2`, `FromBasicPipe_v2` - It has the same functionality as `FromDetailerPipe` and `FromBasicPipe`, but it has an additional output that directly exports the input pipe. It is useful when editing EditBasicPipe and EditDetailerPipe.
|
||||
* `Latent Scale (on Pixel Space)` - This node converts latent to pixel space, upscales it, and then converts it back to latent.
|
||||
* Pipe nodes
|
||||
* ToDetailerPipe, FromDetailerPipe - These nodes are used to bundle multiple inputs used in the detailer, such as models and vae, ..., into a single DETAILER_PIPE or extract the elements that are bundled in the DETAILER_PIPE.
|
||||
* ToBasicPipe, FromBasicPipe - These nodes are used to bundle model, clip, vae, positive conditioning, and negative conditioning into a single BASIC_PIPE, or extract each element from the BASIC_PIPE.
|
||||
* EditBasicPipe, EditDetailerPipe - These nodes are used to replace some elements in BASIC_PIPE or DETAILER_PIPE.
|
||||
* FromDetailerPipe_v2, FromBasicPipe_v2 - It has the same functionality as `FromDetailerPipe` and `FromBasicPipe`, but it has an additional output that directly exports the input pipe. It is useful when editing EditBasicPipe and EditDetailerPipe.
|
||||
* Latent Scale (on Pixel Space) - This node converts latent to pixel space, upscales it, and then converts it back to latent.
|
||||
* If upscale_model_opt is provided, it uses the model to upscale the pixel and then downscales it using the interpolation method provided in scale_method to the target resolution.
|
||||
* `PixelKSampleUpscalerProvider` - An upscaler is provided that converts latent to pixels using VAEDecode, performs upscaling, converts back to latent using VAEEncode, and then performs k-sampling. This upscaler can be attached to nodes such as `Iterative Upscale` for use.
|
||||
* Similar to `Latent Scale (on Pixel Space)`, if upscale_model_opt is provided, it performs pixel upscaling using the model.
|
||||
* `PixelTiledKSampleUpscalerProvider` - It is similar to `PixelKSampleUpscalerProvider`, but it uses `ComfyUI_TiledKSampler` and Tiled VAE Decoder/Encoder to avoid GPU VRAM issues at high resolutions.
|
||||
* PixelKSampleUpscalerProvider - An upscaler is provided that converts latent to pixels using VAEDecode, performs upscaling, converts back to latent using VAEEncode, and then performs k-sampling. This upscaler can be attached to nodes such as 'Iterative Upscale' for use.
|
||||
* Similar to 'Latent Scale (on Pixel Space)', if upscale_model_opt is provided, it performs pixel upscaling using the model.
|
||||
* PixelTiledKSampleUpscalerProvider - It is similar to PixelKSampleUpscalerProvider, but it uses ComfyUI_TiledKSampler and Tiled VAE Decoder/Encoder to avoid GPU VRAM issues at high resolutions.
|
||||
* You need to install the [BlenderNeko/ComfyUI_TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) node extension.
|
||||
|
||||
### PK_HOOK
|
||||
* `DenoiseScheduleHookProvider` - IterativeUpscale provides a hook that gradually changes the denoise to target_denoise as the iterative-step progresses.
|
||||
* `CfgScheduleHookProvider` - IterativeUpscale provides a hook that gradually changes the cfg to target_cfg as the iterative-step progresses.
|
||||
* `StepsScheduleHookProvider` - IterativeUpscale provides a hook that gradually changes the sampling-steps to target_steps as the iterative-step progresses.
|
||||
* `NoiseInjectionHookProvider` - During each iteration of IterativeUpscale, noise is injected into the latent space while varying the strength according to a schedule.
|
||||
* PK_HOOK
|
||||
* DenoiseScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the denoise to target_denoise as the iterative-step progresses.
|
||||
* CfgScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the cfg to target_cfg as the iterative-step progresses.
|
||||
* StepsScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the sampling-steps to target_steps as the iterative-step progresses.
|
||||
* NoiseInjectionHookProvider - During each iteration of IterativeUpscale, noise is injected into the latent space while varying the strength according to a schedule.
|
||||
* You need to install the [BlenderNeko/ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) node extension.
|
||||
* The seed serves as the initial value required for generating noise, and it increments by 1 with each iteration as the process unfolds.
|
||||
* The source determines the types of CPU noise and GPU noise to be configured.
|
||||
* Currently, there is only a simple schedule available, where the strength of the noise varies from start_strength to end_strength during the progression of each iteration.
|
||||
* `UnsamplerHookProvider` - Apply Unsampler during each iteration. To use this node, ComfyUI_Noise must be installed.
|
||||
* `PixelKSampleHookCombine` - This is used to connect two PK_HOOKs. hook1 is executed first and then hook2 is executed.
|
||||
* 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.
|
||||
* DETAILER_HOOK
|
||||
* NoiseInjectionDetailerHookProvider - The `detailer_hook` is a hook in the `Detailer` that injects noise during the processing of each SEGS.
|
||||
* UnsamplerDetailerHookProvider - Apply Unsampler during each cycle. To use this node, ComfyUI_Noise must be installed.
|
||||
* DenoiseSchedulerDetailerHookProvider - During the progress of the cycle, the detailer's denoise is altered up to the `target_denoise`.
|
||||
* CoreMLDetailerHookProvider - CoreML supports only 512x512, 512x768, 768x512, 768x768 size sampling. CoreMLDetailerHookProvider precisely fixes the upscale of the crop_region to this size. When using this hook, it will always be selected size, regardless of the guide_size. However, if the guide_size is too small, skipping will occur.
|
||||
* DetailerHookCombine - This is used to connect two DETAILER_HOOKs. Similar to PixelKSampleHookCombine.
|
||||
* SEGSOrderedFilterDetailerHook, SEGSRangeFilterDetailerHook, SEGSLabelFilterDetailerHook - There are a wrapper node that provides SEGSFilter nodes to be applied in FaceDetailer or Detector by creating DETAILER_HOOK.
|
||||
* PreviewDetailerHOok - Connecting this hook node helps provide assistance for viewing previews whenever SEGS Detailing tasks are completed. When working with a large number of SEGS, such as Make Tile SEGS, it allows for monitoring the situation as improvements progress incrementally.
|
||||
* Since this is the hook applied when pasting onto the original image, it has no effect on nodes like `SEGSDetailer`.
|
||||
* `VariationNoiseDetailerHookProvider` - Apply variation seed to the detailer. It can be applied in multiple stages through combine.
|
||||
|
||||
### Iterative Upscale nodes
|
||||
* `Iterative Upscale (Latent/on Pixel Space)` - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling.
|
||||
This takes latent as input and outputs latent as the result.
|
||||
* `Iterative Upscale (Image)` - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling. This takes image as input and outputs image as the result.
|
||||
* Internally, this node uses 'Iterative Upscale (Latent)'.
|
||||
* 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)'.
|
||||
|
||||
### TwoSamplers nodes
|
||||
* `TwoSamplersForMask` - This node can apply two samplers depending on the mask area. The base_sampler is applied to the area where the mask is 0, while the mask_sampler is applied to the area where the mask is 1.
|
||||
* TwoSamplersForMask - This node can apply two samplers depending on the mask area. The base_sampler is applied to the area where the mask is 0, while the mask_sampler is applied to the area where the mask is 1.
|
||||
* Note: The latent encoded through VAEEncodeForInpaint cannot be used.
|
||||
* `KSamplerProvider` - This is a wrapper that enables KSampler to be used in TwoSamplersForMask TwoSamplersForMaskUpscalerProvider.
|
||||
* `TiledKSamplerProvider` - ComfyUI_TiledKSampler is a wrapper that provides KSAMPLER.
|
||||
* KSamplerProvider - This is a wrapper that enables KSampler to be used in TwoSamplersForMask TwoSamplersForMaskUpscalerProvider.
|
||||
* TiledKSamplerProvider - ComfyUI_TiledKSampler is a wrapper that provides KSAMPLER.
|
||||
* You need to install the [BlenderNeko/ComfyUI_TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) node extension.
|
||||
|
||||
* `TwoAdvancedSamplersForMask` - TwoSamplersForMask is similar to TwoAdvancedSamplersForMask, but they differ in their operation. TwoSamplersForMask performs sampling in the mask area only after all the samples in the base area are finished. On the other hand, TwoAdvancedSamplersForMask performs sampling in both the base area and the mask area sequentially at each step.
|
||||
* `KSamplerAdvancedProvider` - This is a wrapper that enables KSampler to be used in TwoAdvancedSamplersForMask, RegionalSampler.
|
||||
* TwoAdvancedSamplersForMask - TwoSamplersForMask is similar to TwoAdvancedSamplersForMask, but they differ in their operation. TwoSamplersForMask performs sampling in the mask area only after all the samples in the base area are finished. On the other hand, TwoAdvancedSamplersForMask performs sampling in both the base area and the mask area sequentially at each step.
|
||||
* KSamplerAdvancedProvider - This is a wrapper that enables KSampler to be used in TwoAdvancedSamplersForMask, RegionalSampler.
|
||||
* sigma_factor: By multiplying the denoise schedule by the sigma_factor, you can adjust the amount of denoising based on the configured denoise.
|
||||
|
||||
* `TwoSamplersForMaskUpscalerProvider` - This is an Upscaler that extends TwoSamplersForMask to be used in Iterative Upscale.
|
||||
* TwoSamplersForMaskUpscalerProvider - This is an Upscaler that extends TwoSamplersForMask to be used in Iterative Upscale.
|
||||
* TwoSamplersForMaskUpscalerProviderPipe - pipe version of TwoSamplersForMaskUpscalerProvider.
|
||||
|
||||
### 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.
|
||||
* 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.
|
||||
* ImageSender, ImageReceiver - The images generated in ImageSender are automatically sent to the ImageReceiver with the same link_id.
|
||||
* LatentSender, LatentReceiver - The latent generated in LatentSender are automatically sent to the LatentReceiver with the same link_id.
|
||||
* Furthermore, LatentSender is implemented with PreviewLatent, which stores the latent in payload form within the image thumbnail.
|
||||
* Due to the current structure of ComfyUI, it is unable to distinguish between SDXL latent and SD1.5/SD2.1 latent. Therefore, it generates thumbnails by decoding them using the SD1.5 method.
|
||||
|
||||
### Switch nodes
|
||||
* `Switch (image,mask)`, `Switch (latent)`, `Switch (SEGS)` - Among multiple inputs, it selects the input designated by the selector and outputs it. The first input must be provided, while the others are optional. However, if the input specified by the selector is not connected, an error may occur.
|
||||
* `Switch (Any)` - This is a Switch node that takes an arbitrary number of inputs and produces a single output. Its type is determined when connected to any node, and connecting inputs increases the available slots for connections.
|
||||
* `Inversed Switch (Any)` - In contrast to `Switch (Any)`, it takes a single input and outputs one of many.
|
||||
* NOTE: See this [tutorial](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/switch.md)
|
||||
* Switch nodes
|
||||
* Switch (image,mask), Switch (latent), Switch (SEGS) - Among multiple inputs, it selects the input designated by the selector and outputs it. The first input must be provided, while the others are optional. However, if the input specified by the selector is not connected, an error may occur.
|
||||
* Switch (Any) - This is a Switch node that takes an arbitrary number of inputs and produces a single output. Its type is determined when connected to any node, and connecting inputs increases the available slots for connections.
|
||||
* Inversed Switch (Any) - In contrast to `Switch (Any)`, it takes a single input and outputs one of many. Due to ComfyUI's functional limitations, the value of `select` must be determined at the time of queuing a prompt, and while it can serve as a `Primitive Node` or `ImpactInt`, it cannot function properly when connected through other nodes.
|
||||
* Guide
|
||||
* When the `Switch (Any)` and `Inversed Switch (Any)` selects are transformed into primitives, it's important to be cautious because the select range is not appropriately constrained, potentially leading to unintended behavior.
|
||||
* `Switch (image,mask)`, `Switch (latent)`, `Switch (SEGS)`, `Switch (Any)` supports `sel_mode` param. The `sel_mode` sets the moment at which the `select` parameter is determined. `select_on_prompt` determines the `select` at the time of queuing the prompt, while `select_on_execution` determines it during the execution of the workflow. While `select_on_execution` offers more flexibility, it can potentially trigger workflow execution errors due to running nodes that may be impossible to execute within the limitations of ComfyUI. `select_on_prompt` bypasses this constraint by treating any inputs not selected as if they were disconnected. However, please note that when using `select_on_prompt`, the `select` can only be used with widgets or `Primitive Nodes` determined at the queue prompt.
|
||||
* There is an issue when connecting the built-in reroute node with the switch's input/output slots. it can lead to forced disconnections during workflow loading. Therefore, it is advisable not to use reroute for making connections in such cases. However, there are no issues when using the reroute node in Pythongossss.
|
||||
|
||||
### [Wildcards](http://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ImpactWildcard.md) nodes
|
||||
* These are nodes that supports syntax in the form of `__wildcard-name__` and dynamic prompt syntax like `{a|b|c}`.
|
||||
* [Wildcards](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ImpactWildcard.md) - These are nodes that supports syntax in the form of `__wildcard-name__` and dynamic prompt syntax like `{a|b|c}`.
|
||||
* Wildcard files can be used by placing `.txt` or `.yaml` files under either `ComfyUI-Impact-Pack/wildcards` or `ComfyUI-Impact-Pack/custom_wildcards` paths.
|
||||
* You can download and use [Wildcard YAML](https://civitai.com/models/138970/billions-of-wildcards-all-in-one) files in this format.
|
||||
* After the first execution, you can change the custom wildcards path in the `custom_wildcards` entry within the `ComfyUI-Impact-Pack/impact-pack.ini` file created.
|
||||
* `ImpactWildcardProcessor` - The text is generated by processing the wildcard in the Text. If the mode is set to "populate", a dynamic prompt is generated with each execution and the input is filled in the second textbox. If the mode is set to "fixed", the content of the second textbox remains unchanged.
|
||||
* ImpactWildcardProcessor - The text is generated by processing the wildcard in the Text. If the mode is set to "populate", a dynamic prompt is generated with each execution and the input is filled in the second textbox. If the mode is set to "fixed", the content of the second textbox remains unchanged.
|
||||
* When an image is generated with the "fixed" mode, the prompt used for that particular generation is stored in the metadata.
|
||||
* `ImpactWildcardEncode` - Similar to ImpactWildcardProcessor, this provides the loading functionality of LoRAs (e.g. `<lora:some_awesome_lora:0.7:1.2>`). Populated prompts are encoded using the clip after all the lora loading is done.
|
||||
* ImpactWildcardEncode - Similar to ImpactWildcardProcessor, this provides the loading functionality of LoRAs (e.g. `<lora:some_awesome_lora:0.7:1.2>`). Populated prompts are encoded using the clip after all the lora loading is done.
|
||||
* If the `Inspire Pack` is installed, you can use **Lora Block Weight** in the form of `LBW=lbw spec;`
|
||||
* `<lora:chunli:1.0:1.0:LBW=B11:0,0,0,0,0,0,0,0,0,0,A,0,0,0,0,0,0;A=0.;>`, `<lora:chunli:1.0:1.0:LBW=0,0,0,0,0,0,0,0,0,0,A,B,0,0,0,0,0;A=0.5;B=0.2;>`, `<lora:chunli:1.0:1.0:LBW=SD-MIDD;>`
|
||||
|
||||
### Regional Sampling
|
||||
* These nodes offer the capability to divide regions and perform partial sampling using a mask. Unlike TwoSamplersForMask, sampling for each region is applied during each step.
|
||||
* `RegionalPrompt` - This node combines a **mask** for specifying regions and the **sampler** to apply to each region to create `REGIONAL_PROMPTS`.
|
||||
* `CombineRegionalPrompts` - Combine multiple `REGIONAL_PROMPTS` to create a single `REGIONAL_PROMPTS`.
|
||||
* `RegionalSampler` - This node performs sampling using a base sampler and regional prompts. Sampling by the base sampler is executed at each step, while sampling for each region is performed through the sampler bound to each region.
|
||||
* Regional Sampling - These nodes offer the capability to divide regions and perform partial sampling using a mask. Unlike TwoSamplersForMask, sampling for each region is applied during each step.
|
||||
* RegionalPrompt - This node combines a **mask** for specifying regions and the **sampler** to apply to each region to create `REGIONAL_PROMPTS`.
|
||||
* CombineRegionalPrompts - Combine multiple `REGIONAL_PROMPTS` to create a single `REGIONAL_PROMPTS`.
|
||||
* RegionalSampler - This node performs sampling using a base sampler and regional prompts. Sampling by the base sampler is executed at each step, while sampling for each region is performed through the sampler bound to each region.
|
||||
* overlap_factor - Specifies the amount of overlap for each region to blend well with the area outside the mask.
|
||||
* restore_latent - When sampling each region, restore the areas outside the mask to the base latent, preventing additional noise from being introduced outside the mask during region sampling.
|
||||
* `RegionalSamplerAdvanced` - This is the Advanced version of the RegionalSampler. You can control it using `step` instead of `denoise`.
|
||||
> NOTE: The `sde` sampler and `uni_pc` sampler introduce additional noise during each step of the sampling process. To mitigate this, when sampling each region, the `uni_pc` sampler applies additional `dpmpp_fast`, and the sde sampler applies the `dpmpp_2m` sampler as an additional measure.
|
||||
* RegionalSamplerAdvanced - This is the Advanced version of the RegionalSampler. You can control it using `step` instead of `denoise`.
|
||||
* NOTE: The `sde` sampler and `uni_pc` sampler introduce additional noise during each step of the sampling process. To mitigate this, when sampling each region, the `uni_pc` sampler applies additional `dpmpp_fast`, and the sde sampler applies the `dpmpp_2m` sampler as an additional measure.
|
||||
|
||||
* KSampler (pipe), KSampler (advanced/pipe)
|
||||
|
||||
### Impact KSampler
|
||||
* These samplers support basic_pipe and AYS scheduler
|
||||
* `KSampler (pipe)` - pipe version of KSampler
|
||||
* `KSampler (advanced/pipe)` - pipe version of KSamplerAdvacned
|
||||
* When converting the scheduler widget to input, refer to the `Impact Scheduler Adapter` node to resolve compatibility issues.
|
||||
* `GITSScheduler Func Provider` - provider scheduler function for GITSScheduler
|
||||
|
||||
* Image batch To Image List - Convert Image batch to Image List
|
||||
- You can use images generated in a multi batch to handle them
|
||||
* Make Image List - Convert multiple images into a single image list
|
||||
* Make Image Batch - Convert multiple images into a single image batch
|
||||
- The input of images can be scaled up as needed
|
||||
|
||||
### Batch/List Util
|
||||
* `Image Batch to Image List` - Convert Image batch to Image List
|
||||
- You can use images generated in a multi batch to handle them
|
||||
* `Image List to Image Batch` - Convert Image List to Image Batch
|
||||
* `Make Image List` - Convert multiple images into a single image list
|
||||
* `Make Image Batch` - Convert multiple images into a single image batch
|
||||
- The input of images can be scaled up as needed
|
||||
* `Masks to Mask List`, `Mask List to Masks`, `Make Mask List`, `Make Mask Batch` - It has the same functionality as the nodes above, but uses mask as input instead of image.
|
||||
* `Flatten Mask Batch` - Flattens a Mask Batch into a single Mask. Normal operation is not guaranteed for non-binary masks.
|
||||
* 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`, `ImpactConditionalBranchSelMode`, `ImpactInt`, `ImpactValueSender`, `ImpactValueReceiver`, `ImpactImageInfo`, `ImpactMinMax`, `ImpactNeg`, `ImpactConditionalStopIteration`
|
||||
* `ImpactIsNotEmptySEGS` - This node returns `true` only if the input SEGS is not empty.
|
||||
* `ImpactIfNone` - Returns `true` if any_input is None, and returns `false` if it is not None.
|
||||
* `Queue Trigger` - When this node is executed, it adds a new queue to assist with repetitive tasks. It will only execute if the signal's status changes.
|
||||
* `Queue Trigger (Countdown)` - Like the Queue Trigger, it adds a queue, but only adds it if it's greater than 1, and decrements the count by one each time it runs.
|
||||
* `Sleep` - Waits for the specified time (in seconds).
|
||||
* `Set Widget Value` - This node sets one of the optional inputs to the specified node's widget. An error may occur if the types do not match.
|
||||
* `Set Mute State` - This node changes the mute state of a specific node.
|
||||
* `Control Bridge` - This node modifies the state of the connected control nodes based on the `mode` and `behavior` . If there are nodes that require a change, the current execution is paused, the mute status is updated, and a new prompt queue is inserted.
|
||||
* Logics (experimental) - These nodes are experimental nodes designed to implement the logic for loops and dynamic switching.
|
||||
* ImpactCompare, ImpactConditionalBranch, ImpactConditionalBranchSelMode, ImpactInt, ImpactValueSender, ImpactValueReceiver, ImpactImageInfo, ImpactMinMax, ImpactNeg, ImpactConditionalStopIteration
|
||||
* 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 - 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.
|
||||
* Remote Boolean (on prompt), Remote Int (on prompt) - At the start of the prompt, this node forcibly sets the `widget_value` of `node_id`. It is disregarded if the target widget type is different.
|
||||
* You can find the `node_id` by checking through [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager) using the format `Badge: #ID Nickname`.
|
||||
* Experimental set of nodes for implementing loop functionality (tutorial to be prepared later / [example workflow](test/loop-test.json)).
|
||||
|
||||
### HuggingFace nodes
|
||||
* These nodes provide functionalities based on HuggingFace repository models.
|
||||
* The path where the HuggingFace model cache is stored can be changed through the `HF_HOME` environment variable.
|
||||
* HuggingFace - These nodes provide functionalities based on HuggingFace repository models.
|
||||
* `HF Transformers Classifier Provider` - This is a node that provides a classifier based on HuggingFace's transformers models.
|
||||
* The 'repo id' parameter should contain HuggingFace's repo id. When `preset_repo_id` is set to `Manual repo id`, use the manually entered repo id in `manual_repo_id`.
|
||||
* e.g. 'rizvandwiki/gender-classification-2' is a repository that provides a model for gender classification.
|
||||
@@ -271,30 +248,15 @@ This custom node helps to conveniently enhance images through Detector, Detailer
|
||||
* For supported labels, please refer to the `config.json` of the respective HuggingFace repository.
|
||||
* `#Female` and `#Male` are symbols that group multiple labels such as `Female, women, woman, ...`, for convenience, rather than being single labels.
|
||||
|
||||
### Etc nodes
|
||||
* `Impact Scheduler Adapter` - With the addition of AYS to the scheduler of the Impact Pack and Inspire Pack, there is an issue of incompatibility when the existing scheduler widget is converted to input. The Impact Scheduler Adapter allows for an indirect connection to be possible.
|
||||
* `StringListToString` - Convert String List to String
|
||||
* `WildcardPromptFromString` - Create labeled wildcard for detailer from string.
|
||||
* This node works well when used with MakeTileSEGS. [[Link](https://github.com/ltdrdata/ComfyUI-Impact-Pack/pull/536#discussion_r1586060779)]
|
||||
|
||||
* `String Selector` - It selects and returns a portion of the string. When `multiline` mode is disabled, it simply returns the string of the line pointed to by the selector. When `multiline` mode is enabled, it divides the string based on lines that start with `#` and returns them. If the `select` value is larger than the number of items, it will start counting from the first line again and return accordingly.
|
||||
* `Combine Conditionings` - It takes multiple conditionings as input and combines them into a single conditioning.
|
||||
* `Concat Conditionings` - It takes multiple conditionings as input and concat them into a single conditioning.
|
||||
* `Negative Cond Placeholder` - Models like FLUX.1 do not use Negative Conditioning. This is a placeholder node for them. You can use FLUX.1 by replacing the Negative Conditioning used in Impact KSampler, KSampler (Inspire), and Detailer with this node.
|
||||
* `Execution Order Controller` - A helper node that can forcibly control the execution order of nodes.
|
||||
* Connect the output of the node that should be executed first to the signal, and make the input of the node that should be executed later pass through this node.
|
||||
|
||||
|
||||
## MMDet nodes (DEPRECATED) - Don't use these nodes
|
||||
## MMDet nodes
|
||||
* MMDetDetectorProvider - Loads the MMDet model to provide BBOX_DETECTOR and SEGM_DETECTOR.
|
||||
* To use the existing MMDetDetectorProvider, you need to enable the MMDet usage configuration.
|
||||
|
||||
|
||||
## Feature
|
||||
* `Interactive SAM Detector (Clipspace)` - When you right-click on a node that has 'MASK' and 'IMAGE' outputs, a context menu will open. From this menu, you can either open a dialog to create a SAM Mask using 'Open in SAM Detector', or copy the content (likely mask data) using 'Copy (Clipspace)' and generate a mask using 'Impact SAM Detector' from the clipspace menu, and then paste it using 'Paste (Clipspace)'.
|
||||
* Interactive SAM Detector (Clipspace) - When you right-click on a node that has 'MASK' and 'IMAGE' outputs, a context menu will open. From this menu, you can either open a dialog to create a SAM Mask using 'Open in SAM Detector', or copy the content (likely mask data) using 'Copy (Clipspace)' and generate a mask using 'Impact SAM Detector' from the clipspace menu, and then paste it using 'Paste (Clipspace)'.
|
||||
* Providing a feature to detect errors that occur when mixing models and clips from checkpoints such as `SDXL Base`, `SDXL Refiner`, `SD1.x`, `SD2.x` during sample execution, and reporting appropriate errors.
|
||||
|
||||
|
||||
## Deprecated
|
||||
* The following nodes have been kept only for compatibility with existing workflows, and are no longer supported. Please replace them with new nodes.
|
||||
* ONNX Detector (SEGS) - BBOX Detector (SEGS)
|
||||
@@ -313,7 +275,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer
|
||||
* ultralytics/[assets](https://github.com/ultralytics/assets/releases/) - You can download various types of detection models other than faces or people.
|
||||
* civitai/[adetailer](https://civitai.com/search/models?sortBy=models_v5&query=adetailer) - You can download various types detection models....Many models are associated with NSFW content.
|
||||
|
||||
## How to activate 'MMDet usage' (DEPRECATED)
|
||||
## How to activate 'MMDet usage'
|
||||
* Upon the initial execution, an `impact-pack.ini` file will be generated in the custom_nodes/ComfyUI-Impact-Pack directory.
|
||||
```
|
||||
[default]
|
||||
@@ -332,9 +294,9 @@ mmdet_skip = False
|
||||
## Installation
|
||||
|
||||
1. `cd custom_nodes`
|
||||
2. `git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack.git`
|
||||
1. `git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack.git`
|
||||
3. `cd ComfyUI-Impact-Pack`
|
||||
4. (optional) `git clone https://github.com/ltdrdata/ComfyUI-Impact-Subpack impact_subpack`
|
||||
4. (optional) `git submodule update --init --recursive`
|
||||
* Impact Pack will automatically download subpack during its initial launch.
|
||||
5. (optional) `python install.py`
|
||||
* Impact Pack will automatically install its dependencies during its initial launch.
|
||||
@@ -343,9 +305,8 @@ mmdet_skip = False
|
||||
|
||||
6. Restart ComfyUI
|
||||
|
||||
* NOTE1: If an error occurs during the installation process, please refer to [Troubleshooting Page](troubleshooting/TROUBLESHOOTING.md) for assistance.
|
||||
* NOTE2: You can use this colab notebook [colab notebook](https://colab.research.google.com/github/ltdrdata/ComfyUI-Impact-Pack/blob/Main/notebook/comfyui_colab_impact_pack.ipynb) to launch it. This notebook automatically downloads the impact pack to the custom_nodes directory, installs the tested dependencies, and runs it.
|
||||
* NOTE3: If you create an empty file named `skip_download_model` in the `ComfyUI/custom_nodes/` directory, it will skip the model download step during the installation of the impact pack.
|
||||
* NOTE: If an error occurs during the installation process, please refer to [Troubleshooting Page](troubleshooting/TROUBLESHOOTING.md) for assistance.
|
||||
* You can use this colab notebook [colab notebook](https://colab.research.google.com/github/ltdrdata/ComfyUI-Impact-Pack/blob/Main/notebook/comfyui_colab_impact_pack.ipynb) to launch it. This notebook automatically downloads the impact pack to the custom_nodes directory, installs the tested dependencies, and runs it.
|
||||
|
||||
## Package Dependencies (If you need to manual setup.)
|
||||
|
||||
@@ -358,7 +319,7 @@ mmdet_skip = False
|
||||
* (optional) pycocotools
|
||||
* (optional) onnxruntime
|
||||
|
||||
* mim install (deprecated)
|
||||
* mim install (optional)
|
||||
* mmcv==2.0.0, mmdet==3.0.0, mmengine==0.7.2
|
||||
|
||||
* linux packages (ubuntu)
|
||||
@@ -484,9 +445,10 @@ open-mmlab/[mmdetection](https://github.com/open-mmlab/mmdetection) - Object det
|
||||
|
||||
biegert/[ComfyUI-CLIPSeg](https://github.com/biegert/ComfyUI-CLIPSeg) - This is a custom node that enables the use of CLIPSeg technology, which can find segments through prompts, in ComfyUI.
|
||||
|
||||
BlenderNeok/[ComfyUI-TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) - The tile sampler allows high-resolution sampling even in places with low GPU VRAM.
|
||||
BlenderNeok/[ComfyUI-TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) -
|
||||
The tile sampler allows high-resolution sampling even in places with low GPU VRAM.
|
||||
|
||||
BlenderNeok/[ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) - The noise injection feature relies on this function and slerp code for noise variation
|
||||
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.
|
||||
|
||||
|
||||
+67
-69
@@ -15,6 +15,8 @@ comfy_path = os.path.dirname(folder_paths.__file__)
|
||||
impact_path = os.path.join(os.path.dirname(__file__))
|
||||
subpack_path = os.path.join(os.path.dirname(__file__), "impact_subpack")
|
||||
modules_path = os.path.join(os.path.dirname(__file__), "modules")
|
||||
wildcards_path = os.path.join(os.path.dirname(__file__), "wildcards")
|
||||
custom_wildcards_path = os.path.join(os.path.dirname(__file__), "custom_wildcards")
|
||||
|
||||
sys.path.append(modules_path)
|
||||
|
||||
@@ -49,7 +51,6 @@ try:
|
||||
import folder_paths
|
||||
import torch
|
||||
import cv2
|
||||
from cv2 import setNumThreads
|
||||
import numpy as np
|
||||
import comfy.samplers
|
||||
import comfy.sd
|
||||
@@ -68,26 +69,63 @@ except:
|
||||
print("### ComfyUI-Impact-Pack: Reinstall dependencies (several dependencies are missing.)")
|
||||
do_install()
|
||||
|
||||
|
||||
import impact.impact_server # to load server api
|
||||
|
||||
from .modules.impact.impact_pack import *
|
||||
from .modules.impact.detectors import *
|
||||
from .modules.impact.pipe import *
|
||||
from .modules.impact.logics import *
|
||||
from .modules.impact.util_nodes import *
|
||||
from .modules.impact.segs_nodes import *
|
||||
from .modules.impact.special_samplers import *
|
||||
from .modules.impact.hf_nodes import *
|
||||
from .modules.impact.bridge_nodes import *
|
||||
from .modules.impact.hook_nodes import *
|
||||
from .modules.impact.animatediff_nodes import *
|
||||
from .modules.impact.segs_upscaler import *
|
||||
def setup_js():
|
||||
import nodes
|
||||
js_dest_path = os.path.join(comfy_path, "web", "extensions", "impact-pack")
|
||||
|
||||
if hasattr(nodes, "EXTENSION_WEB_DIRS"):
|
||||
if os.path.exists(js_dest_path):
|
||||
shutil.rmtree(js_dest_path)
|
||||
else:
|
||||
print(f"[WARN] ComfyUI-Impact-Pack: Your ComfyUI version is outdated. Please update to the latest version.")
|
||||
# setup js
|
||||
if not os.path.exists(js_dest_path):
|
||||
os.makedirs(js_dest_path)
|
||||
|
||||
js_src_path = os.path.join(impact_path, "js", "impact-pack.js")
|
||||
shutil.copy(js_src_path, js_dest_path)
|
||||
|
||||
js_src_path = os.path.join(impact_path, "js", "impact-sam-editor.js")
|
||||
shutil.copy(js_src_path, js_dest_path)
|
||||
|
||||
js_src_path = os.path.join(impact_path, "js", "comboBoolMigration.js")
|
||||
shutil.copy(js_src_path, js_dest_path)
|
||||
|
||||
|
||||
setup_js()
|
||||
|
||||
from impact.impact_pack import *
|
||||
from impact.detectors import *
|
||||
from impact.pipe import *
|
||||
from impact.logics import *
|
||||
from impact.util_nodes import *
|
||||
from impact.segs_nodes import *
|
||||
from impact.special_samplers import *
|
||||
from impact.hf_nodes import *
|
||||
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']
|
||||
|
||||
threading.Thread(target=impact.wildcards.wildcard_load).start()
|
||||
|
||||
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()
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
@@ -144,6 +182,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"UnsamplerHookProvider": UnsamplerHookProvider,
|
||||
"CoreMLDetailerHookProvider": CoreMLDetailerHookProvider,
|
||||
"PreviewDetailerHookProvider": PreviewDetailerHookProvider,
|
||||
"StableCascade_DetailerHookProvider": StableCascade_DetailerHookProvider,
|
||||
|
||||
"DetailerHookCombine": DetailerHookCombine,
|
||||
"NoiseInjectionDetailerHookProvider": NoiseInjectionDetailerHookProvider,
|
||||
@@ -152,8 +191,6 @@ NODE_CLASS_MAPPINGS = {
|
||||
"SEGSOrderedFilterDetailerHookProvider": SEGSOrderedFilterDetailerHookProvider,
|
||||
"SEGSRangeFilterDetailerHookProvider": SEGSRangeFilterDetailerHookProvider,
|
||||
"SEGSLabelFilterDetailerHookProvider": SEGSLabelFilterDetailerHookProvider,
|
||||
"VariationNoiseDetailerHookProvider": VariationNoiseDetailerHookProvider,
|
||||
# "CustomNoiseDetailerHookProvider": CustomNoiseDetailerHookProvider,
|
||||
|
||||
"BitwiseAndMask": BitwiseAndMask,
|
||||
"SubtractMask": SubtractMask,
|
||||
@@ -161,7 +198,6 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactSegsAndMask": SegsBitwiseAndMask,
|
||||
"ImpactSegsAndMaskForEach": SegsBitwiseAndMaskForEach,
|
||||
"EmptySegs": EmptySEGS,
|
||||
"ImpactFlattenMask": FlattenMask,
|
||||
|
||||
"MediaPipeFaceMeshToSEGS": MediaPipeFaceMeshToSEGS,
|
||||
"MaskToSEGS": MaskToSEGS,
|
||||
@@ -194,9 +230,6 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactDilateMaskInSEGS": DilateMaskInSEGS,
|
||||
"ImpactGaussianBlurMaskInSEGS": GaussianBlurMaskInSEGS,
|
||||
"ImpactScaleBy_BBOX_SEG_ELT": SEG_ELT_BBOX_ScaleBy,
|
||||
"ImpactFrom_SEG_ELT_bbox": From_SEG_ELT_bbox,
|
||||
"ImpactFrom_SEG_ELT_crop_region": From_SEG_ELT_crop_region,
|
||||
"ImpactCount_Elts_in_SEGS": Count_Elts_in_SEGS,
|
||||
|
||||
"BboxDetectorCombined_v2": BboxDetectorCombined,
|
||||
"SegmDetectorCombined_v2": SegmDetectorCombined,
|
||||
@@ -209,8 +242,6 @@ NODE_CLASS_MAPPINGS = {
|
||||
"KSamplerAdvancedProvider": KSamplerAdvancedProvider,
|
||||
"TwoAdvancedSamplersForMask": TwoAdvancedSamplersForMask,
|
||||
|
||||
"ImpactNegativeConditioningPlaceholder": NegativeConditioningPlaceholder,
|
||||
|
||||
"PreviewBridge": PreviewBridge,
|
||||
"PreviewBridgeLatent": PreviewBridgeLatent,
|
||||
"ImageSender": ImageSender,
|
||||
@@ -226,8 +257,6 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactWildcardProcessor": ImpactWildcardProcessor,
|
||||
"ImpactWildcardEncode": ImpactWildcardEncode,
|
||||
|
||||
"SEGSUpscaler": SEGSUpscaler,
|
||||
"SEGSUpscalerPipe": SEGSUpscalerPipe,
|
||||
"SEGSDetailer": SEGSDetailer,
|
||||
"SEGSPaste": SEGSPaste,
|
||||
"SEGSPreview": SEGSPreview,
|
||||
@@ -250,8 +279,6 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactImageBatchToImageList": ImageBatchToImageList,
|
||||
"ImpactMakeImageList": MakeImageList,
|
||||
"ImpactMakeImageBatch": MakeImageBatch,
|
||||
"ImpactMakeMaskList": MakeMaskList,
|
||||
"ImpactMakeMaskBatch": MakeMaskBatch,
|
||||
|
||||
"RegionalSampler": RegionalSampler,
|
||||
"RegionalSamplerAdvanced": RegionalSamplerAdvanced,
|
||||
@@ -282,9 +309,6 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactNeg": ImpactNeg,
|
||||
"ImpactConditionalStopIteration": ImpactConditionalStopIteration,
|
||||
"ImpactStringSelector": StringSelector,
|
||||
"StringListToString": StringListToString,
|
||||
"WildcardPromptFromString": WildcardPromptFromString,
|
||||
"ImpactExecutionOrderController": ImpactExecutionOrderController,
|
||||
|
||||
"RemoveNoiseMask": RemoveNoiseMask,
|
||||
|
||||
@@ -302,10 +326,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ImpactRemoteInt": ImpactRemoteInt,
|
||||
|
||||
"ImpactHFTransformersClassifierProvider": HF_TransformersClassifierProvider,
|
||||
"ImpactSEGSClassify": SEGS_Classify,
|
||||
|
||||
"ImpactSchedulerAdapter": ImpactSchedulerAdapter,
|
||||
"GITSSchedulerFuncProvider": GITSSchedulerFuncProvider
|
||||
"ImpactSEGSClassify": SEGS_Classify
|
||||
}
|
||||
|
||||
|
||||
@@ -328,22 +349,19 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"MediaPipeFaceMeshToSEGS": "MediaPipe FaceMesh to SEGS",
|
||||
"MaskToSEGS": "MASK to SEGS",
|
||||
"MaskToSEGS_for_AnimateDiff": "MASK to SEGS for AnimateDiff",
|
||||
"BitwiseAndMaskForEach": "Pixelwise(SEGS & SEGS)",
|
||||
"SubtractMaskForEach": "Pixelwise(SEGS - SEGS)",
|
||||
"ImpactSegsAndMask": "Pixelwise(SEGS & MASK)",
|
||||
"ImpactSegsAndMaskForEach": "Pixelwise(SEGS & MASKS ForEach)",
|
||||
"BitwiseAndMask": "Pixelwise(MASK & MASK)",
|
||||
"SubtractMask": "Pixelwise(MASK - MASK)",
|
||||
"AddMask": "Pixelwise(MASK + MASK)",
|
||||
"ImpactFlattenMask": "Flatten Mask Batch",
|
||||
"BitwiseAndMaskForEach": "Bitwise(SEGS & SEGS)",
|
||||
"SubtractMaskForEach": "Bitwise(SEGS - SEGS)",
|
||||
"ImpactSegsAndMask": "Bitwise(SEGS & MASK)",
|
||||
"ImpactSegsAndMaskForEach": "Bitwise(SEGS & MASKS ForEach)",
|
||||
"BitwiseAndMask": "Bitwise(MASK & MASK)",
|
||||
"SubtractMask": "Bitwise(MASK - MASK)",
|
||||
"AddMask": "Bitwise(MASK + MASK)",
|
||||
"DetailerForEach": "Detailer (SEGS)",
|
||||
"DetailerForEachPipe": "Detailer (SEGS/pipe)",
|
||||
"DetailerForEachDebug": "DetailerDebug (SEGS)",
|
||||
"DetailerForEachDebugPipe": "DetailerDebug (SEGS/pipe)",
|
||||
"SEGSDetailerForAnimateDiff": "SEGSDetailer For AnimateDiff (SEGS/pipe)",
|
||||
"DetailerForEachPipeForAnimateDiff": "Detailer For AnimateDiff (SEGS/pipe)",
|
||||
"SEGSUpscaler": "Upscaler (SEGS)",
|
||||
"SEGSUpscalerPipe": "Upscaler (SEGS/pipe)",
|
||||
|
||||
"SAMDetectorCombined": "SAMDetector (combined)",
|
||||
"SAMDetectorSegmented": "SAMDetector (segmented)",
|
||||
@@ -385,11 +403,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ImpactAssembleSEGS": "Assemble (SEGS)",
|
||||
"ImpactFrom_SEG_ELT": "From SEG_ELT",
|
||||
"ImpactEdit_SEG_ELT": "Edit SEG_ELT",
|
||||
"ImpactFrom_SEG_ELT_bbox": "From SEG_ELT bbox",
|
||||
"ImpactFrom_SEG_ELT_crop_region": "From SEG_ELT crop_region",
|
||||
"ImpactDilate_Mask_SEG_ELT": "Dilate Mask (SEG_ELT)",
|
||||
"ImpactScaleBy_BBOX_SEG_ELT": "ScaleBy BBOX (SEG_ELT)",
|
||||
"ImpactCount_Elts_in_SEGS": "Count Elts in SEGS",
|
||||
"ImpactDilateMask": "Dilate Mask",
|
||||
"ImpactGaussianBlurMask": "Gaussian Blur Mask",
|
||||
"ImpactDilateMaskInSEGS": "Dilate Mask (SEGS)",
|
||||
@@ -402,21 +417,14 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ImageMaskSwitch": "Switch (images, mask)",
|
||||
"ImpactSwitch": "Switch (Any)",
|
||||
"ImpactInversedSwitch": "Inversed Switch (Any)",
|
||||
"ImpactExecutionOrderController": "Execution Order Controller",
|
||||
|
||||
"MasksToMaskList": "Mask Batch to Mask List",
|
||||
"MaskListToMaskBatch": "Mask List to Mask Batch",
|
||||
"ImpactImageBatchToImageList": "Image Batch to Image List",
|
||||
"MasksToMaskList": "Masks to Mask List",
|
||||
"MaskListToMaskBatch": "Mask List to Masks",
|
||||
"ImpactImageBatchToImageList": "Image batch to Image List",
|
||||
"ImageListToImageBatch": "Image List to Image Batch",
|
||||
|
||||
"ImpactMakeImageList": "Make Image List",
|
||||
"ImpactMakeImageBatch": "Make Image Batch",
|
||||
"ImpactMakeMaskList": "Make Mask List",
|
||||
"ImpactMakeMaskBatch": "Make Mask Batch",
|
||||
|
||||
"ImpactStringSelector": "String Selector",
|
||||
"StringListToString": "String List to String",
|
||||
"WildcardPromptFromString": "Wildcard Prompt from String",
|
||||
"ImpactIsNotEmptySEGS": "SEGS isn't Empty",
|
||||
"SetDefaultImageForSEGS": "Set Default Image for SEGS",
|
||||
"RemoveImageFromSEGS": "Remove Image from SEGS",
|
||||
@@ -441,11 +449,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"LatentSwitch": "Switch (latent/legacy)",
|
||||
"SEGSSwitch": "Switch (SEGS/legacy)",
|
||||
|
||||
"SEGSPreviewCNet": "SEGSPreview (CNET Image)",
|
||||
|
||||
"ImpactSchedulerAdapter": "Impact Scheduler Adapter",
|
||||
"GITSSchedulerFuncProvider": "GITSScheduler Func Provider",
|
||||
"ImpactNegativeConditioningPlaceholder": "Negative Cond Placeholder"
|
||||
"SEGSPreviewCNet": "SEGSPreview (CNET Image)"
|
||||
}
|
||||
|
||||
if not impact.config.get_config()['mmdet_skip']:
|
||||
@@ -486,13 +490,7 @@ except Exception as e:
|
||||
traceback.print_exc()
|
||||
print("---------------------------------\n")
|
||||
|
||||
# NOTE: Inject directly into EXTENSION_WEB_DIRS instead of WEB_DIRECTORY
|
||||
# Provide the js path fixed as ComfyUI-Impact-Pack instead of the path name, making it available for external use
|
||||
|
||||
# WEB_DIRECTORY = "js" -- deprecated method
|
||||
nodes.EXTENSION_WEB_DIRS["ComfyUI-Impact-Pack"] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'js')
|
||||
|
||||
|
||||
WEB_DIRECTORY = "js"
|
||||
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
|
||||
|
||||
|
||||
|
||||
+35
-49
@@ -16,24 +16,7 @@ impact_path = os.path.join(os.path.dirname(__file__), "modules")
|
||||
old_subpack_path = os.path.join(os.path.dirname(__file__), "subpack")
|
||||
subpack_path = os.path.join(os.path.dirname(__file__), "impact_subpack")
|
||||
subpack_repo = "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
|
||||
|
||||
|
||||
comfy_path = os.environ.get('COMFYUI_PATH')
|
||||
if comfy_path is None:
|
||||
print(f"\n[bold yellow]WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `{os.path.dirname(__file__)}/../../` as the ComfyUI path.[/bold yellow]", file=sys.stderr)
|
||||
comfy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
|
||||
model_path = os.environ.get('COMFYUI_MODEL_PATH')
|
||||
if model_path is None:
|
||||
try:
|
||||
import folder_paths
|
||||
model_path = folder_paths.models_dir
|
||||
except:
|
||||
pass
|
||||
|
||||
if model_path is None:
|
||||
model_path = os.path.abspath(os.path.join(comfy_path, 'models'))
|
||||
print(f"\n[bold yellow]WARN: The `COMFYUI_MODEL_PATH` environment variable is not set. Assuming `{model_path}` as the ComfyUI path.[/bold yellow]", file=sys.stderr)
|
||||
comfy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
|
||||
|
||||
sys.path.append(impact_path)
|
||||
@@ -51,9 +34,9 @@ def handle_stream(stream, is_stdout):
|
||||
print(msg, end="", file=sys.stderr)
|
||||
|
||||
|
||||
def process_wrap(cmd_str, cwd=None, handler=None, env=None):
|
||||
def process_wrap(cmd_str, cwd=None, handler=None):
|
||||
print(f"[Impact Pack] EXECUTE: {cmd_str} in '{cwd}'")
|
||||
process = subprocess.Popen(cmd_str, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, text=True, bufsize=1)
|
||||
process = subprocess.Popen(cmd_str, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
|
||||
|
||||
if handler is None:
|
||||
handler = handle_stream
|
||||
@@ -113,6 +96,7 @@ def is_requirements_installed(file_path):
|
||||
|
||||
try:
|
||||
import platform
|
||||
import folder_paths
|
||||
from torchvision.datasets.utils import download_url
|
||||
import impact.config
|
||||
|
||||
@@ -121,11 +105,9 @@ try:
|
||||
|
||||
if "python_embeded" in sys.executable or "python_embedded" in sys.executable:
|
||||
pip_install = [sys.executable, '-s', '-m', 'pip', 'install']
|
||||
pip_upgrade = [sys.executable, '-s', '-m', 'pip', 'install', '-U']
|
||||
mim_install = [sys.executable, '-s', '-m', 'mim', 'install']
|
||||
else:
|
||||
pip_install = [sys.executable, '-m', 'pip', 'install']
|
||||
pip_upgrade = [sys.executable, '-m', 'pip', 'install', '-U']
|
||||
mim_install = [sys.executable, '-m', 'mim', 'install']
|
||||
|
||||
|
||||
@@ -149,6 +131,27 @@ try:
|
||||
shutil.rmtree(old_subpack_path)
|
||||
|
||||
|
||||
def remove_olds():
|
||||
global comfy_path
|
||||
|
||||
comfy_path = os.path.dirname(folder_paths.__file__)
|
||||
custom_nodes_path = os.path.join(comfy_path, "custom_nodes")
|
||||
old_ini_path = os.path.join(custom_nodes_path, "impact-pack.ini")
|
||||
old_py_path = os.path.join(custom_nodes_path, "comfyui-impact-pack.py")
|
||||
|
||||
if os.path.exists(impact.config.old_config_path):
|
||||
impact.config.get_config()['mmdet_skip'] = False
|
||||
os.remove(impact.config.old_config_path)
|
||||
|
||||
if os.path.exists(old_ini_path):
|
||||
print(f"Delete legacy file: {old_ini_path}")
|
||||
os.remove(old_ini_path)
|
||||
|
||||
if os.path.exists(old_py_path):
|
||||
print(f"Delete legacy file: {old_py_path}")
|
||||
os.remove(old_py_path)
|
||||
|
||||
|
||||
def ensure_pip_packages_first():
|
||||
subpack_req = os.path.join(subpack_path, "requirements.txt")
|
||||
if os.path.exists(subpack_req) and not is_requirements_installed(subpack_req):
|
||||
@@ -194,30 +197,12 @@ try:
|
||||
|
||||
# !! cv2 importing test must be very last !!
|
||||
try:
|
||||
from cv2 import setNumThreads
|
||||
import cv2
|
||||
except Exception:
|
||||
try:
|
||||
is_open_cv_installed = False
|
||||
|
||||
# upgrade if opencv is installed already
|
||||
if is_installed('opencv-python'):
|
||||
process_wrap(pip_upgrade + ['opencv-python'])
|
||||
is_open_cv_installed = True
|
||||
|
||||
if is_installed('opencv-python-headless'):
|
||||
process_wrap(pip_upgrade + ['opencv-python-headless'])
|
||||
is_open_cv_installed = True
|
||||
|
||||
if is_installed('opencv-contrib-python'):
|
||||
process_wrap(pip_upgrade + ['opencv-contrib-python'])
|
||||
is_open_cv_installed = True
|
||||
|
||||
if is_installed('opencv-contrib-python-headless'):
|
||||
process_wrap(pip_upgrade + ['opencv-contrib-python-headless'])
|
||||
is_open_cv_installed = True
|
||||
|
||||
# if opencv is not installed install `opencv-python-headless`
|
||||
if not is_open_cv_installed:
|
||||
if not is_installed('opencv-python'):
|
||||
process_wrap(pip_install + ['opencv-python'])
|
||||
if not is_installed('opencv-python-headless'):
|
||||
process_wrap(pip_install + ['opencv-python-headless'])
|
||||
except:
|
||||
print(f"[ERROR] ComfyUI-Impact-Pack: failed to install 'opencv-python'. Please, install manually.")
|
||||
@@ -236,6 +221,8 @@ try:
|
||||
|
||||
|
||||
def install():
|
||||
remove_olds()
|
||||
|
||||
subpack_install_script = os.path.join(subpack_path, "install.py")
|
||||
|
||||
print(f"### ComfyUI-Impact-Pack: Updating subpack")
|
||||
@@ -247,12 +234,8 @@ try:
|
||||
|
||||
ensure_subpack() # The installation of the subpack must take place before ensure_pip. cv2 triggers a permission error.
|
||||
|
||||
new_env = os.environ.copy()
|
||||
new_env["COMFYUI_PATH"] = comfy_path
|
||||
new_env["COMFYUI_MODEL_PATH"] = model_path
|
||||
|
||||
if os.path.exists(subpack_install_script):
|
||||
process_wrap([sys.executable, 'install.py'], cwd=subpack_path, env=new_env)
|
||||
process_wrap([sys.executable, 'install.py'], cwd=subpack_path)
|
||||
if not is_requirements_installed(os.path.join(subpack_path, 'requirements.txt')):
|
||||
process_wrap(pip_install + ['-r', 'requirements.txt'], cwd=subpack_path)
|
||||
else:
|
||||
@@ -267,6 +250,9 @@ try:
|
||||
|
||||
# Download model
|
||||
print("### ComfyUI-Impact-Pack: Check basic models")
|
||||
|
||||
model_path = folder_paths.models_dir
|
||||
|
||||
bbox_path = os.path.join(model_path, "mmdets", "bbox")
|
||||
sam_path = os.path.join(model_path, "sams")
|
||||
onnx_path = os.path.join(model_path, "onnx")
|
||||
|
||||
@@ -46,7 +46,7 @@ async function loadImageFromUrl(image, node_id, v, need_to_load) {
|
||||
if(res.status == 200) {
|
||||
let pb_id = await res.text();
|
||||
if(need_to_load) {;
|
||||
image.src = api.apiURL(`/view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`);
|
||||
image.src = `view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`;
|
||||
}
|
||||
return pb_id;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ async function loadImageFromId(image, v) {
|
||||
let res = await api.fetchApi('/impact/get/pb_id_image?id='+v, { cache: "no-store" });
|
||||
if(res.status == 200) {
|
||||
let item = await res.json();
|
||||
image.src = api.apiURL(`/view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`);
|
||||
image.src = `view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ app.registerExtension({
|
||||
|
||||
Object.defineProperty(node, 'imgs', {
|
||||
set(v) {
|
||||
if (v && !v[0].complete) {
|
||||
if (!v[0].complete) {
|
||||
let orig_onload = v[0].onload;
|
||||
v[0].onload = function(v2) {
|
||||
if(orig_onload)
|
||||
@@ -209,7 +209,7 @@ app.registerExtension({
|
||||
|
||||
let res = api.fetchApi('/view/validate'+params, { cache: "no-store" }).then(response => response);
|
||||
if(res.status == 200) {
|
||||
image.src = api.apiURL('/view'+params);
|
||||
image.src = 'view'+params;
|
||||
}
|
||||
|
||||
this._img = [new Image()]; // placeholder
|
||||
|
||||
+4
-30
@@ -116,27 +116,7 @@ function imgSendHandler(event) {
|
||||
let nodes = app.graph._nodes;
|
||||
for(let i in nodes) {
|
||||
if(nodes[i].type == 'ImageReceiver') {
|
||||
let is_linked = false;
|
||||
|
||||
if(nodes[i].widgets[1].type == 'converted-widget') {
|
||||
for(let j in nodes[i].inputs) {
|
||||
let input = nodes[i].inputs[j];
|
||||
if(input.name === 'link_id') {
|
||||
if(input.link) {
|
||||
let src_node = app.graph._nodes_by_id[app.graph.links[input.link].origin_id];
|
||||
if(src_node.type == 'ImpactInt' || src_node.type == 'PrimitiveNode') {
|
||||
is_linked = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(nodes[i].widgets[1].value == event.detail.link_id) {
|
||||
is_linked = true;
|
||||
}
|
||||
|
||||
if(is_linked) {
|
||||
if(nodes[i].widgets[1].value == event.detail.link_id) {
|
||||
if(data.subfolder)
|
||||
nodes[i].widgets[0].value = `${data.subfolder}/${data.filename} [${data.type}]`;
|
||||
else
|
||||
@@ -237,7 +217,7 @@ app.registerExtension({
|
||||
if(nodeData.name == "ImpactControlBridge") {
|
||||
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
|
||||
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
|
||||
if(index != 0 || !link_info || this.inputs[0].type != '*')
|
||||
if(!link_info || this.inputs[0].type != '*')
|
||||
return;
|
||||
|
||||
// assign type
|
||||
@@ -393,7 +373,6 @@ app.registerExtension({
|
||||
}
|
||||
|
||||
if (nodeData.name === 'ImpactMakeImageList' || nodeData.name === 'ImpactMakeImageBatch' ||
|
||||
nodeData.name === 'ImpactMakeMaskList' || nodeData.name === 'ImpactMakeMaskBatch' ||
|
||||
nodeData.name === 'CombineRegionalPrompts' ||
|
||||
nodeData.name === 'ImpactCombineConditionings' || nodeData.name === 'ImpactConcatConditionings' ||
|
||||
nodeData.name === 'ImpactSEGSConcat' ||
|
||||
@@ -406,11 +385,6 @@ app.registerExtension({
|
||||
input_name = "image";
|
||||
break;
|
||||
|
||||
case 'ImpactMakeMaskList':
|
||||
case 'ImpactMakeMaskBatch':
|
||||
input_name = "mask";
|
||||
break;
|
||||
|
||||
case 'ImpactSEGSConcat':
|
||||
input_name = "segs";
|
||||
break;
|
||||
@@ -513,7 +487,7 @@ app.registerExtension({
|
||||
!stackTrace.includes('LGraphNode.connect') && // for mouse device
|
||||
!stackTrace.includes('loadGraphData') &&
|
||||
this.inputs[index].name != 'select') {
|
||||
this.removeInput(index);
|
||||
this.removeInput(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,7 +578,7 @@ app.registerExtension({
|
||||
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');
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { api } from "../../scripts/api.js";
|
||||
import { ComfyDialog, $el } from "../../scripts/ui.js";
|
||||
import { ComfyApp } from "../../scripts/app.js";
|
||||
import { ClipspaceDialog } from "../../extensions/core/clipspace.js";
|
||||
@@ -43,7 +42,7 @@ function loadedImageToBlob(image) {
|
||||
}
|
||||
|
||||
async function uploadMask(filepath, formData) {
|
||||
await api.fetchApi('/upload/mask', {
|
||||
await fetch('/upload/mask', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
}).then(response => {}).catch(error => {
|
||||
@@ -435,7 +434,7 @@ class ImpactSamEditorDialog extends ComfyDialog {
|
||||
ctx.arc(scaledX, scaledY, 3, 0, 3 * Math.PI);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}줘
|
||||
|
||||
invalidateMaskCanvas(self) {
|
||||
if(self.mask_image) {
|
||||
@@ -459,7 +458,7 @@ class ImpactSamEditorDialog extends ComfyDialog {
|
||||
subfolder: subfolder
|
||||
};
|
||||
|
||||
api.fetchApi('/sam/prepare', {
|
||||
fetch('/sam/prepare', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
@@ -485,7 +484,7 @@ class ImpactSamEditorDialog extends ComfyDialog {
|
||||
threshold: self.confidence/100
|
||||
};
|
||||
|
||||
const response = await api.fetchApi('/sam/detect', {
|
||||
const response = await fetch('/sam/detect', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'image/png' },
|
||||
body: JSON.stringify(data)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { ComfyApp, app } from "../../scripts/app.js";
|
||||
import { api } from "../../scripts/api.js";
|
||||
|
||||
let refresh_btn = document.getElementById('comfy-refresh-button');
|
||||
let refresh_btn2 = document.querySelector('button[title="Refresh widgets in nodes to find new models or files"]');
|
||||
|
||||
let orig = refresh_btn.onclick;
|
||||
|
||||
if(refresh_btn) {
|
||||
refresh_btn.onclick = function() {
|
||||
orig();
|
||||
api.fetchApi('/impact/wildcards/refresh');
|
||||
};
|
||||
}
|
||||
|
||||
if(refresh_btn2) {
|
||||
refresh_btn2?.addEventListener('click', function() {
|
||||
api.fetchApi('/impact/wildcards/refresh');
|
||||
});
|
||||
}
|
||||
@@ -11,22 +11,22 @@ class SEGSDetailerForAnimateDiff:
|
||||
return {"required": {
|
||||
"image_frames": ("IMAGE", ),
|
||||
"segs": ("SEGS", ),
|
||||
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": MAX_RESOLUTION, "step": 8}),
|
||||
"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": (core.SCHEDULERS,),
|
||||
"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}),
|
||||
"refiner_ratio": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0})
|
||||
},
|
||||
"optional": {
|
||||
"refiner_basic_pipe_opt": ("BASIC_PIPE",),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
# 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}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class SEGSDetailerForAnimateDiff:
|
||||
|
||||
@staticmethod
|
||||
def do_detail(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, basic_pipe, refiner_ratio=None, refiner_basic_pipe_opt=None, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
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:
|
||||
@@ -66,31 +66,13 @@ class SEGSDetailerForAnimateDiff:
|
||||
cropped_image_frames = torch.concat((cropped_image_frames, cropped_image), dim=0)
|
||||
|
||||
cropped_image_frames = cropped_image_frames.cpu().numpy()
|
||||
|
||||
# It is assumed that AnimateDiff does not support conditioning masks based on test results, but it will be added for future consideration.
|
||||
cropped_positive = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, cropped_image_frames, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in positive
|
||||
]
|
||||
|
||||
cropped_negative = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, cropped_image_frames, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in negative
|
||||
]
|
||||
|
||||
enhanced_image_tensor, cnet_images = core.enhance_detail_for_animatediff(cropped_image_frames, model, clip, vae, guide_size, guide_size_for, max_size,
|
||||
seg.bbox, seed, steps, cfg, sampler_name, scheduler,
|
||||
cropped_positive, cropped_negative, denoise, seg.cropped_mask,
|
||||
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,
|
||||
noise_mask_feather=noise_mask_feather, scheduler_func=scheduler_func_opt)
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
if cnet_images is not None:
|
||||
cnet_image_list.extend(cnet_images)
|
||||
|
||||
@@ -105,11 +87,11 @@ class SEGSDetailerForAnimateDiff:
|
||||
return (segs[0], new_segs), cnet_image_list
|
||||
|
||||
def doit(self, image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, basic_pipe, refiner_ratio=None, refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
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,
|
||||
noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
if len(cnet_images) == 0:
|
||||
cnet_images = [empty_pil_tensor()]
|
||||
@@ -123,25 +105,25 @@ class DetailerForEachPipeForAnimateDiff:
|
||||
return {"required": {
|
||||
"image_frames": ("IMAGE", ),
|
||||
"segs": ("SEGS", ),
|
||||
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"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": (core.SCHEDULERS,),
|
||||
"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",),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
}
|
||||
"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")
|
||||
@@ -154,7 +136,7 @@ class DetailerForEachPipeForAnimateDiff:
|
||||
@staticmethod
|
||||
def doit(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, feather, basic_pipe, refiner_ratio=None, detailer_hook=None, refiner_basic_pipe_opt=None,
|
||||
noise_mask_feather=0, scheduler_func_opt=None):
|
||||
inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
enhanced_segs = []
|
||||
cnet_image_list = []
|
||||
@@ -162,7 +144,7 @@ class DetailerForEachPipeForAnimateDiff:
|
||||
for sub_seg in segs[1]:
|
||||
single_seg = segs[0], [sub_seg]
|
||||
enhanced_seg, cnet_images = SEGSDetailerForAnimateDiff().do_detail(image_frames, single_seg, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, basic_pipe, refiner_ratio, refiner_basic_pipe_opt, noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
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]
|
||||
|
||||
@@ -170,7 +152,7 @@ class DetailerForEachPipeForAnimateDiff:
|
||||
cnet_image_list.extend(cnet_images)
|
||||
|
||||
if detailer_hook is not None:
|
||||
image_frames = detailer_hook.post_paste(image_frames)
|
||||
detailer_hook.post_paste(image_frames)
|
||||
|
||||
enhanced_segs += enhanced_seg[1]
|
||||
|
||||
|
||||
+29
-113
@@ -1,17 +1,10 @@
|
||||
import os
|
||||
from PIL import ImageOps
|
||||
from impact.utils import *
|
||||
import latent_preview
|
||||
|
||||
|
||||
# NOTE: this should not be `from . import core`.
|
||||
# I don't know why but... 'from .' and 'from impact' refer to different core modules.
|
||||
# This separates global variables of the core module and breaks the preview bridge.
|
||||
from impact import core
|
||||
# <--
|
||||
from . import core
|
||||
import random
|
||||
|
||||
|
||||
class PreviewBridge:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -19,10 +12,7 @@ class PreviewBridge:
|
||||
"images": ("IMAGE",),
|
||||
"image": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"block": ("BOOLEAN", {"default": False, "label_on": "if_empty_mask", "label_off": "never", "tooltip": "is_empty_mask: If the mask is empty, the execution is stopped.\nnever: The execution is never stopped."})
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID", "extra_pnginfo": "EXTRA_PNGINFO"},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "MASK", )
|
||||
@@ -33,8 +23,6 @@ class PreviewBridge:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
DESCRIPTION = "This is a feature that allows you to edit and send a Mask over a image.\nIf the block is set to 'is_empty_mask', the execution is stopped when the mask is empty."
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.output_dir = folder_paths.get_temp_directory()
|
||||
@@ -75,7 +63,7 @@ class PreviewBridge:
|
||||
|
||||
return image, mask.unsqueeze(0), ui_item
|
||||
|
||||
def doit(self, images, image, unique_id, block=False, prompt=None, extra_pnginfo=None):
|
||||
def doit(self, images, image, unique_id):
|
||||
need_refresh = False
|
||||
|
||||
if unique_id not in core.preview_bridge_cache:
|
||||
@@ -88,7 +76,7 @@ class PreviewBridge:
|
||||
pixels, mask, path_item = PreviewBridge.load_image(image)
|
||||
image = [path_item]
|
||||
else:
|
||||
res = nodes.PreviewImage().save_images(images, filename_prefix="PreviewBridge/PB-", prompt=prompt, extra_pnginfo=extra_pnginfo)
|
||||
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")
|
||||
@@ -101,85 +89,44 @@ class PreviewBridge:
|
||||
|
||||
image = image2
|
||||
|
||||
is_empty_mask = torch.all(mask == 0)
|
||||
|
||||
if block and is_empty_mask and core.is_execution_model_version_supported:
|
||||
from comfy_execution.graph import ExecutionBlocker
|
||||
result = ExecutionBlocker(None), ExecutionBlocker(None)
|
||||
elif block and is_empty_mask:
|
||||
print(f"[Impact Pack] PreviewBridge: ComfyUI is outdated - blocking feature is disabled.")
|
||||
result = pixels, mask
|
||||
else:
|
||||
result = pixels, mask
|
||||
|
||||
return {
|
||||
"ui": {"images": image},
|
||||
"result": result,
|
||||
"result": (pixels, mask, ),
|
||||
}
|
||||
|
||||
|
||||
def decode_latent(latent, preview_method, vae_opt=None):
|
||||
def decode_latent(latent_tensor, preview_method, vae_opt=None):
|
||||
if vae_opt is not None:
|
||||
image = nodes.VAEDecode().decode(vae_opt, latent)[0]
|
||||
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"):
|
||||
decoder_name = None
|
||||
|
||||
if preview_method == "TAESD15":
|
||||
decoder_name = "taesd"
|
||||
elif preview_method == 'TAESDXL':
|
||||
else:
|
||||
decoder_name = "taesdxl"
|
||||
elif preview_method == 'TAESD3':
|
||||
decoder_name = "taesd3"
|
||||
elif preview_method == 'TAEF1':
|
||||
decoder_name = "taef1"
|
||||
|
||||
if decoder_name:
|
||||
vae = nodes.VAELoader().load_vae(decoder_name)[0]
|
||||
image = nodes.VAEDecode().decode(vae, latent)[0]
|
||||
return image
|
||||
vae = nodes.VAELoader().load_vae(decoder_name)[0]
|
||||
image = nodes.VAEDecode().decode(vae, latent_tensor)[0]
|
||||
return image
|
||||
|
||||
if preview_method == "Latent2RGB-SD15":
|
||||
latent_format = latent_formats.SD15()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
elif preview_method == "Latent2RGB-SDXL":
|
||||
latent_format = latent_formats.SDXL()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
elif preview_method == "Latent2RGB-SD3":
|
||||
latent_format = latent_formats.SD3()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
elif preview_method == "Latent2RGB-SD-X4":
|
||||
latent_format = latent_formats.SD_X4()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
elif preview_method == "Latent2RGB-Playground-2.5":
|
||||
latent_format = latent_formats.SDXL_Playground_2_5()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
elif preview_method == "Latent2RGB-SC-Prior":
|
||||
latent_format = latent_formats.SC_Prior()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
elif preview_method == "Latent2RGB-SC-B":
|
||||
latent_format = latent_formats.SC_B()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
elif preview_method == "Latent2RGB-FLUX.1":
|
||||
latent_format = latent_formats.Flux()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
else:
|
||||
print(f"[Impact Pack] PreviewBridgeLatent: '{preview_method}' is unsupported preview method.")
|
||||
latent_format = latent_formats.SD15()
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
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)
|
||||
samples = latent_format.process_in(latent['samples'])
|
||||
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)
|
||||
|
||||
pil_image = previewer.decode_latent_to_preview(samples)
|
||||
pixels_size = pil_image.size[0]*8, pil_image.size[1]*8
|
||||
resized_image = pil_image.resize(pixels_size, resample=LANCZOS)
|
||||
|
||||
return to_tensor(resized_image).unsqueeze(0)
|
||||
return to_tensor(resized_image).unsqueeze(0)
|
||||
|
||||
|
||||
class PreviewBridgeLatent:
|
||||
@@ -188,17 +135,12 @@ class PreviewBridgeLatent:
|
||||
return {"required": {
|
||||
"latent": ("LATENT",),
|
||||
"image": ("STRING", {"default": ""}),
|
||||
"preview_method": (["Latent2RGB-FLUX.1",
|
||||
"Latent2RGB-SDXL", "Latent2RGB-SD15", "Latent2RGB-SD3",
|
||||
"Latent2RGB-SD-X4", "Latent2RGB-Playground-2.5",
|
||||
"Latent2RGB-SC-Prior", "Latent2RGB-SC-B",
|
||||
"TAEF1", "TAESDXL", "TAESD15", "TAESD3"],),
|
||||
"preview_method": (["Latent2RGB-SDXL", "Latent2RGB-SD15", "TAESDXL", "TAESD15"],),
|
||||
},
|
||||
"optional": {
|
||||
"vae_opt": ("VAE", ),
|
||||
"block": ("BOOLEAN", {"default": False, "label_on": "if_empty_mask", "label_off": "never", "tooltip": "is_empty_mask: If the mask is empty, the execution is stopped.\nnever: The execution is never stopped. Instead, it returns a white mask."})
|
||||
"vae_opt": ("VAE", )
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID", "prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("LATENT", "MASK", )
|
||||
@@ -209,8 +151,6 @@ class PreviewBridgeLatent:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
DESCRIPTION = "This is a feature that allows you to edit and send a Mask over a latent image.\nIf the block is set to 'is_empty_mask', the execution is stopped when the mask is empty."
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.output_dir = folder_paths.get_temp_directory()
|
||||
@@ -252,14 +192,7 @@ class PreviewBridgeLatent:
|
||||
|
||||
return image, mask, ui_item
|
||||
|
||||
def doit(self, latent, image, preview_method, vae_opt=None, block=False, unique_id=None, prompt=None, extra_pnginfo=None):
|
||||
latent_channels = latent['samples'].shape[1]
|
||||
preview_method_channels = 16 if 'SD3' in preview_method or 'SC-Prior' in preview_method or 'FLUX.1' in preview_method or 'TAEF1' == preview_method else 4
|
||||
|
||||
if vae_opt is None and latent_channels != preview_method_channels:
|
||||
print(f"[PreviewBridgeLatent] The version of latent is not compatible with preview_method.\nSD3, SD1/SD2, SDXL, SC-Prior, SC-B and FLUX.1 are not compatible with each other.")
|
||||
raise Exception("The version of latent is not compatible with preview_method.<BR>SD3, SD1/SD2, SDXL, SC-Prior, SC-B and FLUX.1 are not compatible with each other.")
|
||||
|
||||
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:
|
||||
@@ -281,20 +214,16 @@ class PreviewBridgeLatent:
|
||||
del res_latent['noise_mask']
|
||||
else:
|
||||
res_latent = latent
|
||||
|
||||
is_empty_mask = True
|
||||
else:
|
||||
res_latent = latent.copy()
|
||||
res_latent['noise_mask'] = mask
|
||||
|
||||
is_empty_mask = torch.all(mask == 1)
|
||||
|
||||
res_image = [path_item]
|
||||
else:
|
||||
decoded_image = decode_latent(latent, preview_method, vae_opt)
|
||||
|
||||
if 'noise_mask' in latent:
|
||||
mask = latent['noise_mask'].squeeze(0) # 4D mask -> 3D mask
|
||||
mask = latent['noise_mask']
|
||||
|
||||
decoded_pil = to_pil(decoded_image)
|
||||
|
||||
@@ -310,15 +239,11 @@ class PreviewBridgeLatent:
|
||||
'subfolder': 'PreviewBridge',
|
||||
'type': 'temp',
|
||||
}]
|
||||
|
||||
is_empty_mask = torch.all(mask == 1)
|
||||
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-", prompt=prompt, extra_pnginfo=extra_pnginfo)
|
||||
res = nodes.PreviewImage().save_images(decoded_image, filename_prefix="PreviewBridge/PBL-")
|
||||
res_image = res['ui']['images']
|
||||
|
||||
is_empty_mask = True
|
||||
|
||||
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])
|
||||
@@ -327,16 +252,7 @@ class PreviewBridgeLatent:
|
||||
|
||||
res_latent = latent
|
||||
|
||||
if block and is_empty_mask and core.is_execution_model_version_supported:
|
||||
from comfy_execution.graph import ExecutionBlocker
|
||||
result = ExecutionBlocker(None), ExecutionBlocker(None)
|
||||
elif block and is_empty_mask:
|
||||
print(f"[Impact Pack] PreviewBridgeLatent: ComfyUI is outdated - blocking feature is disabled.")
|
||||
result = res_latent, mask
|
||||
else:
|
||||
result = res_latent, mask
|
||||
|
||||
return {
|
||||
"ui": {"images": res_image},
|
||||
"result": result,
|
||||
"result": (res_latent, mask, ),
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import configparser
|
||||
import os
|
||||
|
||||
version_code = [7, 5]
|
||||
|
||||
version_code = [4, 81]
|
||||
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
|
||||
|
||||
dependency_version = 22
|
||||
dependency_version = 20
|
||||
|
||||
my_path = os.path.dirname(__file__)
|
||||
old_config_path = os.path.join(my_path, "impact-pack.ini")
|
||||
config_path = os.path.join(my_path, "..", "..", "impact-pack.ini")
|
||||
latent_letter_path = os.path.join(my_path, "..", "..", "latent.png")
|
||||
|
||||
MAX_RESOLUTION = 8192
|
||||
|
||||
|
||||
def write_config():
|
||||
config = configparser.ConfigParser()
|
||||
@@ -32,15 +35,11 @@ def read_config():
|
||||
config.read(config_path)
|
||||
default_conf = config['default']
|
||||
|
||||
if not os.path.exists(default_conf['custom_wildcards']):
|
||||
print(f"[WARN] ComfyUI-Impact-Pack: custom_wildcards path not found: {default_conf['custom_wildcards']}. Using default path.")
|
||||
default_conf['custom_wildcards'] = os.path.join(my_path, "..", "..", "custom_wildcards")
|
||||
|
||||
return {
|
||||
'dependency_version': int(default_conf['dependency_version']),
|
||||
'mmdet_skip': default_conf['mmdet_skip'].lower() == 'true' if 'mmdet_skip' in default_conf else True,
|
||||
'sam_editor_cpu': default_conf['sam_editor_cpu'].lower() == 'true' if 'sam_editor_cpu' in default_conf else False,
|
||||
'sam_editor_model': default_conf['sam_editor_model'].lower() if 'sam_editor_model' else 'sam_vit_b_01ec64.pth',
|
||||
'sam_editor_model': 'sam_vit_b_01ec64.pth',
|
||||
'custom_wildcards': default_conf['custom_wildcards'] if 'custom_wildcards' in default_conf else os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "custom_wildcards")),
|
||||
'disable_gpu_opencv': default_conf['disable_gpu_opencv'].lower() == 'true' if 'disable_gpu_opencv' in default_conf else True
|
||||
}
|
||||
|
||||
+139
-366
@@ -1,12 +1,6 @@
|
||||
import copy
|
||||
import os
|
||||
import warnings
|
||||
|
||||
import numpy
|
||||
import torch
|
||||
from segment_anything import SamPredictor
|
||||
|
||||
from comfy_extras.nodes_custom_sampler import Noise_RandomNoise
|
||||
from impact.utils import *
|
||||
from collections import namedtuple
|
||||
import numpy as np
|
||||
@@ -24,12 +18,7 @@ from comfy import model_management
|
||||
from impact import utils
|
||||
from impact import impact_sampling
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
try:
|
||||
from comfy_extras import nodes_differential_diffusion
|
||||
except Exception:
|
||||
print(f"\n#############################################\n[Impact Pack] ComfyUI is an outdated version.\n#############################################\n")
|
||||
raise Exception("[Impact Pack] ComfyUI is an outdated version.")
|
||||
from comfy.ldm.cascade.stage_c_coder import StageC_coder
|
||||
|
||||
|
||||
SEG = namedtuple("SEG",
|
||||
@@ -40,17 +29,6 @@ pb_id_cnt = time.time()
|
||||
preview_bridge_image_id_map = {}
|
||||
preview_bridge_image_name_map = {}
|
||||
preview_bridge_cache = {}
|
||||
current_prompt = None
|
||||
|
||||
SCHEDULERS = comfy.samplers.KSampler.SCHEDULERS + ['AYS SDXL', 'AYS SD1', 'AYS SVD', 'GITS[coeff=1.2]']
|
||||
|
||||
|
||||
def is_execution_model_version_supported():
|
||||
try:
|
||||
import comfy_execution
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def set_previewbridge_image(node_id, file, item):
|
||||
@@ -89,60 +67,19 @@ def erosion_mask(mask, grow_mask_by):
|
||||
return mask_erosion[:, :, :w, :h].round().cpu()
|
||||
|
||||
|
||||
# CREDIT: https://github.com/BlenderNeko/ComfyUI_Noise/blob/afb14757216257b12268c91845eac248727a55e2/nodes.py#L68
|
||||
# https://discuss.pytorch.org/t/help-regarding-slerp-function-for-generative-model-sampling/32475/3
|
||||
def slerp(val, low, high):
|
||||
dims = low.shape
|
||||
|
||||
low = low.reshape(dims[0], -1)
|
||||
high = high.reshape(dims[0], -1)
|
||||
|
||||
low_norm = low/torch.norm(low, dim=1, keepdim=True)
|
||||
high_norm = high/torch.norm(high, dim=1, keepdim=True)
|
||||
|
||||
low_norm[low_norm != low_norm] = 0.0
|
||||
high_norm[high_norm != high_norm] = 0.0
|
||||
|
||||
omega = torch.acos((low_norm*high_norm).sum(1))
|
||||
so = torch.sin(omega)
|
||||
res = (torch.sin((1.0-val)*omega)/so).unsqueeze(1)*low + (torch.sin(val*omega)/so).unsqueeze(1) * high
|
||||
|
||||
return res.reshape(dims)
|
||||
|
||||
|
||||
def mix_noise(from_noise, to_noise, strength, variation_method):
|
||||
if variation_method == 'slerp':
|
||||
mixed_noise = slerp(strength, from_noise, to_noise)
|
||||
else:
|
||||
# linear
|
||||
mixed_noise = (1 - strength) * from_noise + strength * to_noise
|
||||
|
||||
# NOTE: Since the variance of the Gaussian noise in mixed_noise has changed, it must be corrected through scaling.
|
||||
scale_factor = math.sqrt((1 - strength) ** 2 + strength ** 2)
|
||||
mixed_noise /= scale_factor
|
||||
|
||||
return mixed_noise
|
||||
|
||||
|
||||
class REGIONAL_PROMPT:
|
||||
def __init__(self, mask, sampler, variation_seed=0, variation_strength=0.0, variation_method='linear'):
|
||||
def __init__(self, mask, sampler):
|
||||
mask = make_2d_mask(mask)
|
||||
|
||||
self.mask = mask
|
||||
self.sampler = sampler
|
||||
self.mask_erosion = None
|
||||
self.erosion_factor = None
|
||||
self.variation_seed = variation_seed
|
||||
self.variation_strength = variation_strength
|
||||
self.variation_method = variation_method
|
||||
|
||||
def clone_with_sampler(self, sampler):
|
||||
rp = REGIONAL_PROMPT(self.mask, sampler)
|
||||
rp.mask_erosion = self.mask_erosion
|
||||
rp.erosion_factor = self.erosion_factor
|
||||
rp.variation_seed = self.variation_seed
|
||||
rp.variation_strength = self.variation_strength
|
||||
rp.variation_method = self.variation_method
|
||||
return rp
|
||||
|
||||
def get_mask_erosion(self, factor):
|
||||
@@ -152,18 +89,6 @@ class REGIONAL_PROMPT:
|
||||
|
||||
return self.mask_erosion
|
||||
|
||||
def touch_noise(self, noise):
|
||||
if self.variation_strength > 0.0:
|
||||
mask = utils.make_3d_mask(self.mask)
|
||||
mask = utils.resize_mask(mask, (noise.shape[2], noise.shape[3])).unsqueeze(0)
|
||||
|
||||
regional_noise = Noise_RandomNoise(self.variation_seed).generate_noise({'samples': noise})
|
||||
mixed_noise = mix_noise(noise, regional_noise, self.variation_strength, variation_method=self.variation_method)
|
||||
|
||||
return (mask == 1).float() * mixed_noise + (mask == 0).float() * noise
|
||||
|
||||
return noise
|
||||
|
||||
|
||||
class NO_BBOX_DETECTOR:
|
||||
pass
|
||||
@@ -231,15 +156,12 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
|
||||
detailer_hook=None,
|
||||
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None,
|
||||
refiner_negative=None, control_net_wrapper=None, cycle=1,
|
||||
inpaint_model=False, noise_mask_feather=0, scheduler_func=None):
|
||||
inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
if noise_mask is not None:
|
||||
noise_mask = utils.tensor_gaussian_blur_mask(noise_mask, noise_mask_feather)
|
||||
noise_mask = noise_mask.squeeze(3)
|
||||
|
||||
if noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
|
||||
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
|
||||
|
||||
if wildcard_opt is not None and wildcard_opt != "":
|
||||
model, _, wildcard_positive = wildcards.process_with_loras(wildcard_opt, model, clip)
|
||||
|
||||
@@ -247,11 +169,6 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
|
||||
positive = nodes.ConditioningConcat().concat(positive, wildcard_positive)[0]
|
||||
else:
|
||||
positive = wildcard_positive
|
||||
positive = [positive[0].copy()]
|
||||
if 'pooled_output' in wildcard_positive[0][1]:
|
||||
positive[0][1]['pooled_output'] = wildcard_positive[0][1]['pooled_output']
|
||||
elif 'pooled_output' in positive[0][1]:
|
||||
del positive[0][1]['pooled_output']
|
||||
|
||||
h = image.shape[1]
|
||||
w = image.shape[2]
|
||||
@@ -298,6 +215,20 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
|
||||
new_w = w
|
||||
new_h = h
|
||||
|
||||
is_stable_cascade_mode = isinstance(vae.first_stage_model, StageC_coder)
|
||||
|
||||
if is_stable_cascade_mode:
|
||||
dw = new_w % 8
|
||||
dh = new_h % 8
|
||||
|
||||
# preserve aspect ratio as possible
|
||||
if dw > 3 or dh > 3:
|
||||
new_w += 8 - dw
|
||||
new_h += 8 - dh
|
||||
elif dw > 0 or dh > 0:
|
||||
new_w -= dw
|
||||
new_h -= dh
|
||||
|
||||
if detailer_hook is not None:
|
||||
new_w, new_h = detailer_hook.touch_scaled_size(new_w, new_h)
|
||||
|
||||
@@ -316,7 +247,14 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
|
||||
if noise_mask is not None and inpaint_model:
|
||||
positive, negative, latent_image = nodes.InpaintModelConditioning().encode(positive, negative, upscaled_image, vae, noise_mask)
|
||||
else:
|
||||
latent_image = to_latent_image(upscaled_image, vae)
|
||||
if is_stable_cascade_mode:
|
||||
latent_image = detailer_hook.stable_cascade_vae_encode(vae, upscaled_image)
|
||||
if latent_image is None:
|
||||
print(f"[Impact Pack] When using the StableCascade model, it is necessary to connect the StableCascade_DetailerHook.")
|
||||
raise Exception("StableCascade_DetailerHook is not provided.")
|
||||
else:
|
||||
latent_image = to_latent_image(upscaled_image, vae)
|
||||
|
||||
if noise_mask is not None:
|
||||
latent_image['noise_mask'] = noise_mask
|
||||
|
||||
@@ -335,28 +273,24 @@ def enhance_detail(image, model, clip, vae, guide_size, guide_size_for_bbox, max
|
||||
|
||||
model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2, upscaled_latent2, denoise2 = \
|
||||
detailer_hook.pre_ksample(model, seed+i, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)
|
||||
noise, is_touched = detailer_hook.get_custom_noise(seed+i, torch.zeros(latent_image['samples'].size()), is_touched=False)
|
||||
if not is_touched:
|
||||
noise = None
|
||||
else:
|
||||
model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2, upscaled_latent2, denoise2 = \
|
||||
model, seed + i, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise
|
||||
noise = None
|
||||
|
||||
refined_latent = impact_sampling.ksampler_wrapper(model2, seed2, steps2, cfg2, sampler_name2, scheduler2, positive2, negative2,
|
||||
refined_latent, denoise2, refiner_ratio, refiner_model, refiner_clip, refiner_positive, refiner_negative,
|
||||
noise=noise, scheduler_func=scheduler_func)
|
||||
|
||||
if detailer_hook is not None:
|
||||
refined_latent = detailer_hook.pre_decode(refined_latent)
|
||||
refined_latent, denoise2, refiner_ratio, refiner_model, refiner_clip, refiner_positive, refiner_negative)
|
||||
|
||||
# non-latent downscale - latent downscale cause bad quality
|
||||
try:
|
||||
# try to decode image normally
|
||||
if detailer_hook is not None:
|
||||
refined_latent = detailer_hook.pre_decode(refined_latent)
|
||||
stage_b = detailer_hook.stable_cascade_stage_b(image, positive, negative, refined_latent)
|
||||
else:
|
||||
stage_b = None
|
||||
|
||||
if stage_b is None:
|
||||
refined_image = vae.decode(refined_latent['samples'])
|
||||
except Exception as e:
|
||||
#usually an out-of-memory exception from the decode, so try a tiled approach
|
||||
refined_image = vae.decode_tiled(refined_latent["samples"], tile_x=64, tile_y=64, )
|
||||
else:
|
||||
refined_image = stage_b
|
||||
|
||||
if detailer_hook is not None:
|
||||
refined_image = detailer_hook.post_decode(refined_image)
|
||||
@@ -378,14 +312,11 @@ def enhance_detail_for_animatediff(image_frames, model, clip, vae, guide_size, g
|
||||
wildcard_opt=None, wildcard_opt_concat_mode=None,
|
||||
detailer_hook=None,
|
||||
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None,
|
||||
refiner_negative=None, control_net_wrapper=None, noise_mask_feather=0, scheduler_func=None):
|
||||
refiner_negative=None, control_net_wrapper=None, inpaint_model=False, noise_mask_feather=0):
|
||||
if noise_mask is not None:
|
||||
noise_mask = utils.tensor_gaussian_blur_mask(noise_mask, noise_mask_feather)
|
||||
noise_mask = noise_mask.squeeze(3)
|
||||
|
||||
if noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
|
||||
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
|
||||
|
||||
if wildcard_opt is not None and wildcard_opt != "":
|
||||
model, _, wildcard_positive = wildcards.process_with_loras(wildcard_opt, model, clip)
|
||||
|
||||
@@ -492,7 +423,7 @@ def enhance_detail_for_animatediff(image_frames, model, clip, vae, guide_size, g
|
||||
latent = detailer_hook.post_encode(latent)
|
||||
|
||||
refined_latent = impact_sampling.ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
|
||||
latent, denoise, refiner_ratio, refiner_model, refiner_clip, refiner_positive, refiner_negative, scheduler_func=scheduler_func)
|
||||
latent, denoise, refiner_ratio, refiner_model, refiner_clip, refiner_positive, refiner_negative)
|
||||
|
||||
if detailer_hook is not None:
|
||||
refined_latent = detailer_hook.pre_decode(refined_latent)
|
||||
@@ -558,61 +489,16 @@ def sam_predict(predictor, points, plabs, bbox, threshold):
|
||||
return total_masks
|
||||
|
||||
|
||||
class SAMWrapper:
|
||||
def __init__(self, model, is_auto_mode, safe_to_gpu=None):
|
||||
self.model = model
|
||||
self.safe_to_gpu = safe_to_gpu if safe_to_gpu is not None else SafeToGPU_stub()
|
||||
self.is_auto_mode = is_auto_mode
|
||||
|
||||
def prepare_device(self):
|
||||
if self.is_auto_mode:
|
||||
device = comfy.model_management.get_torch_device()
|
||||
self.safe_to_gpu.to_device(self.model, device=device)
|
||||
|
||||
def release_device(self):
|
||||
if self.is_auto_mode:
|
||||
self.model.to(device="cpu")
|
||||
|
||||
def predict(self, image, points, plabs, bbox, threshold):
|
||||
predictor = SamPredictor(self.model)
|
||||
predictor.set_image(image, "RGB")
|
||||
|
||||
return sam_predict(predictor, points, plabs, bbox, threshold)
|
||||
|
||||
|
||||
class ESAMWrapper:
|
||||
def __init__(self, model, device):
|
||||
self.model = model
|
||||
self.func_inference = nodes.NODE_CLASS_MAPPINGS['Yoloworld_ESAM_Zho']
|
||||
self.device = device
|
||||
|
||||
def prepare_device(self):
|
||||
pass
|
||||
|
||||
def release_device(self):
|
||||
pass
|
||||
|
||||
def predict(self, image, points, plabs, bbox, threshold):
|
||||
if self.device == 'CPU':
|
||||
self.device = 'cpu'
|
||||
else:
|
||||
self.device = 'cuda'
|
||||
|
||||
detected_masks = self.func_inference.inference_sam_with_boxes(image=image, xyxy=[bbox], model=self.model, device=self.device)
|
||||
return [detected_masks.squeeze(0)]
|
||||
|
||||
|
||||
def make_sam_mask(sam, segs, image, detection_hint, dilation,
|
||||
def make_sam_mask(sam_model, segs, image, detection_hint, dilation,
|
||||
threshold, bbox_expansion, mask_hint_threshold, mask_hint_use_negative):
|
||||
|
||||
if not hasattr(sam, 'sam_wrapper'):
|
||||
raise Exception("[Impact Pack] Invalid SAMLoader is connected. Make sure 'SAMLoader (Impact)'.\nKnown issue: The ComfyUI-YOLO node overrides the SAMLoader (Impact), making it unusable. You need to uninstall ComfyUI-YOLO.\n\n\n")
|
||||
|
||||
sam_obj = sam.sam_wrapper
|
||||
sam_obj.prepare_device()
|
||||
if sam_model.is_auto_mode:
|
||||
device = comfy.model_management.get_torch_device()
|
||||
sam_model.safe_to.to_device(sam_model, device=device)
|
||||
|
||||
try:
|
||||
predictor = SamPredictor(sam_model)
|
||||
image = np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)
|
||||
predictor.set_image(image, "RGB")
|
||||
|
||||
total_masks = []
|
||||
|
||||
@@ -635,7 +521,7 @@ def make_sam_mask(sam, segs, image, detection_hint, dilation,
|
||||
else:
|
||||
plabs.append(1)
|
||||
|
||||
detected_masks = sam_obj.predict(image, points, plabs, None, threshold)
|
||||
detected_masks = sam_predict(predictor, points, plabs, None, threshold)
|
||||
total_masks += detected_masks
|
||||
|
||||
else:
|
||||
@@ -704,14 +590,15 @@ def make_sam_mask(sam, segs, image, detection_hint, dilation,
|
||||
points += npoints
|
||||
plabs += nplabs
|
||||
|
||||
detected_masks = sam_obj.predict(image, points, plabs, dilated_bbox, threshold)
|
||||
detected_masks = sam_predict(predictor, points, plabs, dilated_bbox, threshold)
|
||||
total_masks += detected_masks
|
||||
|
||||
# merge every collected masks
|
||||
mask = combine_masks2(total_masks)
|
||||
|
||||
finally:
|
||||
sam_obj.release_device()
|
||||
if sam_model.is_auto_mode:
|
||||
sam_model.to(device="cpu")
|
||||
|
||||
if mask is not None:
|
||||
mask = mask.float()
|
||||
@@ -845,15 +732,9 @@ def segs_scale_match(segs, target_shape):
|
||||
new_w = crop_region[2] - crop_region[0]
|
||||
new_h = crop_region[3] - crop_region[1]
|
||||
|
||||
if isinstance(cropped_mask, np.ndarray):
|
||||
cropped_mask = torch.from_numpy(cropped_mask)
|
||||
|
||||
if isinstance(cropped_mask, torch.Tensor) and len(cropped_mask.shape) == 3:
|
||||
cropped_mask = torch.nn.functional.interpolate(cropped_mask.unsqueeze(0), size=(new_h, new_w), mode='bilinear', align_corners=False)
|
||||
cropped_mask = cropped_mask.squeeze(0)
|
||||
else:
|
||||
cropped_mask = torch.nn.functional.interpolate(cropped_mask.unsqueeze(0).unsqueeze(0), size=(new_h, new_w), mode='bilinear', align_corners=False)
|
||||
cropped_mask = cropped_mask.squeeze(0).squeeze(0).numpy()
|
||||
cropped_mask = torch.from_numpy(cropped_mask)
|
||||
cropped_mask = torch.nn.functional.interpolate(cropped_mask.unsqueeze(0).unsqueeze(0), size=(new_h, new_w), mode='bilinear', align_corners=False)
|
||||
cropped_mask = cropped_mask.squeeze(0).squeeze(0).numpy()
|
||||
|
||||
if cropped_image is not None:
|
||||
cropped_image = tensor_resize(cropped_image if isinstance(cropped_image, torch.Tensor) else torch.from_numpy(cropped_image), new_w, new_h)
|
||||
@@ -872,17 +753,16 @@ def every_three_pick_last(stacked_masks):
|
||||
return selected_masks
|
||||
|
||||
|
||||
def make_sam_mask_segmented(sam, segs, image, detection_hint, dilation,
|
||||
def make_sam_mask_segmented(sam_model, segs, image, detection_hint, dilation,
|
||||
threshold, bbox_expansion, mask_hint_threshold, mask_hint_use_negative):
|
||||
|
||||
if not hasattr(sam, 'sam_wrapper'):
|
||||
raise Exception("[Impact Pack] Invalid SAMLoader is connected. Make sure 'SAMLoader (Impact)'.")
|
||||
|
||||
sam_obj = sam.sam_wrapper
|
||||
sam_obj.prepare_device()
|
||||
if sam_model.is_auto_mode:
|
||||
device = comfy.model_management.get_torch_device()
|
||||
sam_model.safe_to.to_device(sam_model, device=device)
|
||||
|
||||
try:
|
||||
predictor = SamPredictor(sam_model)
|
||||
image = np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)
|
||||
predictor.set_image(image, "RGB")
|
||||
|
||||
total_masks = []
|
||||
|
||||
@@ -905,7 +785,7 @@ def make_sam_mask_segmented(sam, segs, image, detection_hint, dilation,
|
||||
else:
|
||||
plabs.append(1)
|
||||
|
||||
detected_masks = sam_obj.predict(image, points, plabs, None, threshold)
|
||||
detected_masks = sam_predict(predictor, points, plabs, None, threshold)
|
||||
total_masks += detected_masks
|
||||
|
||||
else:
|
||||
@@ -923,7 +803,7 @@ def make_sam_mask_segmented(sam, segs, image, detection_hint, dilation,
|
||||
mask_hint_threshold, use_small_negative,
|
||||
mask_hint_use_negative)
|
||||
|
||||
detected_masks = sam_obj.predict(image, points, plabs, dilated_bbox, threshold)
|
||||
detected_masks = sam_predict(predictor, points, plabs, dilated_bbox, threshold)
|
||||
|
||||
total_masks += detected_masks
|
||||
|
||||
@@ -931,7 +811,10 @@ def make_sam_mask_segmented(sam, segs, image, detection_hint, dilation,
|
||||
mask = combine_masks2(total_masks)
|
||||
|
||||
finally:
|
||||
sam_obj.release_device()
|
||||
if sam_model.is_auto_mode:
|
||||
sam_model.cpu()
|
||||
|
||||
pass
|
||||
|
||||
mask_working_device = torch.device("cpu")
|
||||
|
||||
@@ -979,32 +862,6 @@ def segs_bitwise_and_mask(segs, mask):
|
||||
return segs[0], items
|
||||
|
||||
|
||||
def segs_bitwise_subtract_mask(segs, mask):
|
||||
mask = make_2d_mask(mask)
|
||||
|
||||
if mask is None:
|
||||
print("[SegsBitwiseSubtractMask] Cannot operate: MASK is empty.")
|
||||
return ([],)
|
||||
|
||||
items = []
|
||||
|
||||
mask = (mask.cpu().numpy() * 255).astype(np.uint8)
|
||||
|
||||
for seg in segs[1]:
|
||||
cropped_mask = (seg.cropped_mask * 255).astype(np.uint8)
|
||||
crop_region = seg.crop_region
|
||||
|
||||
cropped_mask2 = mask[crop_region[1]:crop_region[3], crop_region[0]:crop_region[2]]
|
||||
|
||||
new_mask = cv2.subtract(cropped_mask.astype(np.uint8), cropped_mask2)
|
||||
new_mask = new_mask.astype(np.float32) / 255.0
|
||||
|
||||
item = SEG(seg.cropped_image, new_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, None)
|
||||
items.append(item)
|
||||
|
||||
return segs[0], items
|
||||
|
||||
|
||||
def apply_mask_to_each_seg(segs, masks):
|
||||
if masks is None:
|
||||
print("[SegsBitwiseAndMask] Cannot operate: MASK is empty.")
|
||||
@@ -1102,21 +959,6 @@ class ONNXDetector:
|
||||
pass
|
||||
|
||||
|
||||
def batch_mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size=1, label='A', crop_min_size=None, detailer_hook=None):
|
||||
combined_mask = mask.max(dim=0).values
|
||||
|
||||
segs = mask_to_segs(combined_mask, combined, crop_factor, bbox_fill, drop_size, label, crop_min_size, detailer_hook)
|
||||
|
||||
new_segs = []
|
||||
for seg in segs[1]:
|
||||
x1, y1, x2, y2 = seg.crop_region
|
||||
cropped_mask = mask[:, y1:y2, x1:x2]
|
||||
item = SEG(None, cropped_mask, 1.0, seg.crop_region, seg.bbox, label, None)
|
||||
new_segs.append(item)
|
||||
|
||||
return segs[0], new_segs
|
||||
|
||||
|
||||
def mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size=1, label='A', crop_min_size=None, detailer_hook=None, is_contour=True):
|
||||
drop_size = max(drop_size, 1)
|
||||
if mask is None:
|
||||
@@ -1216,7 +1058,7 @@ def mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size=1, label='A',
|
||||
cropped_mask[by1:by2, bx1:bx2] = 1.0
|
||||
|
||||
if cropped_mask is not None:
|
||||
cropped_mask = torch.clip(torch.from_numpy(cropped_mask), 0, 1.0)
|
||||
cropped_mask = utils.to_binary_mask(torch.from_numpy(cropped_mask), 0.1)[0]
|
||||
item = SEG(None, cropped_mask.numpy(), 1.0, crop_region, bbox, label, None)
|
||||
result.append(item)
|
||||
|
||||
@@ -1373,11 +1215,8 @@ def vae_encode(vae, pixels, use_tile, hook, tile_size=512):
|
||||
return samples
|
||||
|
||||
|
||||
def latent_upscale_on_pixel_space_shape(samples, scale_method, w, h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
|
||||
return latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
|
||||
|
||||
|
||||
def latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
|
||||
def latent_upscale_on_pixel_space_shape(samples, scale_method, w, h, vae, use_tile=False, tile_size=512,
|
||||
save_temp_prefix=None, hook=None):
|
||||
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size)
|
||||
|
||||
if save_temp_prefix is not None:
|
||||
@@ -1385,18 +1224,14 @@ def latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae, use_t
|
||||
|
||||
pixels = nodes.ImageScale().upscale(pixels, scale_method, int(w), int(h), False)[0]
|
||||
|
||||
old_pixels = pixels
|
||||
if hook is not None:
|
||||
pixels = hook.post_upscale(pixels)
|
||||
|
||||
return (vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size), old_pixels)
|
||||
return vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size)
|
||||
|
||||
|
||||
def latent_upscale_on_pixel_space(samples, scale_method, scale_factor, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
|
||||
return latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
|
||||
|
||||
|
||||
def latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
|
||||
def latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use_tile=False, tile_size=512,
|
||||
save_temp_prefix=None, hook=None):
|
||||
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size)
|
||||
|
||||
if save_temp_prefix is not None:
|
||||
@@ -1406,18 +1241,19 @@ def latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use
|
||||
h = pixels.shape[1] * scale_factor
|
||||
pixels = nodes.ImageScale().upscale(pixels, scale_method, int(w), int(h), False)[0]
|
||||
|
||||
old_pixels = pixels
|
||||
if hook is not None:
|
||||
pixels = hook.post_upscale(pixels)
|
||||
|
||||
return (vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size), old_pixels)
|
||||
return (vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size), pixels)
|
||||
|
||||
|
||||
def latent_upscale_on_pixel_space_with_model_shape(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
|
||||
return latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
|
||||
def latent_upscale_on_pixel_space(samples, scale_method, scale_factor, vae, use_tile=False, tile_size=512,
|
||||
save_temp_prefix=None, hook=None):
|
||||
return latent_upscale_on_pixel_space2(samples, scale_method, scale_factor, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
|
||||
|
||||
|
||||
def latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, upscale_model, new_w, new_h, vae, use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
|
||||
def latent_upscale_on_pixel_space_with_model_shape(samples, scale_method, upscale_model, new_w, new_h, vae,
|
||||
use_tile=False, tile_size=512, save_temp_prefix=None, hook=None):
|
||||
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size)
|
||||
|
||||
if save_temp_prefix is not None:
|
||||
@@ -1437,17 +1273,12 @@ def latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, upsca
|
||||
# downscale to target scale
|
||||
pixels = nodes.ImageScale().upscale(pixels, scale_method, int(new_w), int(new_h), False)[0]
|
||||
|
||||
old_pixels = pixels
|
||||
if hook is not None:
|
||||
pixels = hook.post_upscale(pixels)
|
||||
|
||||
return (vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size), old_pixels)
|
||||
return vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size)
|
||||
|
||||
|
||||
def latent_upscale_on_pixel_space_with_model(samples, scale_method, upscale_model, scale_factor, vae, use_tile=False,
|
||||
tile_size=512, save_temp_prefix=None, hook=None):
|
||||
return latent_upscale_on_pixel_space_with_model2(samples, scale_method, upscale_model, scale_factor, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
|
||||
|
||||
def latent_upscale_on_pixel_space_with_model2(samples, scale_method, upscale_model, scale_factor, vae, use_tile=False,
|
||||
tile_size=512, save_temp_prefix=None, hook=None):
|
||||
pixels = vae_decode(vae, samples, use_tile, hook, tile_size=tile_size)
|
||||
@@ -1473,11 +1304,14 @@ def latent_upscale_on_pixel_space_with_model2(samples, scale_method, upscale_mod
|
||||
# downscale to target scale
|
||||
pixels = nodes.ImageScale().upscale(pixels, scale_method, int(new_w), int(new_h), False)[0]
|
||||
|
||||
old_pixels = pixels
|
||||
if hook is not None:
|
||||
pixels = hook.post_upscale(pixels)
|
||||
|
||||
return (vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size), old_pixels)
|
||||
return (vae_encode(vae, pixels, use_tile, hook, tile_size=tile_size), pixels)
|
||||
|
||||
def latent_upscale_on_pixel_space_with_model(samples, scale_method, upscale_model, scale_factor, vae, use_tile=False,
|
||||
tile_size=512, save_temp_prefix=None, hook=None):
|
||||
return latent_upscale_on_pixel_space_with_model2(samples, scale_method, upscale_model, scale_factor, vae, use_tile, tile_size, save_temp_prefix, hook)[0]
|
||||
|
||||
|
||||
class TwoSamplersForMaskUpscaler:
|
||||
@@ -1498,7 +1332,6 @@ class TwoSamplersForMaskUpscaler:
|
||||
self.hook_full = hook_full_opt
|
||||
self.use_tiled_vae = use_tiled_vae
|
||||
self.tile_size = tile_size
|
||||
self.is_tiled = False
|
||||
self.vae = vae
|
||||
|
||||
def upscale(self, step_info, samples, upscale_factor, save_temp_prefix=None):
|
||||
@@ -1623,8 +1456,7 @@ class TwoSamplersForMaskUpscaler:
|
||||
|
||||
class PixelKSampleUpscaler:
|
||||
def __init__(self, scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise,
|
||||
use_tiled_vae, upscale_model_opt=None, hook_opt=None, tile_size=512, scheduler_func=None,
|
||||
tile_cnet_opt=None, tile_cnet_strength=1.0):
|
||||
use_tiled_vae, upscale_model_opt=None, hook_opt=None, tile_size=512):
|
||||
self.params = scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise
|
||||
self.upscale_model = upscale_model_opt
|
||||
self.hook = hook_opt
|
||||
@@ -1632,28 +1464,6 @@ class PixelKSampleUpscaler:
|
||||
self.tile_size = tile_size
|
||||
self.is_tiled = False
|
||||
self.vae = vae
|
||||
self.scheduler_func = scheduler_func
|
||||
self.tile_cnet = tile_cnet_opt
|
||||
self.tile_cnet_strength = tile_cnet_strength
|
||||
|
||||
def sample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise, images):
|
||||
if self.tile_cnet is not None:
|
||||
image_batch, image_w, image_h, _ = images.shape
|
||||
if image_batch > 1:
|
||||
warnings.warn('Multiple latents in batch, Tile ControlNet being ignored')
|
||||
else:
|
||||
if 'TilePreprocessor' not in nodes.NODE_CLASS_MAPPINGS:
|
||||
raise RuntimeError("'TilePreprocessor' node (from comfyui_controlnet_aux) isn't installed.")
|
||||
preprocessor = nodes.NODE_CLASS_MAPPINGS['TilePreprocessor']()
|
||||
# might add capacity to set pyrUp_iters later, not needed for now though
|
||||
preprocessed = preprocessor.execute(images, pyrUp_iters=3, resolution=min(image_w, image_h))[0]
|
||||
apply_cnet = getattr(nodes.ControlNetApply(), nodes.ControlNetApply.FUNCTION)
|
||||
positive = apply_cnet(positive, self.tile_cnet, preprocessed, strength=self.tile_cnet_strength)[0]
|
||||
|
||||
refined_latent = impact_sampling.impact_sample(model, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, upscaled_latent, denoise, scheduler_func=self.scheduler_func)
|
||||
|
||||
return refined_latent
|
||||
|
||||
def upscale(self, step_info, samples, upscale_factor, save_temp_prefix=None):
|
||||
scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise = self.params
|
||||
@@ -1662,25 +1472,24 @@ class PixelKSampleUpscaler:
|
||||
self.hook.set_steps(step_info)
|
||||
|
||||
if self.upscale_model is None:
|
||||
upscaled_latent, upscaled_images = \
|
||||
latent_upscale_on_pixel_space2(samples, scale_method, upscale_factor, vae,
|
||||
use_tile=self.use_tiled_vae,
|
||||
save_temp_prefix=save_temp_prefix, hook=self.hook, tile_size=512)
|
||||
upscaled_latent = latent_upscale_on_pixel_space(samples, scale_method, upscale_factor, vae,
|
||||
use_tile=self.use_tiled_vae,
|
||||
save_temp_prefix=save_temp_prefix, hook=self.hook)
|
||||
else:
|
||||
upscaled_latent, upscaled_images = \
|
||||
latent_upscale_on_pixel_space_with_model2(samples, scale_method, self.upscale_model,
|
||||
upscale_factor, vae,
|
||||
use_tile=self.use_tiled_vae,
|
||||
save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
upscaled_latent = latent_upscale_on_pixel_space_with_model(samples, scale_method, self.upscale_model,
|
||||
upscale_factor, vae,
|
||||
use_tile=self.use_tiled_vae,
|
||||
save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
|
||||
if self.hook is not None:
|
||||
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
|
||||
self.hook.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
|
||||
upscaled_latent, denoise)
|
||||
|
||||
refined_latent = self.sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise, upscaled_images)
|
||||
refined_latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, upscaled_latent, denoise)[0]
|
||||
return refined_latent
|
||||
|
||||
def upscale_shape(self, step_info, samples, w, h, save_temp_prefix=None):
|
||||
@@ -1690,31 +1499,30 @@ class PixelKSampleUpscaler:
|
||||
self.hook.set_steps(step_info)
|
||||
|
||||
if self.upscale_model is None:
|
||||
upscaled_latent, upscaled_images = \
|
||||
latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae,
|
||||
use_tile=self.use_tiled_vae,
|
||||
save_temp_prefix=save_temp_prefix, hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
upscaled_latent = latent_upscale_on_pixel_space_shape(samples, scale_method, w, h, vae,
|
||||
use_tile=self.use_tiled_vae,
|
||||
save_temp_prefix=save_temp_prefix, hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
else:
|
||||
upscaled_latent, upscaled_images = \
|
||||
latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method, self.upscale_model,
|
||||
w, h, vae,
|
||||
use_tile=self.use_tiled_vae,
|
||||
save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
upscaled_latent = latent_upscale_on_pixel_space_with_model_shape(samples, scale_method, self.upscale_model,
|
||||
w, h, vae,
|
||||
use_tile=self.use_tiled_vae,
|
||||
save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
|
||||
if self.hook is not None:
|
||||
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
|
||||
self.hook.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
|
||||
upscaled_latent, denoise)
|
||||
|
||||
refined_latent = self.sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise, upscaled_images)
|
||||
refined_latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, upscaled_latent, denoise)[0]
|
||||
return refined_latent
|
||||
|
||||
|
||||
class IPAdapterWrapper:
|
||||
def __init__(self, ipadapter_pipe, weight, noise, weight_type, start_at, end_at, unfold_batch, weight_v2, reference_image, neg_image=None, prev_control_net=None, combine_embeds='concat'):
|
||||
def __init__(self, ipadapter_pipe, weight, noise, weight_type, start_at, end_at, unfold_batch, faceid_v2, weight_v2, reference_image, prev_control_net=None):
|
||||
self.reference_image = reference_image
|
||||
self.ipadapter_pipe = ipadapter_pipe
|
||||
self.weight = weight
|
||||
@@ -1724,25 +1532,21 @@ class IPAdapterWrapper:
|
||||
self.end_at = end_at
|
||||
self.unfold_batch = unfold_batch
|
||||
self.prev_control_net = prev_control_net
|
||||
self.faceid_v2 = faceid_v2
|
||||
self.weight_v2 = weight_v2
|
||||
self.image = reference_image
|
||||
self.neg_image = neg_image
|
||||
self.combine_embeds = combine_embeds
|
||||
|
||||
# name 'apply_ipadapter' isn't allowed
|
||||
def doit_ipadapter(self, model):
|
||||
cnet_image_list = [self.image]
|
||||
prev_cnet_images = []
|
||||
|
||||
if 'IPAdapterAdvanced' not in nodes.NODE_CLASS_MAPPINGS:
|
||||
if 'IPAdapterApply' in nodes.NODE_CLASS_MAPPINGS:
|
||||
raise Exception(f"[ERROR] 'ComfyUI IPAdapter Plus' is outdated.")
|
||||
|
||||
if 'IPAdapterApply' not in nodes.NODE_CLASS_MAPPINGS:
|
||||
utils.try_install_custom_node('https://github.com/cubiq/ComfyUI_IPAdapter_plus',
|
||||
"To use 'IPAdapterApplySEGS' node, 'ComfyUI IPAdapter Plus' extension is required.")
|
||||
raise Exception(f"[ERROR] To use IPAdapterApplySEGS, you need to install 'ComfyUI IPAdapter Plus'")
|
||||
|
||||
obj = nodes.NODE_CLASS_MAPPINGS['IPAdapterAdvanced']
|
||||
obj = nodes.NODE_CLASS_MAPPINGS['IPAdapterApply']
|
||||
|
||||
ipadapter, _, clip_vision, insightface, lora_loader = self.ipadapter_pipe
|
||||
model = lora_loader(model)
|
||||
@@ -1750,10 +1554,10 @@ class IPAdapterWrapper:
|
||||
if self.prev_control_net is not None:
|
||||
model, prev_cnet_images = self.prev_control_net.doit_ipadapter(model)
|
||||
|
||||
model = obj().apply_ipadapter(model=model, ipadapter=ipadapter, weight=self.weight, weight_type=self.weight_type,
|
||||
start_at=self.start_at, end_at=self.end_at, combine_embeds=self.combine_embeds,
|
||||
clip_vision=clip_vision, image=self.image, image_negative=self.neg_image, attn_mask=None,
|
||||
insightface=insightface, weight_faceidv2=self.weight_v2)[0]
|
||||
model = obj().apply_ipadapter(ipadapter, model, self.weight, clip_vision=clip_vision, image=self.image,
|
||||
embeds=None, weight_type=self.weight_type, noise=self.noise,
|
||||
attn_mask=None, start_at=self.start_at, end_at=self.end_at,
|
||||
unfold_batch=self.unfold_batch, insightface=insightface, faceid_v2=self.faceid_v2, weight_v2=self.weight_v2)[0]
|
||||
|
||||
cnet_image_list.extend(prev_cnet_images)
|
||||
|
||||
@@ -1833,12 +1637,6 @@ class ControlNetAdvancedWrapper:
|
||||
else:
|
||||
self.control_image = None
|
||||
|
||||
def doit_ipadapter(self, model):
|
||||
if self.prev_control_net is not None:
|
||||
return self.prev_control_net.doit_ipadapter(model)
|
||||
else:
|
||||
return model, []
|
||||
|
||||
def apply(self, positive, negative, image, mask=None, use_acn=False):
|
||||
cnet_image_list = []
|
||||
prev_cnet_images = []
|
||||
@@ -1902,41 +1700,26 @@ class PixelTiledKSampleUpscaler:
|
||||
def __init__(self, scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative,
|
||||
denoise,
|
||||
tile_width, tile_height, tiling_strategy,
|
||||
upscale_model_opt=None, hook_opt=None, tile_cnet_opt=None, tile_size=512, tile_cnet_strength=1.0):
|
||||
upscale_model_opt=None, hook_opt=None, tile_size=512):
|
||||
self.params = scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise
|
||||
self.vae = vae
|
||||
self.tile_params = tile_width, tile_height, tiling_strategy
|
||||
self.upscale_model = upscale_model_opt
|
||||
self.hook = hook_opt
|
||||
self.tile_cnet = tile_cnet_opt
|
||||
self.tile_size = tile_size
|
||||
self.is_tiled = True
|
||||
self.tile_cnet_strength = tile_cnet_strength
|
||||
|
||||
def tiled_ksample(self, latent, images):
|
||||
def tiled_ksample(self, latent):
|
||||
if "BNK_TiledKSampler" in nodes.NODE_CLASS_MAPPINGS:
|
||||
TiledKSampler = nodes.NODE_CLASS_MAPPINGS['BNK_TiledKSampler']
|
||||
else:
|
||||
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_TiledKSampler',
|
||||
"To use 'PixelTiledKSampleUpscalerProvider', 'Tiled sampling for ComfyUI' extension is required.")
|
||||
raise RuntimeError("'BNK_TiledKSampler' node isn't installed.")
|
||||
raise Exception("'BNK_TiledKSampler' node isn't installed.")
|
||||
|
||||
scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise = self.params
|
||||
tile_width, tile_height, tiling_strategy = self.tile_params
|
||||
|
||||
if self.tile_cnet is not None:
|
||||
image_batch, image_w, image_h, _ = images.shape
|
||||
if image_batch > 1:
|
||||
warnings.warn('Multiple latents in batch, Tile ControlNet being ignored')
|
||||
else:
|
||||
if 'TilePreprocessor' not in nodes.NODE_CLASS_MAPPINGS:
|
||||
raise RuntimeError("'TilePreprocessor' node (from comfyui_controlnet_aux) isn't installed.")
|
||||
preprocessor = nodes.NODE_CLASS_MAPPINGS['TilePreprocessor']()
|
||||
# might add capacity to set pyrUp_iters later, not needed for now though
|
||||
preprocessed = preprocessor.execute(images, pyrUp_iters=3, resolution=min(image_w, image_h))[0]
|
||||
apply_cnet = getattr(nodes.ControlNetApply(), nodes.ControlNetApply.FUNCTION)
|
||||
positive = apply_cnet(positive, self.tile_cnet, preprocessed, strength=self.tile_cnet_strength)[0]
|
||||
|
||||
return TiledKSampler().sample(model, seed, tile_width, tile_height, tiling_strategy, steps, cfg, sampler_name,
|
||||
scheduler, positive, negative, latent, denoise)[0]
|
||||
|
||||
@@ -1947,18 +1730,19 @@ class PixelTiledKSampleUpscaler:
|
||||
self.hook.set_steps(step_info)
|
||||
|
||||
if self.upscale_model is None:
|
||||
upscaled_latent, upscaled_images = \
|
||||
latent_upscale_on_pixel_space2(samples, scale_method, upscale_factor, vae,
|
||||
use_tile=True, save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook, tile_size=self.tile_size)
|
||||
upscaled_latent = latent_upscale_on_pixel_space(samples, scale_method, upscale_factor, vae,
|
||||
use_tile=True, save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
else:
|
||||
upscaled_latent, upscaled_images = \
|
||||
latent_upscale_on_pixel_space_with_model2(samples, scale_method, self.upscale_model,
|
||||
upscale_factor, vae, use_tile=True,
|
||||
save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook, tile_size=self.tile_size)
|
||||
upscaled_latent = latent_upscale_on_pixel_space_with_model(samples, scale_method, self.upscale_model,
|
||||
upscale_factor, vae,
|
||||
use_tile=True,
|
||||
save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
|
||||
refined_latent = self.tiled_ksample(upscaled_latent, upscaled_images)
|
||||
refined_latent = self.tiled_ksample(upscaled_latent)
|
||||
|
||||
return refined_latent
|
||||
|
||||
@@ -1969,20 +1753,18 @@ class PixelTiledKSampleUpscaler:
|
||||
self.hook.set_steps(step_info)
|
||||
|
||||
if self.upscale_model is None:
|
||||
upscaled_latent, upscaled_images = \
|
||||
latent_upscale_on_pixel_space_shape2(samples, scale_method, w, h, vae,
|
||||
use_tile=True, save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook, tile_size=self.tile_size)
|
||||
upscaled_latent = latent_upscale_on_pixel_space_shape(samples, scale_method, w, h, vae,
|
||||
use_tile=True, save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook, tile_size=self.tile_size)
|
||||
else:
|
||||
upscaled_latent, upscaled_images = \
|
||||
latent_upscale_on_pixel_space_with_model_shape2(samples, scale_method,
|
||||
self.upscale_model, w, h, vae,
|
||||
use_tile=True,
|
||||
save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
upscaled_latent = latent_upscale_on_pixel_space_with_model_shape(samples, scale_method,
|
||||
self.upscale_model, w, h, vae,
|
||||
use_tile=True,
|
||||
save_temp_prefix=save_temp_prefix,
|
||||
hook=self.hook,
|
||||
tile_size=self.tile_size)
|
||||
|
||||
refined_latent = self.tiled_ksample(upscaled_latent, upscaled_images)
|
||||
refined_latent = self.tiled_ksample(upscaled_latent)
|
||||
|
||||
return refined_latent
|
||||
|
||||
@@ -2057,7 +1839,7 @@ def random_mask_raw(mask, bbox, factor):
|
||||
w = x2 - x1
|
||||
h = y2 - y1
|
||||
|
||||
factor = max(6, int(min(w, h) * factor / 4))
|
||||
factor = int(min(w, h) * factor / 4)
|
||||
|
||||
def draw_random_circle(center, radius):
|
||||
i, j = center
|
||||
@@ -2117,12 +1899,6 @@ def adaptive_mask_paste(dest_mask, src_mask, bbox):
|
||||
dest_mask[y1:y2, x1:x2] = bbox_mask
|
||||
|
||||
|
||||
def crop_condition_mask(mask, image, crop_region):
|
||||
cond_scale = (mask.shape[1] / image.shape[1], mask.shape[2] / image.shape[2])
|
||||
mask_region = [round(v * cond_scale[i % 2]) for i, v in enumerate(crop_region)]
|
||||
return crop_ndarray3(mask, mask_region)
|
||||
|
||||
|
||||
class SafeToGPU:
|
||||
def __init__(self, size):
|
||||
self.size = size
|
||||
@@ -2158,10 +1934,7 @@ try:
|
||||
|
||||
if method != LatentPreviewMethod.NoPreviews or force:
|
||||
# TODO previewer methods
|
||||
taesd_decoder_path = None
|
||||
|
||||
if hasattr(latent_format, "taesd_decoder_path"):
|
||||
taesd_decoder_path = folder_paths.get_full_path("vae_approx", latent_format.taesd_decoder_name)
|
||||
taesd_decoder_path = folder_paths.get_full_path("vae_approx", latent_format.taesd_decoder_name)
|
||||
|
||||
if method == LatentPreviewMethod.Auto:
|
||||
method = LatentPreviewMethod.Latent2RGB
|
||||
@@ -2170,7 +1943,7 @@ try:
|
||||
|
||||
if method == LatentPreviewMethod.TAESD:
|
||||
if taesd_decoder_path:
|
||||
taesd = TAESD(None, taesd_decoder_path, latent_channels=latent_format.latent_channels).to(device)
|
||||
taesd = TAESD(None, taesd_decoder_path).to(device)
|
||||
previewer = TAESDPreviewerImpl(taesd)
|
||||
else:
|
||||
print("Warning: TAESD previews enabled, but could not find models/vae_approx/{}".format(
|
||||
|
||||
+45
-46
@@ -1,35 +1,25 @@
|
||||
import impact.core as core
|
||||
from nodes import MAX_RESOLUTION
|
||||
from impact.config import MAX_RESOLUTION
|
||||
import impact.segs_nodes as segs_nodes
|
||||
import impact.utils as utils
|
||||
import torch
|
||||
from impact.core import SEG
|
||||
|
||||
SAM_MODEL_TOOLTIP = {"tooltip": "Segment Anything Model for Silhouette Detection.\nBe sure to use the SAM_MODEL loaded through the SAMLoader (Impact) node as input."}
|
||||
SAM_MODEL_TOOLTIP_OPTIONAL = {"tooltip": "[OPTIONAL]\nSegment Anything Model for Silhouette Detection.\nBe sure to use the SAM_MODEL loaded through the SAMLoader (Impact) node as input.\nGiven this input, it refines the rectangular areas detected by BBOX_DETECTOR into silhouette shapes through SAM.\nsam_model_opt takes priority over segm_detector_opt."}
|
||||
|
||||
MASK_HINT_THRESHOLD_TOOLTIP = "When detection_hint is mask-area, the mask of SEGS is used as a point hint for SAM (Segment Anything).\nIn this case, only the areas of the mask with brightness values equal to or greater than mask_hint_threshold are used as hints."
|
||||
MASK_HINT_USE_NEGATIVE_TOOLTIP = "When detecting with SAM (Segment Anything), negative hints are applied as follows:\nSmall: When the SEGS is smaller than 10 pixels in size\nOuter: Sampling the image area outside the SEGS region at regular intervals"
|
||||
|
||||
DILATION_TOOLTIP = "Set the value to dilate the result mask. If the value is negative, it erodes the mask."
|
||||
DETECTION_HINT_TOOLTIP = {"tooltip": "It is recommended to use only center-1.\nWhen refining the mask of SEGS with the SAM (Segment Anything) model, center-1 uses only the rectangular area of SEGS and a single point at the exact center as hints.\nOther options were added during the experimental stage and do not work well."}
|
||||
|
||||
BBOX_EXPANSION_TOOLTIP = "When performing SAM (Segment Anything) detection within the SEGS area, the rectangular area of SEGS is expanded and used as a hint."
|
||||
|
||||
class SAMDetectorCombined:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"sam_model": ("SAM_MODEL", SAM_MODEL_TOOLTIP),
|
||||
"segs": ("SEGS", {"tooltip": "This is the segment information detected by the detector.\nIt refines the Mask through the SAM (Segment Anything) detector for all areas pointed to by SEGS, and combines all Masks to return as a single Mask."}),
|
||||
"image": ("IMAGE", {"tooltip": "It is assumed that segs contains only the information about the detected areas, and does not include the image. SAM (Segment Anything) operates by referencing this image."}),
|
||||
"sam_model": ("SAM_MODEL", ),
|
||||
"segs": ("SEGS", ),
|
||||
"image": ("IMAGE", ),
|
||||
"detection_hint": (["center-1", "horizontal-2", "vertical-2", "rect-4", "diamond-4", "mask-area",
|
||||
"mask-points", "mask-point-bbox", "none"], DETECTION_HINT_TOOLTIP),
|
||||
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1, "tooltip": DILATION_TOOLTIP}),
|
||||
"threshold": ("FLOAT", {"default": 0.93, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Set the sensitivity threshold for the mask detected by SAM (Segment Anything). A higher value generates a more specific mask with a narrower range. For example, when pointing to a person's area, it might detect clothes, which is a narrower range, instead of the entire person."}),
|
||||
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1, "tooltip": BBOX_EXPANSION_TOOLTIP}),
|
||||
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": MASK_HINT_THRESHOLD_TOOLTIP}),
|
||||
"mask_hint_use_negative": (["False", "Small", "Outter"], {"tooltip": MASK_HINT_USE_NEGATIVE_TOOLTIP})
|
||||
"mask-points", "mask-point-bbox", "none"],),
|
||||
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
"threshold": ("FLOAT", {"default": 0.93, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
|
||||
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"mask_hint_use_negative": (["False", "Small", "Outter"], )
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,16 +38,16 @@ class SAMDetectorSegmented:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"sam_model": ("SAM_MODEL", SAM_MODEL_TOOLTIP),
|
||||
"segs": ("SEGS", {"tooltip": "This is the segment information detected by the detector.\nFor the SEGS region, the masks detected by SAM (Segment Anything) are created as a unified mask and a batch of individual masks."}),
|
||||
"image": ("IMAGE", {"tooltip": "It is assumed that segs contains only the information about the detected areas, and does not include the image. SAM (Segment Anything) operates by referencing this image."}),
|
||||
"sam_model": ("SAM_MODEL", ),
|
||||
"segs": ("SEGS", ),
|
||||
"image": ("IMAGE", ),
|
||||
"detection_hint": (["center-1", "horizontal-2", "vertical-2", "rect-4", "diamond-4", "mask-area",
|
||||
"mask-points", "mask-point-bbox", "none"], DETECTION_HINT_TOOLTIP),
|
||||
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1, "tooltip": DILATION_TOOLTIP}),
|
||||
"mask-points", "mask-point-bbox", "none"],),
|
||||
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
"threshold": ("FLOAT", {"default": 0.93, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1, "tooltip": BBOX_EXPANSION_TOOLTIP}),
|
||||
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": MASK_HINT_THRESHOLD_TOOLTIP}),
|
||||
"mask_hint_use_negative": (["False", "Small", "Outter"], {"tooltip": MASK_HINT_USE_NEGATIVE_TOOLTIP})
|
||||
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
|
||||
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"mask_hint_use_negative": (["False", "Small", "Outter"], )
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,11 +151,7 @@ class SegmDetectorCombined:
|
||||
|
||||
def doit(self, segm_detector, image, threshold, dilation):
|
||||
mask = segm_detector.detect_combined(image, threshold, dilation)
|
||||
|
||||
if mask is None:
|
||||
mask = torch.zeros((image.shape[2], image.shape[1]), dtype=torch.float32, device="cpu")
|
||||
|
||||
return (mask.unsqueeze(0),)
|
||||
return (mask,)
|
||||
|
||||
|
||||
class BboxDetectorCombined(SegmDetectorCombined):
|
||||
@@ -181,11 +167,7 @@ class BboxDetectorCombined(SegmDetectorCombined):
|
||||
|
||||
def doit(self, bbox_detector, image, threshold, dilation):
|
||||
mask = bbox_detector.detect_combined(image, threshold, dilation)
|
||||
|
||||
if mask is None:
|
||||
mask = torch.zeros((image.shape[2], image.shape[1]), dtype=torch.float32, device="cpu")
|
||||
|
||||
return (mask.unsqueeze(0),)
|
||||
return (mask,)
|
||||
|
||||
|
||||
class SimpleDetectorForEach:
|
||||
@@ -209,7 +191,7 @@ class SimpleDetectorForEach:
|
||||
},
|
||||
"optional": {
|
||||
"post_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
|
||||
"sam_model_opt": ("SAM_MODEL", SAM_MODEL_TOOLTIP_OPTIONAL),
|
||||
"sam_model_opt": ("SAM_MODEL", ),
|
||||
"segm_detector_opt": ("SEGM_DETECTOR", ),
|
||||
}
|
||||
}
|
||||
@@ -321,7 +303,7 @@ class SimpleDetectorForAnimateDiff:
|
||||
"optional": {
|
||||
"masking_mode": (["Pivot SEGS", "Combine neighboring frames", "Don't combine"],),
|
||||
"segs_pivot": (["Combined mask", "1st frame mask"],),
|
||||
"sam_model_opt": ("SAM_MODEL", SAM_MODEL_TOOLTIP_OPTIONAL),
|
||||
"sam_model_opt": ("SAM_MODEL", ),
|
||||
"segm_detector_opt": ("SEGM_DETECTOR", ),
|
||||
}
|
||||
}
|
||||
@@ -420,14 +402,13 @@ class SimpleDetectorForAnimateDiff:
|
||||
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]
|
||||
return segs_nodes.MaskToSEGS().doit(merged_mask, False, crop_factor, False, drop_size, contour_fill=True)[0]
|
||||
|
||||
def get_segs(merged_neighboring=False):
|
||||
def get_merged_neighboring_segs():
|
||||
pivot_segs = get_pivot_segs()
|
||||
|
||||
masks_by_frame = get_masked_frames()
|
||||
if merged_neighboring:
|
||||
masks_by_frame = get_merged_neighboring_mask(masks_by_frame)
|
||||
masks_by_frame = get_merged_neighboring_mask(masks_by_frame)
|
||||
|
||||
new_segs = []
|
||||
for seg in pivot_segs[1]:
|
||||
@@ -446,15 +427,33 @@ class SimpleDetectorForAnimateDiff:
|
||||
|
||||
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_segs(merged_neighboring=True), )
|
||||
return (get_merged_neighboring_segs(), )
|
||||
|
||||
else: # elif masking_mode == "Don't combine":
|
||||
return (get_segs(merged_neighboring=False), )
|
||||
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,
|
||||
|
||||
@@ -42,7 +42,7 @@ class HF_TransformersClassifierProvider:
|
||||
else:
|
||||
device = "cpu"
|
||||
|
||||
classifier = pipeline('image-classification', model=url, device=device)
|
||||
classifier = pipeline(model=url, device=device)
|
||||
|
||||
return (classifier,)
|
||||
|
||||
@@ -83,9 +83,8 @@ class SEGS_Classify:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("SEGS", "SEGS", "STRING")
|
||||
RETURN_NAMES = ("filtered_SEGS", "remained_SEGS", "detected_labels")
|
||||
OUTPUT_IS_LIST = (False, False, True)
|
||||
RETURN_TYPES = ("SEGS", "SEGS",)
|
||||
RETURN_NAMES = ("filtered_SEGS", "remained_SEGS",)
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
@@ -118,7 +117,7 @@ class SEGS_Classify:
|
||||
match = re.match(classify_expr_pattern, expr_str)
|
||||
|
||||
if match is None:
|
||||
return (segs[0], []), segs, []
|
||||
return ((segs[0], []), segs)
|
||||
|
||||
a = match.group(1)
|
||||
op = match.group(2)
|
||||
@@ -129,7 +128,6 @@ class SEGS_Classify:
|
||||
|
||||
classified = []
|
||||
remained_SEGS = []
|
||||
provided_labels = set()
|
||||
|
||||
for seg in segs[1]:
|
||||
cropped_image = None
|
||||
@@ -144,9 +142,6 @@ class SEGS_Classify:
|
||||
cropped_image = to_pil(cropped_image)
|
||||
res = classifier(cropped_image)
|
||||
classified.append((seg, res))
|
||||
|
||||
for x in res:
|
||||
provided_labels.add(x['label'])
|
||||
else:
|
||||
remained_SEGS.append(seg)
|
||||
|
||||
@@ -185,4 +180,4 @@ class SEGS_Classify:
|
||||
else:
|
||||
remained_SEGS.append(seg)
|
||||
|
||||
return (segs[0], filtered_SEGS), (segs[0], remained_SEGS), list(provided_labels)
|
||||
return ((segs[0], filtered_SEGS), (segs[0], remained_SEGS))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
from . import hooks
|
||||
from . import defs
|
||||
import comfy
|
||||
|
||||
|
||||
class SEGSOrderedFilterDetailerHookProvider:
|
||||
@@ -73,13 +74,38 @@ class PreviewDetailerHookProvider:
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DETAILER_HOOK", "UPSCALER_HOOK")
|
||||
RETURN_TYPES = ("DETAILER_HOOK", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
NOT_IDEMPOTENT = True
|
||||
|
||||
def doit(self, quality, unique_id):
|
||||
hook = hooks.PreviewDetailerHook(unique_id, quality)
|
||||
return hook, hook
|
||||
return (hook, )
|
||||
|
||||
|
||||
class StableCascade_DetailerHookProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"b_model": ("MODEL",),
|
||||
"b_vae": ("VAE",),
|
||||
"b_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"b_steps": ("INT", {"default": 5, "min": 1, "max": 10000}),
|
||||
"b_cfg": ("FLOAT", {"default": 1.1, "min": 0.0, "max": 100.0, "step": 0.1, "round": 0.01}),
|
||||
"b_sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
|
||||
"b_scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
|
||||
"c_compression": ("INT", {"default": 42, "min": 4, "max": 128, "step": 1}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DETAILER_HOOK", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, b_model, b_vae, b_seed, b_steps, b_cfg, b_sampler_name, b_scheduler, c_compression):
|
||||
hook = hooks.StableCascade_DetailerHook(b_model, b_vae, b_seed, b_steps, b_cfg, b_sampler_name, b_scheduler, c_compression)
|
||||
return (hook, )
|
||||
|
||||
|
||||
+47
-32
@@ -1,6 +1,8 @@
|
||||
import copy
|
||||
import torch
|
||||
|
||||
import comfy_extras.nodes_stable_cascade
|
||||
import nodes
|
||||
|
||||
from impact import utils
|
||||
from . import segs_nodes
|
||||
from thirdparty import noise_nodes
|
||||
@@ -8,8 +10,7 @@ from server import PromptServer
|
||||
import asyncio
|
||||
import folder_paths
|
||||
import os
|
||||
from comfy_extras import nodes_custom_sampler
|
||||
import math
|
||||
from impact import impact_sampling
|
||||
|
||||
|
||||
class PixelKSampleHook:
|
||||
@@ -104,10 +105,19 @@ class DetailerHookCombine(PixelKSampleHookCombine):
|
||||
image = self.hook2.post_paste(image)
|
||||
return image
|
||||
|
||||
def get_custom_noise(self, seed, noise, is_touched):
|
||||
noise_1st, is_touched = self.hook1.get_custom_noise(seed, noise, is_touched)
|
||||
noise_2nd, is_touched = self.hook2.get_custom_noise(seed, noise, is_touched)
|
||||
return noise, is_touched
|
||||
def stable_cascade_vae_encode(self, vae, pixels):
|
||||
latent = self.hook1.stable_cascade_vae_encode(vae, pixels)
|
||||
if latent is not None:
|
||||
return latent
|
||||
|
||||
return self.hook2.stable_cascade_vae_encode(vae, pixels)
|
||||
|
||||
def stable_cascade_stage_b(self, image, positive, negative, latent):
|
||||
image = self.hook1.stable_cascade_stage_b(image, positive, negative, latent)
|
||||
if image is not None:
|
||||
return image
|
||||
|
||||
return self.hook2.stable_cascade_stage_b(image, positive, negative, latent)
|
||||
|
||||
|
||||
class SimpleCfgScheduleHook(PixelKSampleHook):
|
||||
@@ -170,38 +180,43 @@ class DetailerHook(PixelKSampleHook):
|
||||
def post_paste(self, image):
|
||||
return image
|
||||
|
||||
def get_custom_noise(self, seed, noise, is_touched):
|
||||
return noise, is_touched
|
||||
def stable_cascade_vae_encode(self, vae, pixels):
|
||||
return None
|
||||
|
||||
def stable_cascade_stage_b(self, image, positive, negative, latent):
|
||||
return None
|
||||
|
||||
|
||||
# class CustomNoiseDetailerHookProvider(DetailerHook):
|
||||
# def __init__(self, noise):
|
||||
# super().__init__()
|
||||
# self.noise = noise
|
||||
#
|
||||
# def get_custom_noise(self, seed, noise, is_start):
|
||||
# return self.noise
|
||||
|
||||
|
||||
class VariationNoiseDetailerHookProvider(DetailerHook):
|
||||
def __init__(self, variation_seed, variation_strength):
|
||||
class StableCascade_DetailerHook(DetailerHook):
|
||||
def __init__(self, b_model, b_vae, b_seed, b_steps, b_cfg, b_sampler_name, b_scheduler, c_compression):
|
||||
super().__init__()
|
||||
self.variation_seed = variation_seed
|
||||
self.variation_strength = variation_strength
|
||||
self.b_model = b_model
|
||||
self.b_vae = b_vae
|
||||
self.b_seed = b_seed
|
||||
self.b_steps = b_steps
|
||||
self.b_cfg = b_cfg
|
||||
self.b_sampler_name = b_sampler_name
|
||||
self.b_scheduler = b_scheduler
|
||||
self.c_compression = c_compression
|
||||
self.b_latent = None
|
||||
|
||||
def get_custom_noise(self, seed, noise, is_touched):
|
||||
empty_noise = {'samples': torch.zeros(noise.size())}
|
||||
if not is_touched:
|
||||
noise = nodes_custom_sampler.Noise_RandomNoise(seed).generate_noise(empty_noise)
|
||||
noise_2nd = nodes_custom_sampler.Noise_RandomNoise(self.variation_seed).generate_noise(empty_noise)
|
||||
def stable_cascade_vae_encode(self, vae, pixels):
|
||||
obj = comfy_extras.nodes_stable_cascade.StableCascade_StageC_VAEEncode()
|
||||
stage_c, stage_b = obj.generate(pixels, vae, compression=self.c_compression)
|
||||
self.b_latent = stage_b
|
||||
return stage_c
|
||||
|
||||
mixed_noise = ((1 - self.variation_strength) * noise + self.variation_strength * noise_2nd)
|
||||
def stable_cascade_stage_b(self, image, positive, negative, latent):
|
||||
# prepare stage_b
|
||||
# self.b_latent['noise_mask'] = latent['noise_mask']
|
||||
b_positive = comfy_extras.nodes_stable_cascade.StableCascade_StageB_Conditioning().set_prior(positive, latent)[0]
|
||||
|
||||
# NOTE: Since the variance of the Gaussian noise in mixed_noise has changed, it must be corrected through scaling.
|
||||
scale_factor = math.sqrt((1 - self.variation_strength) ** 2 + self.variation_strength ** 2)
|
||||
corrected_noise = mixed_noise / scale_factor # Scale the noise to maintain variance of 1
|
||||
# stage_b sampling
|
||||
b_latent = impact_sampling.ksampler_wrapper(self.b_model, self.b_seed, self.b_steps, self.b_cfg, self.b_sampler_name, self.b_scheduler, b_positive, negative, self.b_latent, 1.0)
|
||||
|
||||
return corrected_noise, True
|
||||
# stage_b decoding
|
||||
self.b_latent = None
|
||||
return self.b_vae.decode(b_latent['samples'])
|
||||
|
||||
|
||||
class SimpleDetailerDenoiseSchedulerHook(DetailerHook):
|
||||
|
||||
+153
-263
@@ -15,8 +15,7 @@ import impact.wildcards
|
||||
from impact.utils import *
|
||||
import impact.core as core
|
||||
from impact.core import SEG
|
||||
from impact.config import latent_letter_path
|
||||
from nodes import MAX_RESOLUTION
|
||||
from impact.config import MAX_RESOLUTION, latent_letter_path
|
||||
from PIL import Image, ImageOps
|
||||
import numpy as np
|
||||
import hashlib
|
||||
@@ -27,7 +26,6 @@ import comfy.model_management
|
||||
import base64
|
||||
import impact.wildcards as wildcards
|
||||
from . import hooks
|
||||
from . import utils
|
||||
|
||||
warnings.filterwarnings('ignore', category=UserWarning, message='TypedStorage is deprecated')
|
||||
|
||||
@@ -62,10 +60,10 @@ class CLIPSegDetectorProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"text": ("STRING", {"multiline": False, "tooltip": "Enter the targets to be detected, separated by commas"}),
|
||||
"blur": ("FLOAT", {"min": 0, "max": 15, "step": 0.1, "default": 7, "tooltip": "Blurs the detected mask"}),
|
||||
"threshold": ("FLOAT", {"min": 0, "max": 1, "step": 0.05, "default": 0.4, "tooltip": "Detects only areas that are certain above the threshold."}),
|
||||
"dilation_factor": ("INT", {"min": 0, "max": 10, "step": 1, "default": 4, "tooltip": "Dilates the detected mask."}),
|
||||
"text": ("STRING", {"multiline": False}),
|
||||
"blur": ("FLOAT", {"min": 0, "max": 15, "step": 0.1, "default": 7}),
|
||||
"threshold": ("FLOAT", {"min": 0, "max": 1, "step": 0.05, "default": 0.4}),
|
||||
"dilation_factor": ("INT", {"min": 0, "max": 10, "step": 1, "default": 4}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +72,6 @@ class CLIPSegDetectorProvider:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
DESCRIPTION = "Provides a detection function using CLIPSeg, which generates masks based on text prompts.\nTo use this node, the CLIPSeg custom node must be installed."
|
||||
|
||||
def doit(self, text, blur, threshold, dilation_factor):
|
||||
if "CLIPSeg" in nodes.NODE_CLASS_MAPPINGS:
|
||||
return (core.BBoxDetectorBasedOnCLIPSeg(text, blur, threshold, dilation_factor), )
|
||||
@@ -89,10 +85,8 @@ class SAMLoader:
|
||||
models = [x for x in folder_paths.get_filename_list("sams") if 'hq' not in x]
|
||||
return {
|
||||
"required": {
|
||||
"model_name": (models + ['ESAM'], {"tooltip": "The detection accuracy varies depending on the SAM model. ESAM can only be used if ComfyUI-YoloWorld-EfficientSAM is installed."}),
|
||||
"device_mode": (["AUTO", "Prefer GPU", "CPU"], {"tooltip": "AUTO: Only applicable when a GPU is available. It temporarily loads the SAM_MODEL into VRAM only when the detection function is used.\n"
|
||||
"Prefer GPU: Tries to keep the SAM_MODEL on the GPU whenever possible. This can be used when there is sufficient VRAM available.\n"
|
||||
"CPU: Always loads only on the CPU."}),
|
||||
"model_name": (models, ),
|
||||
"device_mode": (["AUTO", "Prefer GPU", "CPU"],),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,29 +95,7 @@ class SAMLoader:
|
||||
|
||||
CATEGORY = "ImpactPack"
|
||||
|
||||
DESCRIPTION = "Load the SAM (Segment Anything) model. This can be used in places that utilize SAM detection functionality, such as SAMDetector or SimpleDetector.\nThe SAM detection functionality in Impact Pack must use the SAM_MODEL loaded through this node."
|
||||
|
||||
def load_model(self, model_name, device_mode="auto"):
|
||||
if model_name == 'ESAM':
|
||||
if 'ESAM_ModelLoader_Zho' not in nodes.NODE_CLASS_MAPPINGS:
|
||||
try_install_custom_node('https://github.com/ZHO-ZHO-ZHO/ComfyUI-YoloWorld-EfficientSAM',
|
||||
"To use 'ESAM' model, 'ComfyUI-YoloWorld-EfficientSAM' extension is required.")
|
||||
raise Exception("'ComfyUI-YoloWorld-EfficientSAM' node isn't installed.")
|
||||
|
||||
esam_loader = nodes.NODE_CLASS_MAPPINGS['ESAM_ModelLoader_Zho']()
|
||||
|
||||
if device_mode == 'CPU':
|
||||
esam = esam_loader.load_esam_model('CPU')[0]
|
||||
else:
|
||||
device_mode = 'CUDA'
|
||||
esam = esam_loader.load_esam_model('CUDA')[0]
|
||||
|
||||
sam_obj = core.ESAMWrapper(esam, device_mode)
|
||||
esam.sam_wrapper = sam_obj
|
||||
|
||||
print(f"Loads EfficientSAM model: (device:{device_mode})")
|
||||
return (esam, )
|
||||
|
||||
modelname = folder_paths.get_full_path("sams", model_name)
|
||||
|
||||
if 'vit_h' in model_name:
|
||||
@@ -135,18 +107,15 @@ class SAMLoader:
|
||||
|
||||
sam = sam_model_registry[model_kind](checkpoint=modelname)
|
||||
size = os.path.getsize(modelname)
|
||||
safe_to = core.SafeToGPU(size)
|
||||
sam.safe_to = core.SafeToGPU(size)
|
||||
|
||||
# Unless user explicitly wants to use CPU, we use GPU
|
||||
device = comfy.model_management.get_torch_device() if device_mode == "Prefer GPU" else "CPU"
|
||||
|
||||
if device_mode == "Prefer GPU":
|
||||
safe_to.to_device(sam, device)
|
||||
sam.safe_to.to_device(sam, device)
|
||||
|
||||
is_auto_mode = device_mode == "AUTO"
|
||||
|
||||
sam_obj = core.SAMWrapper(sam, is_auto_mode=is_auto_mode, safe_to_gpu=safe_to)
|
||||
sam.sam_wrapper = sam_obj
|
||||
sam.is_auto_mode = device_mode == "AUTO"
|
||||
|
||||
print(f"Loads SAM model: {modelname} (device:{device_mode})")
|
||||
return (sam, )
|
||||
@@ -186,14 +155,14 @@ class DetailerForEach:
|
||||
"model": ("MODEL",),
|
||||
"clip": ("CLIP",),
|
||||
"vae": ("VAE",),
|
||||
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"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": (core.SCHEDULERS,),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
|
||||
"positive": ("CONDITIONING",),
|
||||
"negative": ("CONDITIONING",),
|
||||
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
|
||||
@@ -207,8 +176,7 @@ class DetailerForEach:
|
||||
"optional": {
|
||||
"detailer_hook": ("DETAILER_HOOK",),
|
||||
"inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
"noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +189,7 @@ class DetailerForEach:
|
||||
def do_detail(image, segs, model, clip, vae, guide_size, guide_size_for_bbox, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, denoise, feather, noise_mask, force_inpaint, wildcard_opt=None, detailer_hook=None,
|
||||
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None, refiner_negative=None,
|
||||
cycle=1, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
cycle=1, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: DetailerForEach 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.')
|
||||
@@ -244,21 +212,17 @@ class DetailerForEach:
|
||||
else:
|
||||
wmode, wildcard_chooser = None, None
|
||||
|
||||
if wmode in ['ASC', 'DSC', 'ASC-SIZE', 'DSC-SIZE']:
|
||||
if wmode in ['ASC', 'DSC']:
|
||||
if wmode == 'ASC':
|
||||
ordered_segs = sorted(segs[1], key=lambda x: (x.bbox[0], x.bbox[1]))
|
||||
elif wmode == 'DSC':
|
||||
else:
|
||||
ordered_segs = sorted(segs[1], key=lambda x: (x.bbox[0], x.bbox[1]), reverse=True)
|
||||
elif wmode == 'ASC-SIZE':
|
||||
ordered_segs = sorted(segs[1], key=lambda x: (x.bbox[2]-x.bbox[0]) * (x.bbox[3]-x.bbox[1]))
|
||||
|
||||
else: # wmode == 'DSC-SIZE'
|
||||
ordered_segs = sorted(segs[1], key=lambda x: (x.bbox[2]-x.bbox[0]) * (x.bbox[3]-x.bbox[1]), reverse=True)
|
||||
else:
|
||||
ordered_segs = segs[1]
|
||||
|
||||
for i, seg in enumerate(ordered_segs):
|
||||
cropped_image = crop_ndarray4(image.cpu().numpy(), seg.crop_region) # Never use seg.cropped_image to handle overlapping area
|
||||
cropped_image = seg.cropped_image if seg.cropped_image is not None \
|
||||
else crop_ndarray4(image.numpy(), seg.crop_region)
|
||||
cropped_image = to_tensor(cropped_image)
|
||||
mask = to_tensor(seg.cropped_mask)
|
||||
mask = tensor_gaussian_blur_mask(mask, feather)
|
||||
@@ -282,42 +246,15 @@ class DetailerForEach:
|
||||
|
||||
seg_seed = seed + i if seg_seed is None else seg_seed
|
||||
|
||||
cropped_positive = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in positive
|
||||
]
|
||||
|
||||
if not isinstance(negative, str):
|
||||
cropped_negative = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in negative
|
||||
]
|
||||
else:
|
||||
# Negative Conditioning is placeholder such as FLUX.1
|
||||
cropped_negative = negative
|
||||
|
||||
if wildcard_item and wildcard_item.strip() == '[SKIP]':
|
||||
continue
|
||||
|
||||
if wildcard_item and wildcard_item.strip() == '[STOP]':
|
||||
break
|
||||
|
||||
enhanced_image, cnet_pils = core.enhance_detail(cropped_image, model, clip, vae, guide_size, guide_size_for_bbox, max_size,
|
||||
seg.bbox, seg_seed, steps, cfg, sampler_name, scheduler,
|
||||
cropped_positive, cropped_negative, denoise, cropped_mask, force_inpaint,
|
||||
positive, negative, denoise, cropped_mask, force_inpaint,
|
||||
wildcard_opt=wildcard_item, wildcard_opt_concat_mode=wildcard_concat_mode,
|
||||
detailer_hook=detailer_hook,
|
||||
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,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather,
|
||||
scheduler_func=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
if cnet_pils is not None:
|
||||
cnet_pil_list.extend(cnet_pils)
|
||||
@@ -331,7 +268,7 @@ class DetailerForEach:
|
||||
enhanced_list.append(enhanced_image)
|
||||
|
||||
if detailer_hook is not None:
|
||||
image = detailer_hook.post_paste(image)
|
||||
detailer_hook.post_paste(image)
|
||||
|
||||
if not (enhanced_image is None):
|
||||
# Convert enhanced_pil_alpha to RGBA mode
|
||||
@@ -360,13 +297,13 @@ class DetailerForEach:
|
||||
|
||||
def doit(self, image, segs, model, clip, vae, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name,
|
||||
scheduler, positive, negative, denoise, feather, noise_mask, force_inpaint, wildcard, cycle=1,
|
||||
detailer_hook=None, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
detailer_hook=None, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
enhanced_img, *_ = \
|
||||
DetailerForEach.do_detail(image, segs, model, clip, vae, guide_size, guide_size_for, max_size, seed, steps,
|
||||
cfg, sampler_name, scheduler, positive, negative, denoise, feather, noise_mask,
|
||||
force_inpaint, wildcard, detailer_hook,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
return (enhanced_img, )
|
||||
|
||||
@@ -377,14 +314,14 @@ class DetailerForEachPipe:
|
||||
return {"required": {
|
||||
"image": ("IMAGE", ),
|
||||
"segs": ("SEGS", ),
|
||||
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"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": (core.SCHEDULERS,),
|
||||
"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}),
|
||||
"noise_mask": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
@@ -396,12 +333,11 @@ class DetailerForEachPipe:
|
||||
"cycle": ("INT", {"default": 1, "min": 1, "max": 10, "step": 1}),
|
||||
},
|
||||
"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": 20, "min": 0, "max": 100, "step": 1}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
}
|
||||
"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")
|
||||
@@ -414,7 +350,7 @@ class DetailerForEachPipe:
|
||||
def doit(self, image, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, feather, noise_mask, force_inpaint, basic_pipe, wildcard,
|
||||
refiner_ratio=None, detailer_hook=None, refiner_basic_pipe_opt=None,
|
||||
cycle=1, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
cycle=1, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: DetailerForEach 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.')
|
||||
@@ -432,13 +368,13 @@ class DetailerForEachPipe:
|
||||
force_inpaint, wildcard, detailer_hook,
|
||||
refiner_ratio=refiner_ratio, refiner_model=refiner_model,
|
||||
refiner_clip=refiner_clip, refiner_positive=refiner_positive, refiner_negative=refiner_negative,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
# set fallback image
|
||||
if len(cnet_pil_list) == 0:
|
||||
cnet_pil_list = [empty_pil_tensor()]
|
||||
|
||||
return enhanced_img, new_segs, basic_pipe, cnet_pil_list
|
||||
return (enhanced_img, new_segs, basic_pipe, cnet_pil_list)
|
||||
|
||||
|
||||
class FaceDetailer:
|
||||
@@ -449,14 +385,14 @@ class FaceDetailer:
|
||||
"model": ("MODEL",),
|
||||
"clip": ("CLIP",),
|
||||
"vae": ("VAE",),
|
||||
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"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": (core.SCHEDULERS,),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
|
||||
"positive": ("CONDITIONING",),
|
||||
"negative": ("CONDITIONING",),
|
||||
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
|
||||
@@ -487,8 +423,7 @@ class FaceDetailer:
|
||||
"segm_detector_opt": ("SEGM_DETECTOR", ),
|
||||
"detailer_hook": ("DETAILER_HOOK",),
|
||||
"inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
"noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
||||
}}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "IMAGE", "IMAGE", "MASK", "DETAILER_PIPE", "IMAGE")
|
||||
@@ -506,7 +441,7 @@ class FaceDetailer:
|
||||
sam_mask_hint_use_negative, drop_size,
|
||||
bbox_detector, segm_detector=None, sam_model_opt=None, wildcard_opt=None, detailer_hook=None,
|
||||
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None, refiner_negative=None, cycle=1,
|
||||
inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
# make default prompt as 'face' if empty prompt for CLIPSeg
|
||||
bbox_detector.setAux('face')
|
||||
@@ -538,7 +473,7 @@ class FaceDetailer:
|
||||
refiner_ratio=refiner_ratio, refiner_model=refiner_model,
|
||||
refiner_clip=refiner_clip, refiner_positive=refiner_positive,
|
||||
refiner_negative=refiner_negative,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
else:
|
||||
enhanced_img = image
|
||||
cropped_enhanced = []
|
||||
@@ -564,7 +499,7 @@ class FaceDetailer:
|
||||
bbox_threshold, bbox_dilation, bbox_crop_factor,
|
||||
sam_detection_hint, sam_dilation, sam_threshold, sam_bbox_expansion, sam_mask_hint_threshold,
|
||||
sam_mask_hint_use_negative, drop_size, bbox_detector, wildcard, cycle=1,
|
||||
sam_model_opt=None, segm_detector_opt=None, detailer_hook=None, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
sam_model_opt=None, segm_detector_opt=None, detailer_hook=None, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
result_img = None
|
||||
result_mask = None
|
||||
@@ -582,7 +517,7 @@ class FaceDetailer:
|
||||
bbox_threshold, bbox_dilation, bbox_crop_factor,
|
||||
sam_detection_hint, sam_dilation, sam_threshold, sam_bbox_expansion, sam_mask_hint_threshold,
|
||||
sam_mask_hint_use_negative, drop_size, bbox_detector, segm_detector_opt, sam_model_opt, wildcard, detailer_hook,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
result_img = torch.cat((result_img, enhanced_img), dim=0) if result_img is not None else enhanced_img
|
||||
result_mask = torch.cat((result_mask, mask), dim=0) if result_mask is not None else mask
|
||||
@@ -654,41 +589,6 @@ class NoiseInjectionDetailerHookProvider:
|
||||
pass
|
||||
|
||||
|
||||
# class CustomNoiseDetailerHookProvider:
|
||||
# @classmethod
|
||||
# def INPUT_TYPES(s):
|
||||
# return {"required": {
|
||||
# "noise": ("NOISE",)},
|
||||
# }
|
||||
#
|
||||
# RETURN_TYPES = ("DETAILER_HOOK",)
|
||||
# FUNCTION = "doit"
|
||||
#
|
||||
# CATEGORY = "ImpactPack/Detailer"
|
||||
#
|
||||
# def doit(self, noise):
|
||||
# hook = hooks.CustomNoiseDetailerHookProvider(noise)
|
||||
# return (hook, )
|
||||
|
||||
|
||||
class VariationNoiseDetailerHookProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"strength": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01})}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DETAILER_HOOK",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Detailer"
|
||||
|
||||
def doit(self, seed, strength):
|
||||
hook = hooks.VariationNoiseDetailerHookProvider(seed, strength)
|
||||
return (hook, )
|
||||
|
||||
|
||||
class UnsamplerDetailerHookProvider:
|
||||
schedules = ["skip_start", "from_start"]
|
||||
|
||||
@@ -968,8 +868,6 @@ class PixelTiledKSampleUpscalerProvider:
|
||||
"optional": {
|
||||
"upscale_model_opt": ("UPSCALE_MODEL", ),
|
||||
"pk_hook_opt": ("PK_HOOK", ),
|
||||
"tile_cnet_opt": ("CONTROL_NET", ),
|
||||
"tile_cnet_strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -978,18 +876,12 @@ class PixelTiledKSampleUpscalerProvider:
|
||||
|
||||
CATEGORY = "ImpactPack/Upscale"
|
||||
|
||||
def doit(self, scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, tile_width, tile_height, tiling_strategy, upscale_model_opt=None,
|
||||
pk_hook_opt=None, tile_cnet_opt=None, tile_cnet_strength=1.0):
|
||||
def doit(self, scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, tile_width, tile_height, tiling_strategy, upscale_model_opt=None, pk_hook_opt=None):
|
||||
if "BNK_TiledKSampler" in nodes.NODE_CLASS_MAPPINGS:
|
||||
upscaler = core.PixelTiledKSampleUpscaler(scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise,
|
||||
tile_width, tile_height, tiling_strategy, upscale_model_opt, pk_hook_opt, tile_cnet_opt,
|
||||
tile_size=max(tile_width, tile_height), tile_cnet_strength=tile_cnet_strength)
|
||||
upscaler = core.PixelTiledKSampleUpscaler(scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, tile_width, tile_height, tiling_strategy, upscale_model_opt, pk_hook_opt, tile_size=max(tile_width, tile_height))
|
||||
return (upscaler, )
|
||||
else:
|
||||
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_TiledKSampler',
|
||||
"To use 'PixelTiledKSampleUpscalerProvider' node, 'BlenderNeko/ComfyUI_TiledKSampler' extension is required.")
|
||||
|
||||
raise Exception("[ERROR] PixelTiledKSampleUpscalerProvider: ComfyUI_TiledKSampler custom node isn't installed. You must install BlenderNeko/ComfyUI_TiledKSampler extension to use this node.")
|
||||
print("[ERROR] PixelTiledKSampleUpscalerProvider: ComfyUI_TiledKSampler custom node isn't installed. You must install BlenderNeko/ComfyUI_TiledKSampler extension to use this node.")
|
||||
|
||||
|
||||
class PixelTiledKSampleUpscalerProviderPipe:
|
||||
@@ -1013,8 +905,6 @@ class PixelTiledKSampleUpscalerProviderPipe:
|
||||
"optional": {
|
||||
"upscale_model_opt": ("UPSCALE_MODEL", ),
|
||||
"pk_hook_opt": ("PK_HOOK", ),
|
||||
"tile_cnet_opt": ("CONTROL_NET", ),
|
||||
"tile_cnet_strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1023,13 +913,10 @@ class PixelTiledKSampleUpscalerProviderPipe:
|
||||
|
||||
CATEGORY = "ImpactPack/Upscale"
|
||||
|
||||
def doit(self, scale_method, seed, steps, cfg, sampler_name, scheduler, denoise, tile_width, tile_height, tiling_strategy, basic_pipe, upscale_model_opt=None, pk_hook_opt=None,
|
||||
tile_cnet_opt=None, tile_cnet_strength=1.0):
|
||||
def doit(self, scale_method, seed, steps, cfg, sampler_name, scheduler, denoise, tile_width, tile_height, tiling_strategy, basic_pipe, upscale_model_opt=None, pk_hook_opt=None):
|
||||
if "BNK_TiledKSampler" in nodes.NODE_CLASS_MAPPINGS:
|
||||
model, _, vae, positive, negative = basic_pipe
|
||||
upscaler = core.PixelTiledKSampleUpscaler(scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise,
|
||||
tile_width, tile_height, tiling_strategy, upscale_model_opt, pk_hook_opt, tile_cnet_opt,
|
||||
tile_size=max(tile_width, tile_height), tile_cnet_strength=tile_cnet_strength)
|
||||
upscaler = core.PixelTiledKSampleUpscaler(scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, tile_width, tile_height, tiling_strategy, upscale_model_opt, pk_hook_opt, tile_size=max(tile_width, tile_height))
|
||||
return (upscaler, )
|
||||
else:
|
||||
print("[ERROR] PixelTiledKSampleUpscalerProviderPipe: ComfyUI_TiledKSampler custom node isn't installed. You must install BlenderNeko/ComfyUI_TiledKSampler extension to use this node.")
|
||||
@@ -1048,7 +935,7 @@ class PixelKSampleUpscalerProvider:
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||
"scheduler": (core.SCHEDULERS, ),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"positive": ("CONDITIONING", ),
|
||||
"negative": ("CONDITIONING", ),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
@@ -1058,7 +945,6 @@ class PixelKSampleUpscalerProvider:
|
||||
"optional": {
|
||||
"upscale_model_opt": ("UPSCALE_MODEL", ),
|
||||
"pk_hook_opt": ("PK_HOOK", ),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1068,10 +954,10 @@ class PixelKSampleUpscalerProvider:
|
||||
CATEGORY = "ImpactPack/Upscale"
|
||||
|
||||
def doit(self, scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise,
|
||||
use_tiled_vae, upscale_model_opt=None, pk_hook_opt=None, tile_size=512, scheduler_func_opt=None):
|
||||
use_tiled_vae, upscale_model_opt=None, pk_hook_opt=None, tile_size=512):
|
||||
upscaler = core.PixelKSampleUpscaler(scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, denoise, use_tiled_vae, upscale_model_opt, pk_hook_opt,
|
||||
tile_size=tile_size, scheduler_func=scheduler_func_opt)
|
||||
tile_size=tile_size)
|
||||
return (upscaler, )
|
||||
|
||||
|
||||
@@ -1086,7 +972,7 @@ class PixelKSampleUpscalerProviderPipe(PixelKSampleUpscalerProvider):
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||
"scheduler": (core.SCHEDULERS, ),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"use_tiled_vae": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"basic_pipe": ("BASIC_PIPE",),
|
||||
@@ -1095,9 +981,6 @@ class PixelKSampleUpscalerProviderPipe(PixelKSampleUpscalerProvider):
|
||||
"optional": {
|
||||
"upscale_model_opt": ("UPSCALE_MODEL", ),
|
||||
"pk_hook_opt": ("PK_HOOK", ),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
"tile_cnet_opt": ("CONTROL_NET", ),
|
||||
"tile_cnet_strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1107,13 +990,11 @@ class PixelKSampleUpscalerProviderPipe(PixelKSampleUpscalerProvider):
|
||||
CATEGORY = "ImpactPack/Upscale"
|
||||
|
||||
def doit_pipe(self, scale_method, seed, steps, cfg, sampler_name, scheduler, denoise,
|
||||
use_tiled_vae, basic_pipe, upscale_model_opt=None, pk_hook_opt=None,
|
||||
tile_size=512, scheduler_func_opt=None, tile_cnet_opt=None, tile_cnet_strength=1.0):
|
||||
use_tiled_vae, basic_pipe, upscale_model_opt=None, pk_hook_opt=None, tile_size=512):
|
||||
model, _, vae, positive, negative = basic_pipe
|
||||
upscaler = core.PixelKSampleUpscaler(scale_method, model, vae, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, denoise, use_tiled_vae, upscale_model_opt, pk_hook_opt,
|
||||
tile_size=tile_size, scheduler_func=scheduler_func_opt,
|
||||
tile_cnet_opt=tile_cnet_opt, tile_cnet_strength=tile_cnet_strength)
|
||||
tile_size=tile_size)
|
||||
return (upscaler, )
|
||||
|
||||
|
||||
@@ -1213,11 +1094,10 @@ class IterativeLatentUpscale:
|
||||
"upscale_factor": ("FLOAT", {"default": 1.5, "min": 1, "max": 10000, "step": 0.1}),
|
||||
"steps": ("INT", {"default": 3, "min": 1, "max": 10000, "step": 1}),
|
||||
"temp_prefix": ("STRING", {"default": ""}),
|
||||
"upscaler": ("UPSCALER",),
|
||||
"step_mode": (["simple", "geometric"], {"default": "simple"})
|
||||
},
|
||||
"upscaler": ("UPSCALER",)
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("LATENT", "VAE")
|
||||
RETURN_NAMES = ("latent", "vae")
|
||||
@@ -1225,27 +1105,19 @@ class IterativeLatentUpscale:
|
||||
|
||||
CATEGORY = "ImpactPack/Upscale"
|
||||
|
||||
def doit(self, samples, upscale_factor, steps, temp_prefix, upscaler, step_mode="simple", unique_id=None):
|
||||
def doit(self, samples, upscale_factor, steps, temp_prefix, upscaler, unique_id):
|
||||
w = samples['samples'].shape[3]*8 # image width
|
||||
h = samples['samples'].shape[2]*8 # image height
|
||||
|
||||
if temp_prefix == "":
|
||||
temp_prefix = None
|
||||
|
||||
if step_mode == "geometric":
|
||||
upscale_factor_unit = pow(upscale_factor, 1.0/steps)
|
||||
else: # simple
|
||||
upscale_factor_unit = max(0, (upscale_factor - 1.0) / steps)
|
||||
|
||||
upscale_factor_unit = max(0, (upscale_factor-1.0)/steps)
|
||||
current_latent = samples
|
||||
scale = 1
|
||||
|
||||
for i in range(steps-1):
|
||||
if step_mode == "geometric":
|
||||
scale *= upscale_factor_unit
|
||||
else: # simple
|
||||
scale += upscale_factor_unit
|
||||
|
||||
scale += upscale_factor_unit
|
||||
new_w = w*scale
|
||||
new_h = h*scale
|
||||
core.update_node_status(unique_id, f"{i+1}/{steps} steps | x{scale:.2f}", (i+1)/steps)
|
||||
@@ -1276,10 +1148,9 @@ class IterativeImageUpscale:
|
||||
"temp_prefix": ("STRING", {"default": ""}),
|
||||
"upscaler": ("UPSCALER",),
|
||||
"vae": ("VAE",),
|
||||
"step_mode": (["simple", "geometric"], {"default": "simple"})
|
||||
},
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"}
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
RETURN_NAMES = ("image",)
|
||||
@@ -1287,7 +1158,7 @@ class IterativeImageUpscale:
|
||||
|
||||
CATEGORY = "ImpactPack/Upscale"
|
||||
|
||||
def doit(self, pixels, upscale_factor, steps, temp_prefix, upscaler, vae, step_mode="simple", unique_id=None):
|
||||
def doit(self, pixels, upscale_factor, steps, temp_prefix, upscaler, vae, unique_id):
|
||||
if temp_prefix == "":
|
||||
temp_prefix = None
|
||||
|
||||
@@ -1297,7 +1168,7 @@ class IterativeImageUpscale:
|
||||
else:
|
||||
latent = nodes.VAEEncode().encode(vae, pixels)[0]
|
||||
|
||||
refined_latent = IterativeLatentUpscale().doit(latent, upscale_factor, steps, temp_prefix, upscaler, step_mode, unique_id)
|
||||
refined_latent = IterativeLatentUpscale().doit(latent, upscale_factor, steps, temp_prefix, upscaler, unique_id)
|
||||
|
||||
core.update_node_status(unique_id, "VAEDecode (final)", 1.0)
|
||||
if upscaler.is_tiled:
|
||||
@@ -1316,18 +1187,18 @@ class FaceDetailerPipe:
|
||||
return {"required": {
|
||||
"image": ("IMAGE", ),
|
||||
"detailer_pipe": ("DETAILER_PIPE",),
|
||||
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"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": (core.SCHEDULERS,),
|
||||
"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}),
|
||||
"noise_mask": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"force_inpaint": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"force_inpaint": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
|
||||
"bbox_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"bbox_dilation": ("INT", {"default": 10, "min": -512, "max": 512, "step": 1}),
|
||||
@@ -1347,8 +1218,7 @@ class FaceDetailerPipe:
|
||||
},
|
||||
"optional": {
|
||||
"inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
"noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1363,7 +1233,7 @@ class FaceDetailerPipe:
|
||||
denoise, feather, noise_mask, force_inpaint, bbox_threshold, bbox_dilation, bbox_crop_factor,
|
||||
sam_detection_hint, sam_dilation, sam_threshold, sam_bbox_expansion,
|
||||
sam_mask_hint_threshold, sam_mask_hint_use_negative, drop_size, refiner_ratio=None,
|
||||
cycle=1, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
cycle=1, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
result_img = None
|
||||
result_mask = None
|
||||
@@ -1386,7 +1256,7 @@ class FaceDetailerPipe:
|
||||
sam_mask_hint_use_negative, drop_size, bbox_detector, segm_detector, sam_model_opt, wildcard, detailer_hook,
|
||||
refiner_ratio=refiner_ratio, refiner_model=refiner_model,
|
||||
refiner_clip=refiner_clip, refiner_positive=refiner_positive, refiner_negative=refiner_negative,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
result_img = torch.cat((result_img, enhanced_img), dim=0) if result_img is not None else enhanced_img
|
||||
result_mask = torch.cat((result_mask, mask), dim=0) if result_mask is not None else mask
|
||||
@@ -1414,7 +1284,7 @@ class MaskDetailerPipe:
|
||||
"mask": ("MASK", ),
|
||||
"basic_pipe": ("BASIC_PIPE",),
|
||||
|
||||
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"guide_size": ("FLOAT", {"default": 384, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"guide_size_for": ("BOOLEAN", {"default": True, "label_on": "mask bbox", "label_off": "crop region"}),
|
||||
"max_size": ("FLOAT", {"default": 1024, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
|
||||
"mask_mode": ("BOOLEAN", {"default": True, "label_on": "masked only", "label_off": "whole"}),
|
||||
@@ -1423,7 +1293,7 @@ class MaskDetailerPipe:
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
|
||||
"scheduler": (core.SCHEDULERS,),
|
||||
"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}),
|
||||
@@ -1438,10 +1308,7 @@ class MaskDetailerPipe:
|
||||
"refiner_basic_pipe_opt": ("BASIC_PIPE", ),
|
||||
"detailer_hook": ("DETAILER_HOOK",),
|
||||
"inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
"bbox_fill": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"contour_fill": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
"noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1455,8 +1322,7 @@ class MaskDetailerPipe:
|
||||
def doit(self, image, mask, basic_pipe, guide_size, guide_size_for, max_size, mask_mode,
|
||||
seed, steps, cfg, sampler_name, scheduler, denoise,
|
||||
feather, crop_factor, drop_size, refiner_ratio, batch_size, cycle=1,
|
||||
refiner_basic_pipe_opt=None, detailer_hook=None, inpaint_model=False, noise_mask_feather=0,
|
||||
bbox_fill=False, contour_fill=True, scheduler_func_opt=None):
|
||||
refiner_basic_pipe_opt=None, detailer_hook=None, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: MaskDetailer 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.')
|
||||
@@ -1471,7 +1337,7 @@ class MaskDetailerPipe:
|
||||
# create segs
|
||||
if mask is not None:
|
||||
mask = make_2d_mask(mask)
|
||||
segs = core.mask_to_segs(mask, False, crop_factor, bbox_fill, drop_size, is_contour=contour_fill)
|
||||
segs = core.mask_to_segs(mask, False, crop_factor, False, drop_size)
|
||||
else:
|
||||
segs = ((image.shape[1], image.shape[2]), [])
|
||||
|
||||
@@ -1487,7 +1353,7 @@ class MaskDetailerPipe:
|
||||
force_inpaint=True, wildcard_opt=None, detailer_hook=detailer_hook,
|
||||
refiner_ratio=refiner_ratio, refiner_model=refiner_model, refiner_clip=refiner_clip,
|
||||
refiner_positive=refiner_positive, refiner_negative=refiner_negative,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
else:
|
||||
enhanced_img, cropped_enhanced, cropped_enhanced_alpha = image, [], []
|
||||
|
||||
@@ -1520,7 +1386,7 @@ class DetailerForEachTest(DetailerForEach):
|
||||
|
||||
def doit(self, image, segs, model, clip, vae, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name,
|
||||
scheduler, positive, negative, denoise, feather, noise_mask, force_inpaint, wildcard, detailer_hook=None,
|
||||
cycle=1, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
cycle=1, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: DetailerForEach 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.')
|
||||
@@ -1529,7 +1395,7 @@ class DetailerForEachTest(DetailerForEach):
|
||||
DetailerForEach.do_detail(image, segs, model, clip, vae, guide_size, guide_size_for, max_size, seed, steps,
|
||||
cfg, sampler_name, scheduler, positive, negative, denoise, feather, noise_mask,
|
||||
force_inpaint, wildcard, detailer_hook,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
# set fallback image
|
||||
if len(cropped) == 0:
|
||||
@@ -1558,7 +1424,7 @@ class DetailerForEachTestPipe(DetailerForEachPipe):
|
||||
|
||||
def doit(self, image, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, feather, noise_mask, force_inpaint, basic_pipe, wildcard, cycle=1,
|
||||
refiner_ratio=None, detailer_hook=None, refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
refiner_ratio=None, detailer_hook=None, refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: DetailerForEach 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.')
|
||||
@@ -1577,7 +1443,7 @@ class DetailerForEachTestPipe(DetailerForEachPipe):
|
||||
refiner_ratio=refiner_ratio, refiner_model=refiner_model,
|
||||
refiner_clip=refiner_clip, refiner_positive=refiner_positive,
|
||||
refiner_negative=refiner_negative,
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
cycle=cycle, inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
# set fallback image
|
||||
if len(cropped) == 0:
|
||||
@@ -1646,13 +1512,43 @@ class BitwiseAndMaskForEach:
|
||||
|
||||
CATEGORY = "ImpactPack/Operation"
|
||||
|
||||
DESCRIPTION = "Retains only the overlapping areas between the masks included in base_segs and the mask regions of mask_segs. SEGS with no overlapping mask areas are filtered out."
|
||||
|
||||
def doit(self, base_segs, mask_segs):
|
||||
mask = core.segs_to_combined_mask(mask_segs)
|
||||
mask = make_3d_mask(mask)
|
||||
|
||||
return SegsBitwiseAndMask().doit(base_segs, mask)
|
||||
result = []
|
||||
|
||||
for bseg in base_segs[1]:
|
||||
cropped_mask1 = bseg.cropped_mask.copy()
|
||||
crop_region1 = bseg.crop_region
|
||||
|
||||
for mseg in mask_segs[1]:
|
||||
cropped_mask2 = mseg.cropped_mask
|
||||
crop_region2 = mseg.crop_region
|
||||
|
||||
# compute the intersection of the two crop regions
|
||||
intersect_region = (max(crop_region1[0], crop_region2[0]),
|
||||
max(crop_region1[1], crop_region2[1]),
|
||||
min(crop_region1[2], crop_region2[2]),
|
||||
min(crop_region1[3], crop_region2[3]))
|
||||
|
||||
overlapped = False
|
||||
|
||||
# set all pixels in cropped_mask1 to 0 except for those that overlap with cropped_mask2
|
||||
for i in range(intersect_region[0], intersect_region[2]):
|
||||
for j in range(intersect_region[1], intersect_region[3]):
|
||||
if cropped_mask1[j - crop_region1[1], i - crop_region1[0]] == 1 and \
|
||||
cropped_mask2[j - crop_region2[1], i - crop_region2[0]] == 1:
|
||||
# pixel overlaps with both masks, keep it as 1
|
||||
overlapped = True
|
||||
pass
|
||||
else:
|
||||
# pixel does not overlap with both masks, set it to 0
|
||||
cropped_mask1[j - crop_region1[1], i - crop_region1[0]] = 0
|
||||
|
||||
if overlapped:
|
||||
item = SEG(bseg.cropped_image, cropped_mask1, bseg.confidence, bseg.crop_region, bseg.bbox, bseg.label, None)
|
||||
result.append(item)
|
||||
|
||||
return ((base_segs[0], result),)
|
||||
|
||||
|
||||
class SubtractMaskForEach:
|
||||
@@ -1669,12 +1565,45 @@ class SubtractMaskForEach:
|
||||
|
||||
CATEGORY = "ImpactPack/Operation"
|
||||
|
||||
DESCRIPTION = "Removes only the overlapping areas between the masks included in base_segs and the mask regions of mask_segs. SEGS with no overlapping mask areas are filtered out."
|
||||
|
||||
def doit(self, base_segs, mask_segs):
|
||||
mask = core.segs_to_combined_mask(mask_segs)
|
||||
mask = make_3d_mask(mask)
|
||||
return (core.segs_bitwise_subtract_mask(base_segs, mask), )
|
||||
|
||||
result = []
|
||||
|
||||
for bseg in base_segs[1]:
|
||||
cropped_mask1 = bseg.cropped_mask.copy()
|
||||
crop_region1 = bseg.crop_region
|
||||
|
||||
for mseg in mask_segs[1]:
|
||||
cropped_mask2 = mseg.cropped_mask
|
||||
crop_region2 = mseg.crop_region
|
||||
|
||||
# compute the intersection of the two crop regions
|
||||
intersect_region = (max(crop_region1[0], crop_region2[0]),
|
||||
max(crop_region1[1], crop_region2[1]),
|
||||
min(crop_region1[2], crop_region2[2]),
|
||||
min(crop_region1[3], crop_region2[3]))
|
||||
|
||||
changed = False
|
||||
|
||||
# subtract operation
|
||||
for i in range(intersect_region[0], intersect_region[2]):
|
||||
for j in range(intersect_region[1], intersect_region[3]):
|
||||
if cropped_mask1[j - crop_region1[1], i - crop_region1[0]] == 1 and \
|
||||
cropped_mask2[j - crop_region2[1], i - crop_region2[0]] == 1:
|
||||
# pixel overlaps with both masks, set it as 0
|
||||
changed = True
|
||||
cropped_mask1[j - crop_region1[1], i - crop_region1[0]] = 0
|
||||
else:
|
||||
# pixel does not overlap with both masks, don't care
|
||||
pass
|
||||
|
||||
if changed:
|
||||
item = SEG(bseg.cropped_image, cropped_mask1, bseg.confidence, bseg.crop_region, bseg.bbox, bseg.label, None)
|
||||
result.append(item)
|
||||
else:
|
||||
result.append(base_segs)
|
||||
|
||||
return ((base_segs[0], result),)
|
||||
|
||||
|
||||
class ToBinaryMask:
|
||||
@@ -1696,25 +1625,6 @@ class ToBinaryMask:
|
||||
return (mask,)
|
||||
|
||||
|
||||
class FlattenMask:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"masks": ("MASK",),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MASK",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Operation"
|
||||
|
||||
def doit(self, masks):
|
||||
masks = utils.make_3d_mask(masks)
|
||||
masks = utils.flatten_mask(masks)
|
||||
return (masks,)
|
||||
|
||||
|
||||
class BitwiseAndMask:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -2153,7 +2063,7 @@ class ImpactWildcardProcessor:
|
||||
return impact.wildcards.process(**kwargs)
|
||||
|
||||
def doit(self, *args, **kwargs):
|
||||
populated_text = ImpactWildcardProcessor.process(text=kwargs['populated_text'], seed=kwargs['seed'])
|
||||
populated_text = kwargs['populated_text']
|
||||
return (populated_text, )
|
||||
|
||||
|
||||
@@ -2188,29 +2098,9 @@ class ImpactWildcardEncode:
|
||||
|
||||
def doit(self, *args, **kwargs):
|
||||
populated = kwargs['populated_text']
|
||||
processed = []
|
||||
model, clip, conditioning = impact.wildcards.process_with_loras(wildcard_opt=populated, model=kwargs['model'], clip=kwargs['clip'], seed=kwargs['seed'], processed=processed)
|
||||
return model, clip, conditioning, processed[0]
|
||||
model, clip, conditioning = impact.wildcards.process_with_loras(populated, kwargs['model'], kwargs['clip'])
|
||||
return (model, clip, conditioning, populated)
|
||||
|
||||
|
||||
class ImpactSchedulerAdapter:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, {"defaultInput": True, }),
|
||||
"extra_scheduler": (['None', 'AYS SDXL', 'AYS SD1', 'AYS SVD', 'GITS[coeff=1.2]'],),
|
||||
}}
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
RETURN_TYPES = (core.SCHEDULERS,)
|
||||
RETURN_NAMES = ("scheduler",)
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
def doit(self, scheduler, extra_scheduler):
|
||||
if extra_scheduler != 'None':
|
||||
return (extra_scheduler,)
|
||||
|
||||
return (scheduler,)
|
||||
|
||||
|
||||
@@ -2,19 +2,9 @@ import nodes
|
||||
from comfy.k_diffusion import sampling as k_diffusion_sampling
|
||||
from comfy import samplers
|
||||
from comfy_extras import nodes_custom_sampler
|
||||
import latent_preview
|
||||
import comfy
|
||||
|
||||
import torch
|
||||
import math
|
||||
import comfy.model_management as mm
|
||||
|
||||
|
||||
try:
|
||||
from comfy_extras.nodes_custom_sampler import Noise_EmptyNoise, Noise_RandomNoise
|
||||
import node_helpers
|
||||
except:
|
||||
print(f"\n#############################################\n[Impact Pack] ComfyUI is an outdated version.\n#############################################\n")
|
||||
raise Exception("[Impact Pack] ComfyUI is an outdated version.")
|
||||
|
||||
|
||||
def calculate_sigmas(model, sampler, scheduler, steps):
|
||||
@@ -23,12 +13,7 @@ def calculate_sigmas(model, sampler, scheduler, steps):
|
||||
steps += 1
|
||||
discard_penultimate_sigma = True
|
||||
|
||||
if scheduler.startswith('AYS'):
|
||||
sigmas = nodes.NODE_CLASS_MAPPINGS['AlignYourStepsScheduler']().get_sigmas(scheduler[4:], steps, denoise=1.0)[0]
|
||||
elif scheduler.startswith('GITS[coeff='):
|
||||
sigmas = nodes.NODE_CLASS_MAPPINGS['GITSScheduler']().get_sigmas(float(scheduler[11:-1]), steps, denoise=1.0)[0]
|
||||
else:
|
||||
sigmas = samplers.calculate_sigmas(model.get_model_object("model_sampling"), scheduler, steps)
|
||||
sigmas = samplers.calculate_sigmas_scheduler(model.model, scheduler, steps)
|
||||
|
||||
if discard_penultimate_sigma:
|
||||
sigmas = torch.cat([sigmas[:-2], sigmas[-1:]])
|
||||
@@ -90,7 +75,7 @@ def ksampler(sampler_name, total_sigmas, extra_options={}, inpaint_options={}):
|
||||
if noise_sampler is not None:
|
||||
kwargs['noise_sampler'] = noise_sampler
|
||||
|
||||
return k_diffusion_sampling.sample_dpmpp_3m_sde(model, x, sigmas, **kwargs)
|
||||
return k_diffusion_sampling.sample_dpmpp_2m_sde(model, x, sigmas, **kwargs)
|
||||
|
||||
sampler_function = sample_dpmpp_sde
|
||||
|
||||
@@ -100,109 +85,23 @@ def ksampler(sampler_name, total_sigmas, extra_options={}, inpaint_options={}):
|
||||
if noise_sampler is not None:
|
||||
kwargs['noise_sampler'] = noise_sampler
|
||||
|
||||
return k_diffusion_sampling.sample_dpmpp_3m_sde_gpu(model, x, sigmas, **kwargs)
|
||||
return k_diffusion_sampling.sample_dpmpp_2m_sde_gpu(model, x, sigmas, **kwargs)
|
||||
|
||||
sampler_function = sample_dpmpp_sde
|
||||
|
||||
else:
|
||||
return comfy.samplers.sampler_object(sampler_name)
|
||||
return samplers.ksampler(sampler_name, extra_options, inpaint_options)
|
||||
|
||||
return samplers.KSAMPLER(sampler_function, extra_options, inpaint_options)
|
||||
|
||||
|
||||
# modified version of SamplerCustom.sample
|
||||
def sample_with_custom_noise(model, add_noise, noise_seed, cfg, positive, negative, sampler, sigmas, latent_image, noise=None, callback=None):
|
||||
latent = latent_image
|
||||
latent_image = latent["samples"]
|
||||
|
||||
if hasattr(comfy.sample, 'fix_empty_latent_channels'):
|
||||
latent_image = comfy.sample.fix_empty_latent_channels(model, latent_image)
|
||||
|
||||
out = latent.copy()
|
||||
out['samples'] = latent_image
|
||||
|
||||
if noise is None:
|
||||
if not add_noise:
|
||||
noise = Noise_EmptyNoise().generate_noise(out)
|
||||
else:
|
||||
noise = Noise_RandomNoise(noise_seed).generate_noise(out)
|
||||
|
||||
noise_mask = None
|
||||
if "noise_mask" in latent:
|
||||
noise_mask = latent["noise_mask"]
|
||||
|
||||
x0_output = {}
|
||||
preview_callback = latent_preview.prepare_callback(model, sigmas.shape[-1] - 1, x0_output)
|
||||
|
||||
if callback is not None:
|
||||
def touched_callback(step, x0, x, total_steps):
|
||||
callback(step, x0, x, total_steps)
|
||||
preview_callback(step, x0, x, total_steps)
|
||||
else:
|
||||
touched_callback = preview_callback
|
||||
|
||||
disable_pbar = not comfy.utils.PROGRESS_BAR_ENABLED
|
||||
|
||||
device = mm.get_torch_device()
|
||||
|
||||
noise = noise.to(device)
|
||||
latent_image = latent_image.to(device)
|
||||
if noise_mask is not None:
|
||||
noise_mask = noise_mask.to(device)
|
||||
|
||||
if negative != 'NegativePlaceholder':
|
||||
# This way is incompatible with Advanced ControlNet, yet.
|
||||
# guider = comfy.samplers.CFGGuider(model)
|
||||
# guider.set_conds(positive, negative)
|
||||
# guider.set_cfg(cfg)
|
||||
samples = comfy.sample.sample_custom(model, noise, cfg, sampler, sigmas, positive, negative, latent_image,
|
||||
noise_mask=noise_mask, callback=touched_callback,
|
||||
disable_pbar=disable_pbar, seed=noise_seed)
|
||||
else:
|
||||
guider = nodes_custom_sampler.Guider_Basic(model)
|
||||
positive = node_helpers.conditioning_set_values(positive, {"guidance": cfg})
|
||||
guider.set_conds(positive)
|
||||
samples = guider.sample(noise, latent_image, sampler, sigmas, denoise_mask=noise_mask, callback=touched_callback, disable_pbar=disable_pbar, seed=noise_seed)
|
||||
|
||||
samples = samples.to(comfy.model_management.intermediate_device())
|
||||
|
||||
out["samples"] = samples
|
||||
if "x0" in x0_output:
|
||||
out_denoised = latent.copy()
|
||||
out_denoised["samples"] = model.model.process_latent_out(x0_output["x0"].cpu())
|
||||
else:
|
||||
out_denoised = out
|
||||
return out, out_denoised
|
||||
|
||||
|
||||
# When sampling one step at a time, it mitigates the problem. (especially for _sde series samplers)
|
||||
def separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler, positive, negative,
|
||||
latent_image, start_at_step, end_at_step, return_with_leftover_noise, sigma_ratio=1.0, sampler_opt=None, noise=None, callback=None, scheduler_func=None):
|
||||
|
||||
if scheduler_func is not None:
|
||||
total_sigmas = scheduler_func(model, sampler_name, steps)
|
||||
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:
|
||||
if sampler_opt is None:
|
||||
total_sigmas = calculate_sigmas(model, sampler_name, scheduler, steps)
|
||||
else:
|
||||
total_sigmas = calculate_sigmas(model, "", scheduler, steps)
|
||||
|
||||
sigmas = total_sigmas
|
||||
|
||||
if end_at_step is not None and end_at_step < (len(total_sigmas) - 1):
|
||||
sigmas = total_sigmas[:end_at_step + 1]
|
||||
if not return_with_leftover_noise:
|
||||
sigmas[-1] = 0
|
||||
|
||||
if start_at_step is not None:
|
||||
if start_at_step < (len(sigmas) - 1):
|
||||
sigmas = sigmas[start_at_step:] * sigma_ratio
|
||||
else:
|
||||
if latent_image is not None:
|
||||
return latent_image
|
||||
else:
|
||||
return {'samples': torch.zeros_like(noise)}
|
||||
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:
|
||||
@@ -211,7 +110,7 @@ def separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler
|
||||
if len(sigmas) == 0 or (len(sigmas) == 1 and sigmas[0] == 0):
|
||||
return latent_image
|
||||
|
||||
res = sample_with_custom_noise(model, add_noise, seed, cfg, positive, negative, impact_sampler, sigmas, latent_image, noise=noise, callback=callback)
|
||||
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]
|
||||
@@ -219,28 +118,11 @@ def separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler
|
||||
return res[1]
|
||||
|
||||
|
||||
def impact_sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=1.0, sigma_ratio=1.0, sampler_opt=None, noise=None, scheduler_func=None):
|
||||
advanced_steps = math.floor(steps / denoise)
|
||||
start_at_step = advanced_steps - steps
|
||||
end_at_step = start_at_step + steps
|
||||
return separated_sample(model, True, seed, advanced_steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
|
||||
start_at_step, end_at_step, False, scheduler_func=scheduler_func)
|
||||
|
||||
|
||||
def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise,
|
||||
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None, refiner_negative=None, sigma_factor=1.0, noise=None, scheduler_func=None):
|
||||
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None, refiner_negative=None, sigma_factor=1.0):
|
||||
|
||||
if refiner_ratio is None or refiner_model is None or refiner_clip is None or refiner_positive is None or refiner_negative is None:
|
||||
# Use separated_sample instead of KSampler for `AYS scheduler`
|
||||
# refined_latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise * sigma_factor)[0]
|
||||
|
||||
advanced_steps = math.floor(steps / denoise)
|
||||
start_at_step = advanced_steps - steps
|
||||
end_at_step = start_at_step + steps
|
||||
|
||||
refined_latent = separated_sample(model, True, seed, advanced_steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, latent_image, start_at_step, end_at_step, False,
|
||||
sigma_ratio=sigma_factor, noise=noise, scheduler_func=scheduler_func)
|
||||
refined_latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise * sigma_factor)[0]
|
||||
else:
|
||||
advanced_steps = math.floor(steps / denoise)
|
||||
start_at_step = advanced_steps - steps
|
||||
@@ -248,8 +130,7 @@ def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive,
|
||||
|
||||
# print(f"pre: {start_at_step} .. {end_at_step} / {advanced_steps}")
|
||||
temp_latent = separated_sample(model, True, seed, advanced_steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, latent_image, start_at_step, end_at_step, True,
|
||||
sigma_ratio=sigma_factor, noise=noise, scheduler_func=scheduler_func)
|
||||
positive, negative, latent_image, start_at_step, end_at_step, True, sigma_ratio=sigma_factor)
|
||||
|
||||
if 'noise_mask' in latent_image:
|
||||
# noise_latent = \
|
||||
@@ -262,8 +143,7 @@ def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive,
|
||||
|
||||
# print(f"post: {end_at_step} .. {advanced_steps + 1} / {advanced_steps}")
|
||||
refined_latent = separated_sample(refiner_model, False, seed, advanced_steps, cfg, sampler_name, scheduler,
|
||||
refiner_positive, refiner_negative, temp_latent, end_at_step, advanced_steps + 1, False,
|
||||
sigma_ratio=sigma_factor, scheduler_func=scheduler_func)
|
||||
refiner_positive, refiner_negative, temp_latent, end_at_step, advanced_steps + 1, False, sigma_ratio=sigma_factor)
|
||||
|
||||
return refined_latent
|
||||
|
||||
@@ -271,17 +151,16 @@ def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive,
|
||||
class KSamplerAdvancedWrapper:
|
||||
params = None
|
||||
|
||||
def __init__(self, model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=None, sigma_factor=1.0, scheduler_func=None):
|
||||
def __init__(self, model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=None, sigma_factor=1.0):
|
||||
self.params = model, cfg, sampler_name, scheduler, positive, negative, sigma_factor
|
||||
self.sampler_opt = sampler_opt
|
||||
self.scheduler_func = scheduler_func
|
||||
|
||||
def clone_with_conditionings(self, positive, negative):
|
||||
model, cfg, sampler_name, scheduler, _, _, _ = self.params
|
||||
return KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, self.sampler_opt)
|
||||
|
||||
def sample_advanced(self, add_noise, seed, steps, latent_image, start_at_step, end_at_step, return_with_leftover_noise, hook=None,
|
||||
recovery_mode="ratio additional", recovery_sampler="AUTO", recovery_sigma_ratio=1.0, noise=None):
|
||||
recovery_mode="ratio additional", recovery_sampler="AUTO", recovery_sigma_ratio=1.0):
|
||||
|
||||
model, cfg, sampler_name, scheduler, positive, negative, sigma_factor = self.params
|
||||
# steps, start_at_step, end_at_step = self.compensate_denoise(steps, start_at_step, end_at_step)
|
||||
@@ -305,8 +184,7 @@ class KSamplerAdvancedWrapper:
|
||||
if sigma_ratio > 0:
|
||||
latent_image = separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, latent_image, start_at_step, end_at_step,
|
||||
return_with_leftover_noise, sigma_ratio=sigma_ratio * sigma_factor,
|
||||
sampler_opt=self.sampler_opt, noise=noise, scheduler_func=self.scheduler_func)
|
||||
return_with_leftover_noise, sigma_ratio=sigma_ratio * sigma_factor, 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")
|
||||
@@ -329,8 +207,8 @@ class KSamplerAdvancedWrapper:
|
||||
|
||||
try:
|
||||
latent_image = separated_sample(model, add_noise, seed, steps, cfg, recovery_sampler, scheduler,
|
||||
positive, negative, latent_image, start_at_step-compensate, end_at_step, return_with_leftover_noise,
|
||||
sigma_ratio=recovery_sigma_ratio * sigma_factor, sampler_opt=self.sampler_opt, scheduler_func=self.scheduler_func)
|
||||
positive, negative, latent_image, start_at_step-compensate, end_at_step,
|
||||
return_with_leftover_noise, sigma_ratio=recovery_sigma_ratio * sigma_factor, sampler_opt=self.sampler_opt)
|
||||
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")
|
||||
@@ -341,9 +219,8 @@ class KSamplerAdvancedWrapper:
|
||||
class KSamplerWrapper:
|
||||
params = None
|
||||
|
||||
def __init__(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, scheduler_func=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
|
||||
self.scheduler_func = scheduler_func
|
||||
|
||||
def sample(self, latent_image, hook=None):
|
||||
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise = self.params
|
||||
@@ -352,4 +229,4 @@ class KSamplerWrapper:
|
||||
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
|
||||
hook.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)
|
||||
|
||||
return impact_sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise, scheduler_func=self.scheduler_func)
|
||||
return nodes.common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)[0]
|
||||
|
||||
@@ -5,6 +5,7 @@ import traceback
|
||||
from aiohttp import web
|
||||
|
||||
import impact
|
||||
import server
|
||||
import folder_paths
|
||||
|
||||
import torchvision
|
||||
@@ -21,10 +22,9 @@ import impact.wildcards as wildcards
|
||||
import comfy
|
||||
from io import BytesIO
|
||||
import random
|
||||
from server import PromptServer
|
||||
|
||||
|
||||
@PromptServer.instance.routes.post("/upload/temp")
|
||||
@server.PromptServer.instance.routes.post("/upload/temp")
|
||||
async def upload_image(request):
|
||||
upload_dir = folder_paths.get_temp_directory()
|
||||
|
||||
@@ -91,7 +91,7 @@ def async_prepare_sam(image_dir, model_name, filename):
|
||||
sam_predictor.model.cpu()
|
||||
|
||||
|
||||
@PromptServer.instance.routes.post("/sam/prepare")
|
||||
@server.PromptServer.instance.routes.post("/sam/prepare")
|
||||
async def sam_prepare(request):
|
||||
global sam_predictor
|
||||
global last_prepare_data
|
||||
@@ -127,10 +127,9 @@ async def sam_prepare(request):
|
||||
thread.start()
|
||||
|
||||
print(f"[INFO] ComfyUI-Impact-Pack: SAM model loaded. ")
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.post("/sam/release")
|
||||
@server.PromptServer.instance.routes.post("/sam/release")
|
||||
async def release_sam(request):
|
||||
global sam_predictor
|
||||
|
||||
@@ -141,7 +140,7 @@ async def release_sam(request):
|
||||
print(f"[INFO] ComfyUI-Impact-Pack: unloading SAM model")
|
||||
|
||||
|
||||
@PromptServer.instance.routes.post("/sam/detect")
|
||||
@server.PromptServer.instance.routes.post("/sam/detect")
|
||||
async def sam_detect(request):
|
||||
global sam_predictor
|
||||
with sam_lock:
|
||||
@@ -194,19 +193,13 @@ async def sam_detect(request):
|
||||
return web.Response(status=400)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.get("/impact/wildcards/refresh")
|
||||
async def wildcards_refresh(request):
|
||||
impact.wildcards.wildcard_load()
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.get("/impact/wildcards/list")
|
||||
@server.PromptServer.instance.routes.get("/impact/wildcards/list")
|
||||
async def wildcards_list(request):
|
||||
data = {'data': impact.wildcards.get_wildcard_list()}
|
||||
return web.json_response(data)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.post("/impact/wildcards")
|
||||
@server.PromptServer.instance.routes.post("/impact/wildcards")
|
||||
async def populate_wildcards(request):
|
||||
data = await request.json()
|
||||
populated = wildcards.process(data['text'], data.get('seed', None))
|
||||
@@ -215,7 +208,7 @@ async def populate_wildcards(request):
|
||||
|
||||
segs_picker_map = {}
|
||||
|
||||
@PromptServer.instance.routes.get("/impact/segs/picker/count")
|
||||
@server.PromptServer.instance.routes.get("/impact/segs/picker/count")
|
||||
async def segs_picker_count(request):
|
||||
node_id = request.rel_url.query.get('id', '')
|
||||
|
||||
@@ -226,7 +219,7 @@ async def segs_picker_count(request):
|
||||
return web.Response(status=400)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.get("/impact/segs/picker/view")
|
||||
@server.PromptServer.instance.routes.get("/impact/segs/picker/view")
|
||||
async def segs_picker(request):
|
||||
node_id = request.rel_url.query.get('id', '')
|
||||
idx = int(request.rel_url.query.get('idx', ''))
|
||||
@@ -243,7 +236,7 @@ async def segs_picker(request):
|
||||
return web.Response(status=400)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.get("/view/validate")
|
||||
@server.PromptServer.instance.routes.get("/view/validate")
|
||||
async def view_validate(request):
|
||||
if "filename" in request.rel_url.query:
|
||||
filename = request.rel_url.query["filename"]
|
||||
@@ -264,7 +257,7 @@ async def view_validate(request):
|
||||
return web.Response(status=400)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.get("/impact/validate/pb_id_image")
|
||||
@server.PromptServer.instance.routes.get("/impact/validate/pb_id_image")
|
||||
async def view_validate(request):
|
||||
if "id" in request.rel_url.query:
|
||||
pb_id = request.rel_url.query["id"]
|
||||
@@ -279,7 +272,7 @@ async def view_validate(request):
|
||||
return web.Response(status=400)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.get("/impact/set/pb_id_image")
|
||||
@server.PromptServer.instance.routes.get("/impact/set/pb_id_image")
|
||||
async def set_previewbridge_image(request):
|
||||
try:
|
||||
if "filename" in request.rel_url.query:
|
||||
@@ -315,7 +308,7 @@ async def set_previewbridge_image(request):
|
||||
return web.Response(status=400)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.get("/impact/get/pb_id_image")
|
||||
@server.PromptServer.instance.routes.get("/impact/get/pb_id_image")
|
||||
async def get_previewbridge_image(request):
|
||||
if "id" in request.rel_url.query:
|
||||
pb_id = request.rel_url.query["id"]
|
||||
@@ -327,7 +320,7 @@ async def get_previewbridge_image(request):
|
||||
return web.Response(status=400)
|
||||
|
||||
|
||||
@PromptServer.instance.routes.get("/impact/view/pb_id_image")
|
||||
@server.PromptServer.instance.routes.get("/impact/view/pb_id_image")
|
||||
async def view_previewbridge_image(request):
|
||||
if "id" in request.rel_url.query:
|
||||
pb_id = request.rel_url.query["id"]
|
||||
@@ -353,16 +346,13 @@ def onprompt_for_switch(json_data):
|
||||
|
||||
cls = v['class_type']
|
||||
if cls == 'ImpactInversedSwitch':
|
||||
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'select' in v['inputs']:
|
||||
select_input = v['inputs']['select']
|
||||
if isinstance(select_input, list) and len(select_input) == 2:
|
||||
input_node = json_data['prompt'][select_input[0]]
|
||||
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
|
||||
inversed_switch_info[k] = input_node['inputs']['value']
|
||||
else:
|
||||
print(f"\n##### ##### #####\n[WARN] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactInversedSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs if 'select_on_prompt' is selected.\n##### ##### #####\n")
|
||||
else:
|
||||
inversed_switch_info[k] = select_input
|
||||
select_input = v['inputs']['select']
|
||||
if isinstance(select_input, list) and len(select_input) == 2:
|
||||
input_node = json_data['prompt'][select_input[0]]
|
||||
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
|
||||
inversed_switch_info[k] = input_node['inputs']['value']
|
||||
else:
|
||||
inversed_switch_info[k] = select_input
|
||||
|
||||
elif cls in ['ImpactSwitch', 'LatentSwitch', 'SEGSSwitch', 'ImpactMakeImageList']:
|
||||
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'select' in v['inputs']:
|
||||
@@ -375,7 +365,7 @@ def onprompt_for_switch(json_data):
|
||||
if isinstance(input_node['inputs']['select'], int):
|
||||
onprompt_switch_info[k] = input_node['inputs']['select']
|
||||
else:
|
||||
print(f"\n##### ##### #####\n[WARN] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs if 'select_on_prompt' is selected.\n##### ##### #####\n")
|
||||
print(f"\n##### ##### #####\n[WARN] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs.\n##### ##### #####\n")
|
||||
else:
|
||||
onprompt_switch_info[k] = select_input
|
||||
|
||||
@@ -473,7 +463,7 @@ def regional_sampler_seed_update(json_data):
|
||||
new_seed = random.randint(0, 1125899906842624)
|
||||
|
||||
if new_seed is not None:
|
||||
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "seed_2nd", "type": "INT", "value": new_seed})
|
||||
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):
|
||||
@@ -506,7 +496,7 @@ def onprompt_populate_wildcards(json_data):
|
||||
inputs['populated_text'] = wildcards.process(inputs['wildcard_text'], input_seed)
|
||||
inputs['mode'] = False
|
||||
|
||||
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "populated_text", "type": "STRING", "value": inputs['populated_text']})
|
||||
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']:
|
||||
@@ -545,7 +535,7 @@ def onprompt_for_remote(json_data):
|
||||
break
|
||||
|
||||
target_inputs[widget_name] = inputs['value']
|
||||
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": node_id, "widget_name": widget_name, "type": widget_type, "value": inputs['value']})
|
||||
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):
|
||||
@@ -557,11 +547,10 @@ def onprompt(json_data):
|
||||
gc_preview_bridge_cache(json_data)
|
||||
workflow_imagereceiver_update(json_data)
|
||||
regional_sampler_seed_update(json_data)
|
||||
core.current_prompt = json_data
|
||||
except Exception as e:
|
||||
print(f"[WARN] ComfyUI-Impact-Pack: Error on prompt - several features will not work.\n{e}")
|
||||
|
||||
return json_data
|
||||
|
||||
|
||||
PromptServer.instance.add_on_prompt_handler(onprompt)
|
||||
server.PromptServer.instance.add_on_prompt_handler(onprompt)
|
||||
|
||||
@@ -25,8 +25,6 @@ class MMDetLoader:
|
||||
|
||||
CATEGORY = "ImpactPack/Legacy"
|
||||
|
||||
DEPRECATED = True
|
||||
|
||||
def load_mmdet(self, model_name):
|
||||
mmdet_path = folder_paths.get_full_path("mmdets", model_name)
|
||||
model = mmdet_nodes.load_mmdet(mmdet_path)
|
||||
@@ -54,8 +52,6 @@ class BboxDetectorForEach:
|
||||
|
||||
CATEGORY = "ImpactPack/Legacy"
|
||||
|
||||
DEPRECATED = True
|
||||
|
||||
@staticmethod
|
||||
def detect(bbox_model, image, threshold, dilation, crop_factor, drop_size=1, detailer_hook=None):
|
||||
mmdet_results = mmdet_nodes.inference_bbox(bbox_model, image, threshold)
|
||||
@@ -106,8 +102,6 @@ class SegmDetectorCombined:
|
||||
|
||||
CATEGORY = "ImpactPack/Legacy"
|
||||
|
||||
DEPRECATED = True
|
||||
|
||||
def doit(self, segm_model, image, threshold, dilation):
|
||||
mmdet_results = mmdet_nodes.inference_segm(image, segm_model, threshold)
|
||||
segmasks = core.create_segmasks(mmdet_results)
|
||||
@@ -156,8 +150,6 @@ class SegmDetectorForEach:
|
||||
|
||||
CATEGORY = "ImpactPack/Legacy"
|
||||
|
||||
DEPRECATED = True
|
||||
|
||||
def doit(self, segm_model, image, threshold, dilation, crop_factor):
|
||||
mmdet_results = mmdet_nodes.inference_segm(image, segm_model, threshold)
|
||||
segmasks = core.create_segmasks(mmdet_results)
|
||||
@@ -198,8 +190,6 @@ class SegsMaskCombine:
|
||||
|
||||
CATEGORY = "ImpactPack/Legacy"
|
||||
|
||||
DEPRECATED = True
|
||||
|
||||
@staticmethod
|
||||
def combine(segs, image):
|
||||
h = image.shape[1]
|
||||
@@ -236,8 +226,6 @@ class MaskPainter(nodes.PreviewImage):
|
||||
|
||||
CATEGORY = "ImpactPack/Legacy"
|
||||
|
||||
DEPRECATED = True
|
||||
|
||||
def save_painted_images(self, images, filename_prefix="impact-mask",
|
||||
prompt=None, extra_pnginfo=None, mask_image=None, image=None):
|
||||
if image == "#placeholder" or image['image_hash'] != id(images):
|
||||
|
||||
+67
-119
@@ -2,13 +2,13 @@ import sys
|
||||
import time
|
||||
|
||||
import execution
|
||||
import folder_paths
|
||||
import impact.impact_server
|
||||
from server import PromptServer
|
||||
from impact.utils import any_typ
|
||||
import impact.core as core
|
||||
import re
|
||||
import nodes
|
||||
import traceback
|
||||
|
||||
|
||||
class ImpactCompare:
|
||||
@classmethod
|
||||
@@ -65,8 +65,8 @@ class ImpactConditionalBranch:
|
||||
return {
|
||||
"required": {
|
||||
"cond": ("BOOLEAN",),
|
||||
"tt_value": (any_typ,{"lazy": True}),
|
||||
"ff_value": (any_typ,{"lazy": True}),
|
||||
"tt_value": (any_typ,),
|
||||
"ff_value": (any_typ,),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -75,13 +75,7 @@ class ImpactConditionalBranch:
|
||||
|
||||
RETURN_TYPES = (any_typ, )
|
||||
|
||||
def check_lazy_status(self, cond, tt_value=None, ff_value=None):
|
||||
if cond and tt_value is None:
|
||||
return ["tt_value"]
|
||||
if not cond and ff_value is None:
|
||||
return ["ff_value"]
|
||||
|
||||
def doit(self, cond, tt_value=None, ff_value=None):
|
||||
def doit(self, cond, tt_value, ff_value):
|
||||
if cond:
|
||||
return (tt_value,)
|
||||
else:
|
||||
@@ -91,18 +85,11 @@ class ImpactConditionalBranch:
|
||||
class ImpactConditionalBranchSelMode:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
if not core.is_execution_model_version_supported():
|
||||
required_inputs = {
|
||||
return {
|
||||
"required": {
|
||||
"cond": ("BOOLEAN",),
|
||||
"sel_mode": ("BOOLEAN", {"default": True, "label_on": "select_on_prompt", "label_off": "select_on_execution"}),
|
||||
}
|
||||
else:
|
||||
required_inputs = {
|
||||
"cond": ("BOOLEAN",),
|
||||
}
|
||||
|
||||
return {
|
||||
"required": required_inputs,
|
||||
},
|
||||
"optional": {
|
||||
"tt_value": (any_typ,),
|
||||
"ff_value": (any_typ,),
|
||||
@@ -114,7 +101,7 @@ class ImpactConditionalBranchSelMode:
|
||||
|
||||
RETURN_TYPES = (any_typ, )
|
||||
|
||||
def doit(self, cond, tt_value=None, ff_value=None, **kwargs):
|
||||
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,)
|
||||
@@ -162,7 +149,7 @@ class ImpactIfNone:
|
||||
"optional": {"signal": (any_typ,), "any_input": (any_typ,), }
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ, "BOOLEAN")
|
||||
RETURN_TYPES = (any_typ, "BOOLEAN", )
|
||||
RETURN_NAMES = ("signal_opt", "bool")
|
||||
FUNCTION = "doit"
|
||||
|
||||
@@ -630,127 +617,88 @@ class ImpactControlBridge:
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"value": (any_typ,),
|
||||
"mode": ("BOOLEAN", {"default": True, "label_on": "Active", "label_off": "Stop/Mute/Bypass"}),
|
||||
"behavior": (["Stop", "Mute", "Bypass"], ),
|
||||
"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"}
|
||||
}
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Logic"
|
||||
CATEGORY = "ImpactPack/Logic/_for_test"
|
||||
RETURN_TYPES = (any_typ,)
|
||||
RETURN_NAMES = ("value",)
|
||||
OUTPUT_NODE = True
|
||||
|
||||
DESCRIPTION = ("When behavior is Stop and mode is active, the input value is passed directly to the output.\n"
|
||||
"When behavior is Mute/Bypass and mode is active, the node connected to the output is changed to active state.\n"
|
||||
"When behavior is Stop and mode is Stop/Mute/Bypass, the workflow execution of the current node is halted.\n"
|
||||
"When behavior is Mute/Bypass and mode is Stop/Mute/Bypass, the node connected to the output is changed to Mute/Bypass state.")
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(self, value, mode, behavior="Stop", unique_id=None, prompt=None, extra_pnginfo=None):
|
||||
if behavior == "Stop":
|
||||
return value, mode, behavior
|
||||
else:
|
||||
# NOTE: extra_pnginfo is not populated for IS_CHANGED.
|
||||
# so extra_pnginfo is useless in here
|
||||
try:
|
||||
workflow = core.current_prompt['extra_data']['extra_pnginfo']['workflow']
|
||||
except:
|
||||
print(f"[Impact Pack] core.current_prompt['extra_data']['extra_pnginfo']['workflow']")
|
||||
return 0
|
||||
def IS_CHANGED(self, value, mode, behavior=True, unique_id=None, prompt=None, extra_pnginfo=None):
|
||||
nodes, links = workflow_to_map(extra_pnginfo['workflow'])
|
||||
|
||||
nodes, links = workflow_to_map(workflow)
|
||||
next_nodes = []
|
||||
next_nodes = []
|
||||
|
||||
for link in nodes[unique_id]['outputs'][0]['links']:
|
||||
node_id = str(links[link][2])
|
||||
impact.utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)
|
||||
for link in nodes[unique_id]['outputs'][0]['links']:
|
||||
node_id = str(links[link][2])
|
||||
impact.utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)
|
||||
|
||||
return next_nodes
|
||||
|
||||
def doit(self, value, mode, behavior="Stop", unique_id=None, prompt=None, extra_pnginfo=None):
|
||||
|
||||
def doit(self, value, mode, behavior=True, unique_id=None, prompt=None, extra_pnginfo=None):
|
||||
global error_skip_flag
|
||||
|
||||
if core.is_execution_model_version_supported:
|
||||
from comfy_execution.graph import ExecutionBlocker
|
||||
nodes, links = workflow_to_map(extra_pnginfo['workflow'])
|
||||
|
||||
active_nodes = []
|
||||
mute_nodes = []
|
||||
bypass_nodes = []
|
||||
|
||||
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:
|
||||
# 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:
|
||||
print("[Impact Pack] ImpactControlBridge: ComfyUI is outdated. The 'Stop' behavior cannot function properly.")
|
||||
# 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.")
|
||||
|
||||
if behavior == "Stop":
|
||||
if mode:
|
||||
return (value, )
|
||||
else:
|
||||
return (ExecutionBlocker(None), )
|
||||
else:
|
||||
workflow_nodes, links = workflow_to_map(extra_pnginfo['workflow'])
|
||||
|
||||
active_nodes = []
|
||||
mute_nodes = []
|
||||
bypass_nodes = []
|
||||
|
||||
for link in workflow_nodes[unique_id]['outputs'][0]['links']:
|
||||
node_id = str(links[link][2])
|
||||
|
||||
next_nodes = []
|
||||
impact.utils.collect_non_reroute_nodes(workflow_nodes, links, next_nodes, node_id)
|
||||
|
||||
for next_node_id in next_nodes:
|
||||
node_mode = workflow_nodes[next_node_id]['mode']
|
||||
|
||||
if node_mode == 0:
|
||||
active_nodes.append(next_node_id)
|
||||
elif node_mode == 2:
|
||||
mute_nodes.append(next_node_id)
|
||||
elif node_mode == 4:
|
||||
bypass_nodes.append(next_node_id)
|
||||
|
||||
if mode:
|
||||
# active
|
||||
should_be_active_nodes = mute_nodes + bypass_nodes
|
||||
if len(should_be_active_nodes) > 0:
|
||||
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'actives': list(should_be_active_nodes)})
|
||||
nodes.interrupt_processing()
|
||||
|
||||
elif behavior == "Mute" or behavior == True:
|
||||
# mute
|
||||
should_be_mute_nodes = active_nodes + bypass_nodes
|
||||
if len(should_be_mute_nodes) > 0:
|
||||
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'mutes': list(should_be_mute_nodes)})
|
||||
nodes.interrupt_processing()
|
||||
|
||||
else:
|
||||
# bypass
|
||||
should_be_bypass_nodes = active_nodes + mute_nodes
|
||||
if len(should_be_bypass_nodes) > 0:
|
||||
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'bypasses': list(should_be_bypass_nodes)})
|
||||
nodes.interrupt_processing()
|
||||
|
||||
return (value, )
|
||||
|
||||
|
||||
class ImpactExecutionOrderController:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {"required": {
|
||||
"signal": (any_typ,),
|
||||
"value": (any_typ,),
|
||||
}}
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
RETURN_TYPES = (any_typ, any_typ)
|
||||
RETURN_NAMES = ("signal", "value")
|
||||
|
||||
def doit(self, signal, value):
|
||||
return signal, value
|
||||
return (value, )
|
||||
|
||||
|
||||
original_handle_execution = execution.PromptExecutor.handle_execution_error
|
||||
|
||||
|
||||
def handle_execution_error(**kwargs):
|
||||
print(f" handled")
|
||||
execution.PromptExecutor.handle_execution_error(**kwargs)
|
||||
|
||||
|
||||
+40
-293
@@ -5,13 +5,10 @@ import impact.impact_server
|
||||
from nodes import MAX_RESOLUTION
|
||||
|
||||
from impact.utils import *
|
||||
from . import core
|
||||
from .core import SEG
|
||||
import impact.core as core
|
||||
from impact.core import SEG
|
||||
import impact.utils as utils
|
||||
from . import defs
|
||||
from . import segs_upscaler
|
||||
from comfy.cli_args import args
|
||||
import math
|
||||
|
||||
|
||||
class SEGSDetailer:
|
||||
@@ -20,17 +17,17 @@ class SEGSDetailer:
|
||||
return {"required": {
|
||||
"image": ("IMAGE", ),
|
||||
"segs": ("SEGS", ),
|
||||
"guide_size": ("FLOAT", {"default": 512, "min": 64, "max": MAX_RESOLUTION, "step": 8}),
|
||||
"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": (core.SCHEDULERS,),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
|
||||
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
|
||||
"noise_mask": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"force_inpaint": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"force_inpaint": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"basic_pipe": ("BASIC_PIPE",),
|
||||
"refiner_ratio": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0}),
|
||||
"batch_size": ("INT", {"default": 1, "min": 1, "max": 100}),
|
||||
@@ -40,8 +37,7 @@ class SEGSDetailer:
|
||||
"optional": {
|
||||
"refiner_basic_pipe_opt": ("BASIC_PIPE",),
|
||||
"inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
"noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +52,7 @@ class SEGSDetailer:
|
||||
@staticmethod
|
||||
def do_detail(image, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, noise_mask, force_inpaint, basic_pipe, refiner_ratio=None, batch_size=1, cycle=1,
|
||||
refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=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:
|
||||
@@ -87,29 +83,13 @@ class SEGSDetailer:
|
||||
else:
|
||||
cropped_mask = None
|
||||
|
||||
cropped_positive = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in positive
|
||||
]
|
||||
|
||||
cropped_negative = [
|
||||
[condition, {
|
||||
k: core.crop_condition_mask(v, image, seg.crop_region) if k == "mask" else v
|
||||
for k, v in details.items()
|
||||
}]
|
||||
for condition, details in negative
|
||||
]
|
||||
|
||||
enhanced_image, cnet_pils = core.enhance_detail(cropped_image, model, clip, vae, guide_size, guide_size_for, max_size,
|
||||
seg.bbox, seed, steps, cfg, sampler_name, scheduler,
|
||||
cropped_positive, cropped_negative, denoise, cropped_mask, force_inpaint,
|
||||
positive, negative, denoise, cropped_mask, force_inpaint,
|
||||
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, cycle=cycle,
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func=scheduler_func_opt)
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
if cnet_pils is not None:
|
||||
cnet_pil_list.extend(cnet_pils)
|
||||
@@ -126,7 +106,7 @@ class SEGSDetailer:
|
||||
|
||||
def doit(self, image, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
|
||||
denoise, noise_mask, force_inpaint, basic_pipe, refiner_ratio=None, batch_size=1, cycle=1,
|
||||
refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0):
|
||||
|
||||
if len(image) > 1:
|
||||
raise Exception('[Impact Pack] ERROR: SEGSDetailer 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.')
|
||||
@@ -134,13 +114,13 @@ class SEGSDetailer:
|
||||
segs, cnet_pil_list = SEGSDetailer.do_detail(image, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name,
|
||||
scheduler, denoise, noise_mask, force_inpaint, basic_pipe, refiner_ratio, batch_size, cycle=cycle,
|
||||
refiner_basic_pipe_opt=refiner_basic_pipe_opt,
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
|
||||
|
||||
# set fallback image
|
||||
if len(cnet_pil_list) == 0:
|
||||
cnet_pil_list = [empty_pil_tensor()]
|
||||
|
||||
return segs, cnet_pil_list
|
||||
return (segs, cnet_pil_list)
|
||||
|
||||
|
||||
class SEGSPaste:
|
||||
@@ -196,11 +176,6 @@ class SEGSPaste:
|
||||
|
||||
mask = tensor_gaussian_blur_mask(mask, feather) * (alpha/255)
|
||||
x, y, *_ = seg.crop_region
|
||||
|
||||
# ensure same device
|
||||
mask = mask.to(image_i.device)
|
||||
ref_image = ref_image.to(image_i.device)
|
||||
|
||||
tensor_paste(image_i, ref_image, (x, y), mask)
|
||||
|
||||
if result is None:
|
||||
@@ -208,9 +183,6 @@ class SEGSPaste:
|
||||
else:
|
||||
result = torch.concat((result, image_i), dim=0)
|
||||
|
||||
if not args.highvram and not args.gpu_only:
|
||||
result = result.cpu()
|
||||
|
||||
return (result, )
|
||||
|
||||
|
||||
@@ -486,7 +458,7 @@ class SEGSOrderedFilter:
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"segs": ("SEGS", ),
|
||||
"target": (["area(=w*h)", "width", "height", "x1", "y1", "x2", "y2", "confidence"],),
|
||||
"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}),
|
||||
@@ -520,12 +492,8 @@ class SEGSOrderedFilter:
|
||||
value = x2
|
||||
elif target == "y1":
|
||||
value = y1
|
||||
elif target == "y2":
|
||||
value = y2
|
||||
elif target == "confidence":
|
||||
value = seg.confidence
|
||||
else:
|
||||
raise Exception(f"[Impact Pack] SEGSOrderedFilter - Unexpected target '{target}'")
|
||||
value = y2
|
||||
|
||||
segs_with_order.append((value, seg))
|
||||
|
||||
@@ -543,7 +511,7 @@ class SEGSOrderedFilter:
|
||||
else:
|
||||
remained_list.append(item[1])
|
||||
|
||||
return (segs[0], result_list), (segs[0], remained_list),
|
||||
return ((segs[0], result_list), (segs[0], remained_list), )
|
||||
|
||||
|
||||
class SEGSRangeFilter:
|
||||
@@ -551,7 +519,7 @@ class SEGSRangeFilter:
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"segs": ("SEGS", ),
|
||||
"target": (["area(=w*h)", "width", "height", "x1", "y1", "x2", "y2", "length_percent", "confidence(0-100)"],),
|
||||
"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}),
|
||||
@@ -591,12 +559,8 @@ class SEGSRangeFilter:
|
||||
value = x2
|
||||
elif target == "y1":
|
||||
value = y1
|
||||
elif target == "y2":
|
||||
value = y2
|
||||
elif target == "confidence(0-100)":
|
||||
value = seg.confidence*100
|
||||
else:
|
||||
raise Exception(f"[Impact Pack] SEGSRangeFilter - Unexpected target '{target}'")
|
||||
value = y2
|
||||
|
||||
if mode and min_value <= value <= max_value:
|
||||
print(f"[in] value={value} / {mode}, {min_value}, {max_value}")
|
||||
@@ -608,7 +572,7 @@ class SEGSRangeFilter:
|
||||
remained_segs.append(seg)
|
||||
print(f"[filter] value={value} / {mode}, {min_value}, {max_value}")
|
||||
|
||||
return (segs[0], new_segs), (segs[0], remained_segs),
|
||||
return ((segs[0], new_segs), (segs[0], remained_segs), )
|
||||
|
||||
|
||||
class SEGSToImageList:
|
||||
@@ -731,23 +695,6 @@ class SEGSConcat:
|
||||
return ((dim, res), )
|
||||
|
||||
|
||||
class Count_Elts_in_SEGS:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"segs": ("SEGS", ),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("INT",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, segs):
|
||||
return (len(segs[1]), )
|
||||
|
||||
|
||||
class DecomposeSEGS:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -808,44 +755,6 @@ class From_SEG_ELT:
|
||||
return (seg_elt, cropped_image, to_tensor(seg_elt.cropped_mask), seg_elt.crop_region, seg_elt.bbox, seg_elt.control_net_wrapper, seg_elt.confidence, seg_elt.label,)
|
||||
|
||||
|
||||
class From_SEG_ELT_bbox:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"bbox": ("SEG_ELT_bbox", ),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("INT", "INT", "INT", "INT")
|
||||
RETURN_NAMES = ("left", "top", "right", "bottom")
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, bbox):
|
||||
return bbox
|
||||
|
||||
|
||||
class From_SEG_ELT_crop_region:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"crop_region": ("SEG_ELT_crop_region", ),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("INT", "INT", "INT", "INT")
|
||||
RETURN_NAMES = ("left", "top", "right", "bottom")
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, crop_region):
|
||||
return crop_region
|
||||
|
||||
|
||||
class Edit_SEG_ELT:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -1170,11 +1079,10 @@ class MaskToSEGS:
|
||||
|
||||
CATEGORY = "ImpactPack/Operation"
|
||||
|
||||
@staticmethod
|
||||
def doit(mask, combined, crop_factor, bbox_fill, drop_size, contour_fill=False):
|
||||
def doit(self, mask, combined, crop_factor, bbox_fill, drop_size, contour_fill=False):
|
||||
mask = make_2d_mask(mask)
|
||||
result = core.mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size, is_contour=contour_fill)
|
||||
|
||||
result = core.mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size, is_contour=contour_fill)
|
||||
return (result, )
|
||||
|
||||
|
||||
@@ -1196,17 +1104,11 @@ class MaskToSEGS_for_AnimateDiff:
|
||||
|
||||
CATEGORY = "ImpactPack/Operation"
|
||||
|
||||
@staticmethod
|
||||
def doit(mask, combined, crop_factor, bbox_fill, drop_size, contour_fill=False):
|
||||
if (len(mask.shape) == 4 and mask.shape[1] > 1) or (len(mask.shape) == 3 and mask.shape[0] > 1):
|
||||
mask = make_3d_mask(mask)
|
||||
if contour_fill:
|
||||
print(f"[Impact Pack] MaskToSEGS_for_AnimateDiff: 'contour_fill' is ignored because batch mask 'contour_fill' is not supported.")
|
||||
result = core.batch_mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size)
|
||||
return (result, )
|
||||
|
||||
def doit(self, mask, combined, crop_factor, bbox_fill, drop_size, contour_fill=False):
|
||||
mask = make_2d_mask(mask)
|
||||
|
||||
segs = core.mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size, is_contour=contour_fill)
|
||||
|
||||
all_masks = SEGSToMaskList().doit(segs)[0]
|
||||
|
||||
result_mask = (all_masks[0] * 255).to(torch.uint8)
|
||||
@@ -1216,7 +1118,7 @@ class MaskToSEGS_for_AnimateDiff:
|
||||
result_mask = (result_mask/255.0).to(torch.float32)
|
||||
result_mask = utils.to_binary_mask(result_mask, 0.1)[0]
|
||||
|
||||
return MaskToSEGS.doit(result_mask, False, crop_factor, False, drop_size, contour_fill)
|
||||
return MaskToSEGS().doit(result_mask, False, crop_factor, False, drop_size, contour_fill)
|
||||
|
||||
|
||||
class IPAdapterApplySEGS:
|
||||
@@ -1235,11 +1137,7 @@ class IPAdapterApplySEGS:
|
||||
"weight_v2": ("FLOAT", {"default": 1.0, "min": -1, "max": 3, "step": 0.05}),
|
||||
"context_crop_factor": ("FLOAT", {"default": 1.2, "min": 1.0, "max": 100, "step": 0.1}),
|
||||
"reference_image": ("IMAGE",),
|
||||
},
|
||||
"optional": {
|
||||
"combine_embeds": (["concat", "add", "subtract", "average", "norm average"],),
|
||||
"neg_image": ("IMAGE",),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("SEGS",)
|
||||
@@ -1247,8 +1145,7 @@ class IPAdapterApplySEGS:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(segs, ipadapter_pipe, weight, noise, weight_type, start_at, end_at, unfold_batch, faceid_v2, weight_v2, context_crop_factor, reference_image, combine_embeds="concat", neg_image=None):
|
||||
def doit(self, segs, ipadapter_pipe, weight, noise, weight_type, start_at, end_at, unfold_batch, faceid_v2, weight_v2, context_crop_factor, reference_image):
|
||||
|
||||
if len(ipadapter_pipe) == 4:
|
||||
print(f"[Impact Pack] IPAdapterApplySEGS: Installed Inspire Pack is outdated.")
|
||||
@@ -1266,7 +1163,7 @@ class IPAdapterApplySEGS:
|
||||
context_crop_region = make_crop_region(w, h, seg.crop_region, context_crop_factor)
|
||||
cropped_image = crop_image(reference_image, context_crop_region)
|
||||
|
||||
control_net_wrapper = core.IPAdapterWrapper(ipadapter_pipe, weight, noise, weight_type, start_at, end_at, unfold_batch, weight_v2, cropped_image, neg_image=neg_image, prev_control_net=seg.control_net_wrapper, combine_embeds=combine_embeds)
|
||||
control_net_wrapper = core.IPAdapterWrapper(ipadapter_pipe, weight, noise, weight_type, start_at, end_at, unfold_batch, faceid_v2, weight_v2, cropped_image, prev_control_net=seg.control_net_wrapper)
|
||||
new_seg = SEG(seg.cropped_image, seg.cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, control_net_wrapper)
|
||||
new_segs.append(new_seg)
|
||||
|
||||
@@ -1292,8 +1189,7 @@ class ControlNetApplySEGS:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(segs, control_net, strength, segs_preprocessor=None, control_image=None):
|
||||
def doit(self, segs, control_net, strength, segs_preprocessor=None, control_image=None):
|
||||
new_segs = []
|
||||
|
||||
for seg in segs[1]:
|
||||
@@ -1326,8 +1222,7 @@ class ControlNetApplyAdvancedSEGS:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(segs, control_net, strength, start_percent, end_percent, segs_preprocessor=None, control_image=None):
|
||||
def doit(self, segs, control_net, strength, start_percent, end_percent, segs_preprocessor=None, control_image=None):
|
||||
new_segs = []
|
||||
|
||||
for seg in segs[1]:
|
||||
@@ -1350,8 +1245,7 @@ class ControlNetClearSEGS:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(segs):
|
||||
def doit(self, segs):
|
||||
new_segs = []
|
||||
|
||||
for seg in segs[1]:
|
||||
@@ -1409,8 +1303,7 @@ class SEGSPicker:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(picks, segs, fallback_image_opt=None, unique_id=None):
|
||||
def doit(self, picks, segs, fallback_image_opt=None, unique_id=None):
|
||||
if fallback_image_opt is not None:
|
||||
segs = core.segs_scale_match(segs, fallback_image_opt.shape)
|
||||
|
||||
@@ -1425,7 +1318,7 @@ class SEGSPicker:
|
||||
else:
|
||||
cropped_image = empty_pil_tensor()
|
||||
|
||||
mask_array = seg.cropped_mask.copy()
|
||||
mask_array = seg.cropped_mask
|
||||
mask_array[mask_array < 0.3] = 0.3
|
||||
mask_array = mask_array[None, ..., None]
|
||||
cropped_image = cropped_image * mask_array
|
||||
@@ -1465,8 +1358,7 @@ class DefaultImageForSEGS:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(segs, image, override):
|
||||
def doit(self, segs, image, override):
|
||||
results = []
|
||||
|
||||
segs = core.segs_scale_match(segs, image.shape)
|
||||
@@ -1510,8 +1402,7 @@ class RemoveImageFromSEGS:
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(segs):
|
||||
def doit(self, segs):
|
||||
results = []
|
||||
|
||||
if len(segs[1]) > 0:
|
||||
@@ -1530,7 +1421,7 @@ class MakeTileSEGS:
|
||||
return {"required": {
|
||||
"images": ("IMAGE", ),
|
||||
"bbox_size": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 8}),
|
||||
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 10, "step": 0.01}),
|
||||
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 10, "step": 0.1}),
|
||||
"min_overlap": ("INT", {"default": 5, "min": 0, "max": 512, "step": 1}),
|
||||
"filter_segs_dilation": ("INT", {"default": 20, "min": -255, "max": 255, "step": 1}),
|
||||
"mask_irregularity": ("FLOAT", {"default": 0, "min": 0, "max": 1.0, "step": 0.01}),
|
||||
@@ -1548,10 +1439,9 @@ class MakeTileSEGS:
|
||||
|
||||
CATEGORY = "ImpactPack/__for_testing"
|
||||
|
||||
@staticmethod
|
||||
def doit(images, bbox_size, crop_factor, min_overlap, filter_segs_dilation, mask_irregularity=0, irregular_mask_mode="Reuse fast", filter_in_segs_opt=None, filter_out_segs_opt=None):
|
||||
def doit(self, images, bbox_size, crop_factor, min_overlap, filter_segs_dilation, mask_irregularity=0, irregular_mask_mode="Reuse fast", filter_in_segs_opt=None, filter_out_segs_opt=None):
|
||||
if bbox_size <= 2*min_overlap:
|
||||
new_min_overlap = bbox_size / 2
|
||||
new_min_overlap = 2 / bbox_size
|
||||
print(f"[MakeTileSEGS] min_overlap should be greater than bbox_size. (value changed: {min_overlap} => {new_min_overlap})")
|
||||
min_overlap = new_min_overlap
|
||||
|
||||
@@ -1571,12 +1461,6 @@ class MakeTileSEGS:
|
||||
elif irregular_mask_mode == "All random fast":
|
||||
mask_quality = 512
|
||||
|
||||
# compensate overlap/bbox_size for irregular mask
|
||||
if mask_irregularity > 0:
|
||||
compensate = max(6, int(mask_quality * mask_irregularity / 4))
|
||||
min_overlap += compensate
|
||||
bbox_size += compensate*2
|
||||
|
||||
# create exclusion mask
|
||||
if filter_out_segs_opt is not None:
|
||||
exclusion_mask = core.segs_to_combined_mask(filter_out_segs_opt)
|
||||
@@ -1594,7 +1478,7 @@ class MakeTileSEGS:
|
||||
|
||||
a, b = core.mask_to_segs(and_mask, True, 1.0, False, 0)
|
||||
if len(b) == 0:
|
||||
return ((a, b),)
|
||||
return a, b
|
||||
|
||||
start_x, start_y, c, d = b[0].crop_region
|
||||
w = c - start_x
|
||||
@@ -1611,8 +1495,8 @@ class MakeTileSEGS:
|
||||
print(f"[MaskTileSEGS] bbox_size is greater than resolution (value changed: {bbox_size} => {new_bbox_size}")
|
||||
bbox_size = new_bbox_size
|
||||
|
||||
n_horizontal = math.ceil(w / (bbox_size - min_overlap))
|
||||
n_vertical = math.ceil(h / (bbox_size - min_overlap))
|
||||
n_horizontal = int(w / (bbox_size - min_overlap))
|
||||
n_vertical = int(h / (bbox_size - min_overlap))
|
||||
|
||||
w_overlap_sum = (bbox_size * n_horizontal) - w
|
||||
if w_overlap_sum < 0:
|
||||
@@ -1630,12 +1514,6 @@ class MakeTileSEGS:
|
||||
|
||||
new_segs = []
|
||||
|
||||
if w_overlap_size == bbox_size:
|
||||
n_horizontal = 1
|
||||
|
||||
if h_overlap_size == bbox_size:
|
||||
n_vertical = 1
|
||||
|
||||
y = start_y
|
||||
for j in range(0, n_vertical):
|
||||
x = start_x
|
||||
@@ -1712,134 +1590,3 @@ class MakeTileSEGS:
|
||||
|
||||
res = (ih, iw), new_segs # segs
|
||||
return (res,)
|
||||
|
||||
|
||||
class SEGSUpscaler:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
resampling_methods = ["lanczos", "nearest", "bilinear", "bicubic"]
|
||||
|
||||
return {"required": {
|
||||
"image": ("IMAGE",),
|
||||
"segs": ("SEGS",),
|
||||
"model": ("MODEL",),
|
||||
"clip": ("CLIP",),
|
||||
"vae": ("VAE",),
|
||||
"rescale_factor": ("FLOAT", {"default": 2, "min": 0.01, "max": 100.0, "step": 0.01}),
|
||||
"resampling_method": (resampling_methods,),
|
||||
"supersample": (["true", "false"],),
|
||||
"rounding_modulus": ("INT", {"default": 8, "min": 8, "max": 1024, "step": 8}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
|
||||
"scheduler": (core.SCHEDULERS,),
|
||||
"positive": ("CONDITIONING",),
|
||||
"negative": ("CONDITIONING",),
|
||||
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
|
||||
"feather": ("INT", {"default": 5, "min": 0, "max": 100, "step": 1}),
|
||||
"inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
},
|
||||
"optional": {
|
||||
"upscale_model_opt": ("UPSCALE_MODEL",),
|
||||
"upscaler_hook_opt": ("UPSCALER_HOOK",),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Upscale"
|
||||
|
||||
@staticmethod
|
||||
def doit(image, segs, model, clip, vae, rescale_factor, resampling_method, supersample, rounding_modulus,
|
||||
seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, feather, inpaint_model, noise_mask_feather,
|
||||
upscale_model_opt=None, upscaler_hook_opt=None, scheduler_func_opt=None):
|
||||
|
||||
new_image = segs_upscaler.upscaler(image, upscale_model_opt, rescale_factor, resampling_method, supersample, rounding_modulus)
|
||||
|
||||
segs = core.segs_scale_match(segs, new_image.shape)
|
||||
|
||||
ordered_segs = segs[1]
|
||||
|
||||
for i, seg in enumerate(ordered_segs):
|
||||
cropped_image = crop_ndarray4(new_image.numpy(), seg.crop_region)
|
||||
cropped_image = to_tensor(cropped_image)
|
||||
mask = to_tensor(seg.cropped_mask)
|
||||
mask = tensor_gaussian_blur_mask(mask, feather)
|
||||
|
||||
is_mask_all_zeros = (seg.cropped_mask == 0).all().item()
|
||||
if is_mask_all_zeros:
|
||||
print(f"SEGSUpscaler: segment skip [empty mask]")
|
||||
continue
|
||||
|
||||
cropped_mask = seg.cropped_mask
|
||||
|
||||
seg_seed = seed + i
|
||||
|
||||
enhanced_image = segs_upscaler.img2img_segs(cropped_image, model, clip, vae, seg_seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, denoise,
|
||||
noise_mask=cropped_mask, control_net_wrapper=seg.control_net_wrapper,
|
||||
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather, scheduler_func_opt=scheduler_func_opt)
|
||||
if not (enhanced_image is None):
|
||||
new_image = new_image.cpu()
|
||||
enhanced_image = enhanced_image.cpu()
|
||||
left = seg.crop_region[0]
|
||||
top = seg.crop_region[1]
|
||||
tensor_paste(new_image, enhanced_image, (left, top), mask)
|
||||
|
||||
if upscaler_hook_opt is not None:
|
||||
new_image = upscaler_hook_opt.post_paste(new_image)
|
||||
|
||||
enhanced_img = tensor_convert_rgb(new_image)
|
||||
|
||||
return (enhanced_img,)
|
||||
|
||||
|
||||
class SEGSUpscalerPipe:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
resampling_methods = ["lanczos", "nearest", "bilinear", "bicubic"]
|
||||
|
||||
return {"required": {
|
||||
"image": ("IMAGE",),
|
||||
"segs": ("SEGS",),
|
||||
"basic_pipe": ("BASIC_PIPE",),
|
||||
"rescale_factor": ("FLOAT", {"default": 2, "min": 0.01, "max": 100.0, "step": 0.01}),
|
||||
"resampling_method": (resampling_methods,),
|
||||
"supersample": (["true", "false"],),
|
||||
"rounding_modulus": ("INT", {"default": 8, "min": 8, "max": 1024, "step": 8}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
|
||||
"scheduler": (core.SCHEDULERS,),
|
||||
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
|
||||
"feather": ("INT", {"default": 5, "min": 0, "max": 100, "step": 1}),
|
||||
"inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"noise_mask_feather": ("INT", {"default": 20, "min": 0, "max": 100, "step": 1}),
|
||||
},
|
||||
"optional": {
|
||||
"upscale_model_opt": ("UPSCALE_MODEL",),
|
||||
"upscaler_hook_opt": ("UPSCALER_HOOK",),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC",),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Upscale"
|
||||
|
||||
@staticmethod
|
||||
def doit(image, segs, basic_pipe, rescale_factor, resampling_method, supersample, rounding_modulus,
|
||||
seed, steps, cfg, sampler_name, scheduler, denoise, feather, inpaint_model, noise_mask_feather,
|
||||
upscale_model_opt=None, upscaler_hook_opt=None, scheduler_func_opt=None):
|
||||
|
||||
model, clip, vae, positive, negative = basic_pipe
|
||||
|
||||
return SEGSUpscaler.doit(image, segs, model, clip, vae, rescale_factor, resampling_method, supersample, rounding_modulus,
|
||||
seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, feather, inpaint_model, noise_mask_feather,
|
||||
upscale_model_opt=upscale_model_opt, upscaler_hook_opt=upscaler_hook_opt, scheduler_func_opt=scheduler_func_opt)
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
from impact.utils import *
|
||||
from impact import impact_sampling
|
||||
from comfy import model_management
|
||||
from comfy.cli_args import args
|
||||
import nodes
|
||||
|
||||
try:
|
||||
from comfy_extras import nodes_differential_diffusion
|
||||
except Exception:
|
||||
print(f"[Impact Pack] ComfyUI is an outdated version. The DifferentialDiffusion feature will be disabled.")
|
||||
|
||||
|
||||
# Implementation based on `https://github.com/lingondricka2/Upscaler-Detailer`
|
||||
|
||||
# code from comfyroll --->
|
||||
# https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/blob/main/nodes/functions_upscale.py
|
||||
|
||||
def upscale_with_model(upscale_model, image):
|
||||
device = model_management.get_torch_device()
|
||||
upscale_model.to(device)
|
||||
in_img = image.movedim(-1, -3).to(device)
|
||||
free_memory = model_management.get_free_memory(device)
|
||||
|
||||
tile = 512
|
||||
overlap = 32
|
||||
|
||||
oom = True
|
||||
while oom:
|
||||
try:
|
||||
steps = in_img.shape[0] * comfy.utils.get_tiled_scale_steps(in_img.shape[3], in_img.shape[2], tile_x=tile, tile_y=tile, overlap=overlap)
|
||||
pbar = comfy.utils.ProgressBar(steps)
|
||||
s = comfy.utils.tiled_scale(in_img, lambda a: upscale_model(a), tile_x=tile, tile_y=tile, overlap=overlap, upscale_amount=upscale_model.scale, pbar=pbar)
|
||||
oom = False
|
||||
except model_management.OOM_EXCEPTION as e:
|
||||
tile //= 2
|
||||
if tile < 128:
|
||||
raise e
|
||||
|
||||
s = torch.clamp(s.movedim(-3, -1), min=0, max=1.0)
|
||||
return s
|
||||
|
||||
|
||||
def apply_resize_image(image: Image.Image, original_width, original_height, rounding_modulus, mode='scale', supersample='true', factor: int = 2, width: int = 1024, height: int = 1024,
|
||||
resample='bicubic'):
|
||||
# Calculate the new width and height based on the given mode and parameters
|
||||
if mode == 'rescale':
|
||||
new_width, new_height = int(original_width * factor), int(original_height * factor)
|
||||
else:
|
||||
m = rounding_modulus
|
||||
original_ratio = original_height / original_width
|
||||
height = int(width * original_ratio)
|
||||
|
||||
new_width = width if width % m == 0 else width + (m - width % m)
|
||||
new_height = height if height % m == 0 else height + (m - height % m)
|
||||
|
||||
# Define a dictionary of resampling filters
|
||||
resample_filters = {'nearest': 0, 'bilinear': 2, 'bicubic': 3, 'lanczos': 1}
|
||||
|
||||
# Apply supersample
|
||||
if supersample == 'true':
|
||||
image = image.resize((new_width * 8, new_height * 8), resample=Image.Resampling(resample_filters[resample]))
|
||||
|
||||
# Resize the image using the given resampling filter
|
||||
resized_image = image.resize((new_width, new_height), resample=Image.Resampling(resample_filters[resample]))
|
||||
|
||||
return resized_image
|
||||
|
||||
|
||||
def upscaler(image, upscale_model, rescale_factor, resampling_method, supersample, rounding_modulus):
|
||||
if upscale_model is not None:
|
||||
up_image = upscale_with_model(upscale_model, image)
|
||||
else:
|
||||
up_image = image
|
||||
|
||||
pil_img = tensor2pil(image)
|
||||
original_width, original_height = pil_img.size
|
||||
scaled_image = pil2tensor(apply_resize_image(tensor2pil(up_image), original_width, original_height, rounding_modulus, 'rescale',
|
||||
supersample, rescale_factor, 1024, resampling_method))
|
||||
return scaled_image
|
||||
|
||||
# <---
|
||||
|
||||
|
||||
def img2img_segs(image, model, clip, vae, seed, steps, cfg, sampler_name, scheduler,
|
||||
positive, negative, denoise, noise_mask, control_net_wrapper=None,
|
||||
inpaint_model=False, noise_mask_feather=0, scheduler_func_opt=None):
|
||||
|
||||
original_image_size = image.shape[1:3]
|
||||
|
||||
# Match to original image size
|
||||
if original_image_size[0] % 8 > 0 or original_image_size[1] % 8 > 0:
|
||||
scale = 8/min(original_image_size[0], original_image_size[1]) + 1
|
||||
w = int(original_image_size[1] * scale)
|
||||
h = int(original_image_size[0] * scale)
|
||||
image = tensor_resize(image, w, h)
|
||||
|
||||
if noise_mask is not None:
|
||||
noise_mask = tensor_gaussian_blur_mask(noise_mask, noise_mask_feather)
|
||||
noise_mask = noise_mask.squeeze(3)
|
||||
|
||||
if noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
|
||||
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]
|
||||
|
||||
if control_net_wrapper is not None:
|
||||
positive, negative, _ = control_net_wrapper.apply(positive, negative, image, noise_mask)
|
||||
|
||||
# prepare mask
|
||||
if noise_mask is not None and inpaint_model:
|
||||
positive, negative, latent_image = nodes.InpaintModelConditioning().encode(positive, negative, image, vae, noise_mask)
|
||||
else:
|
||||
latent_image = to_latent_image(image, vae)
|
||||
if noise_mask is not None:
|
||||
latent_image['noise_mask'] = noise_mask
|
||||
|
||||
refined_latent = latent_image
|
||||
|
||||
# ksampler
|
||||
refined_latent = impact_sampling.ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, refined_latent, denoise, scheduler_func=scheduler_func_opt)
|
||||
|
||||
# non-latent downscale - latent downscale cause bad quality
|
||||
refined_image = vae.decode(refined_latent['samples'])
|
||||
|
||||
# prevent mixing of device
|
||||
refined_image = refined_image.cpu()
|
||||
|
||||
# Match to original image size
|
||||
if refined_image.shape[1:3] != original_image_size:
|
||||
refined_image = tensor_resize(refined_image, original_image_size[1], original_image_size[0])
|
||||
|
||||
# don't convert to latent - latent break image
|
||||
# preserving pil is much better
|
||||
return refined_image
|
||||
+167
-252
@@ -1,37 +1,33 @@
|
||||
import math
|
||||
import impact.core as core
|
||||
from comfy_extras.nodes_custom_sampler import Noise_RandomNoise
|
||||
from impact.utils import *
|
||||
from nodes import MAX_RESOLUTION
|
||||
import nodes
|
||||
from impact.impact_sampling import KSamplerWrapper, KSamplerAdvancedWrapper, separated_sample, impact_sample
|
||||
import comfy
|
||||
from impact.impact_sampling import KSamplerWrapper, KSamplerAdvancedWrapper
|
||||
|
||||
|
||||
class TiledKSamplerProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "tooltip": "classifier free guidance value"}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "sampler"}),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, {"tooltip": "noise schedule"}),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
|
||||
"tile_width": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64, "tooltip": "Sets the width of the tile to be used in TiledKSampler."}),
|
||||
"tile_height": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64, "tooltip": "Sets the height of the tile to be used in TiledKSampler."}),
|
||||
"tiling_strategy": (["random", "padded", 'simple'], {"tooltip": "Sets the tiling strategy for TiledKSampler."} ),
|
||||
"basic_pipe": ("BASIC_PIPE", {"tooltip": "basic_pipe input for sampling"})
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"tile_width": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64}),
|
||||
"tile_height": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64}),
|
||||
"tiling_strategy": (["random", "padded", 'simple'], ),
|
||||
"basic_pipe": ("BASIC_PIPE", )
|
||||
}}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
|
||||
|
||||
RETURN_TYPES = ("KSAMPLER",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Sampler"
|
||||
|
||||
@staticmethod
|
||||
def doit(seed, steps, cfg, sampler_name, scheduler, denoise,
|
||||
def doit(self, seed, steps, cfg, sampler_name, scheduler, denoise,
|
||||
tile_width, tile_height, tiling_strategy, basic_pipe):
|
||||
model, _, _, positive, negative = basic_pipe
|
||||
sampler = core.TiledKSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise,
|
||||
@@ -43,30 +39,24 @@ class KSamplerProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "tooltip": "classifier free guidance value"}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "sampler"}),
|
||||
"scheduler": (core.SCHEDULERS, {"tooltip": "noise schedule"}),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
|
||||
"basic_pipe": ("BASIC_PIPE", {"tooltip": "basic_pipe input for sampling"})
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"basic_pipe": ("BASIC_PIPE", )
|
||||
},
|
||||
"optional": {
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
|
||||
}
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)",)
|
||||
|
||||
RETURN_TYPES = ("KSAMPLER",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Sampler"
|
||||
|
||||
@staticmethod
|
||||
def doit(seed, steps, cfg, sampler_name, scheduler, denoise, basic_pipe, scheduler_func_opt=None):
|
||||
def doit(self, seed, steps, cfg, sampler_name, scheduler, denoise, basic_pipe):
|
||||
model, _, _, positive, negative = basic_pipe
|
||||
sampler = KSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise, scheduler_func=scheduler_func_opt)
|
||||
sampler = KSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise)
|
||||
return (sampler, )
|
||||
|
||||
|
||||
@@ -74,29 +64,25 @@ class KSamplerAdvancedProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "toolip": "classifier free guidance value"}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"toolip": "sampler"}),
|
||||
"scheduler": (core.SCHEDULERS, {"toolip": "noise schedule"}),
|
||||
"sigma_factor": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01, "toolip": "Multiplier of noise schedule"}),
|
||||
"basic_pipe": ("BASIC_PIPE", {"toolip": "basic_pipe input for sampling"})
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"sigma_factor": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}),
|
||||
"basic_pipe": ("BASIC_PIPE", )
|
||||
},
|
||||
"optional": {
|
||||
"sampler_opt": ("SAMPLER", {"toolip": "[OPTIONAL] Uses the passed sampler instead of internal impact_sampler."}),
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC", {"toolip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
|
||||
"sampler_opt": ("SAMPLER", )
|
||||
}
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("sampler wrapper. (Can be used when generating a regional_prompt.)", )
|
||||
|
||||
RETURN_TYPES = ("KSAMPLER_ADVANCED",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Sampler"
|
||||
|
||||
@staticmethod
|
||||
def doit(cfg, sampler_name, scheduler, basic_pipe, sigma_factor=1.0, sampler_opt=None, scheduler_func_opt=None):
|
||||
def doit(self, cfg, sampler_name, scheduler, basic_pipe, sigma_factor=1.0, sampler_opt=None):
|
||||
model, _, _, positive, negative = basic_pipe
|
||||
sampler = KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=sampler_opt, sigma_factor=sigma_factor, scheduler_func=scheduler_func_opt)
|
||||
sampler = KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=sampler_opt, sigma_factor=sigma_factor)
|
||||
return (sampler, )
|
||||
|
||||
|
||||
@@ -104,22 +90,19 @@ class TwoSamplersForMask:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"latent_image": ("LATENT", {"tooltip": "input latent image"}),
|
||||
"base_sampler": ("KSAMPLER", {"tooltip": "Sampler to apply to the region outside the mask."}),
|
||||
"mask_sampler": ("KSAMPLER", {"tooltip": "Sampler to apply to the masked region."}),
|
||||
"mask": ("MASK", {"tooltip": "region mask"})
|
||||
"latent_image": ("LATENT", ),
|
||||
"base_sampler": ("KSAMPLER", ),
|
||||
"mask_sampler": ("KSAMPLER", ),
|
||||
"mask": ("MASK", )
|
||||
},
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("result latent", )
|
||||
|
||||
RETURN_TYPES = ("LATENT", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Sampler"
|
||||
|
||||
@staticmethod
|
||||
def doit(latent_image, base_sampler, mask_sampler, mask):
|
||||
def doit(self, latent_image, base_sampler, mask_sampler, mask):
|
||||
inv_mask = torch.where(mask != 1.0, torch.tensor(1.0), torch.tensor(0.0))
|
||||
|
||||
latent_image['noise_mask'] = inv_mask
|
||||
@@ -137,59 +120,82 @@ class TwoAdvancedSamplersForMask:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
|
||||
"samples": ("LATENT", {"tooltip": "input latent image"}),
|
||||
"base_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "Sampler to apply to the region outside the mask."}),
|
||||
"mask_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "Sampler to apply to the masked region."}),
|
||||
"mask": ("MASK", {"tooltip": "region mask"}),
|
||||
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000, "tooltip": "To smooth the seams of the region boundaries, expand the mask by the overlap_factor amount to overlap with other regions."})
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"samples": ("LATENT", ),
|
||||
"base_sampler": ("KSAMPLER_ADVANCED", ),
|
||||
"mask_sampler": ("KSAMPLER_ADVANCED", ),
|
||||
"mask": ("MASK", ),
|
||||
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000})
|
||||
},
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("result latent", )
|
||||
|
||||
RETURN_TYPES = ("LATENT", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Sampler"
|
||||
|
||||
@staticmethod
|
||||
def doit(seed, steps, denoise, samples, base_sampler, mask_sampler, mask, overlap_factor):
|
||||
regional_prompts = RegionalPrompt().doit(mask=mask, advanced_sampler=mask_sampler)[0]
|
||||
def mask_erosion(samples, mask, grow_mask_by):
|
||||
mask = mask.clone()
|
||||
|
||||
return RegionalSampler().doit(seed=seed, seed_2nd=0, seed_2nd_mode="ignore", steps=steps, base_only_steps=1,
|
||||
denoise=denoise, samples=samples, base_sampler=base_sampler,
|
||||
regional_prompts=regional_prompts, overlap_factor=overlap_factor,
|
||||
restore_latent=True, additional_mode="ratio between",
|
||||
additional_sampler="AUTO", additional_sigma_ratio=0.3)
|
||||
w = samples['samples'].shape[3]
|
||||
h = samples['samples'].shape[2]
|
||||
|
||||
mask2 = torch.nn.functional.interpolate(mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])), size=(w, h), mode="bilinear")
|
||||
if grow_mask_by == 0:
|
||||
mask_erosion = mask2
|
||||
else:
|
||||
kernel_tensor = torch.ones((1, 1, grow_mask_by, grow_mask_by))
|
||||
padding = math.ceil((grow_mask_by - 1) / 2)
|
||||
|
||||
mask_erosion = torch.clamp(torch.nn.functional.conv2d(mask2.round(), kernel_tensor, padding=padding), 0, 1)
|
||||
|
||||
return mask_erosion[:, :, :w, :h].round()
|
||||
|
||||
def doit(self, seed, steps, denoise, samples, base_sampler, mask_sampler, mask, overlap_factor):
|
||||
|
||||
inv_mask = torch.where(mask != 1.0, torch.tensor(1.0), torch.tensor(0.0))
|
||||
|
||||
adv_steps = int(steps / denoise)
|
||||
start_at_step = adv_steps - steps
|
||||
|
||||
new_latent_image = samples.copy()
|
||||
|
||||
mask_erosion = TwoAdvancedSamplersForMask.mask_erosion(samples, mask, overlap_factor)
|
||||
|
||||
for i in range(start_at_step, adv_steps):
|
||||
add_noise = "enable" if i == start_at_step else "disable"
|
||||
return_with_leftover_noise = "enable" if i+1 != adv_steps else "disable"
|
||||
|
||||
new_latent_image['noise_mask'] = inv_mask
|
||||
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image, i, i + 1, "enable", recovery_mode="ratio additional")
|
||||
|
||||
new_latent_image['noise_mask'] = mask_erosion
|
||||
new_latent_image = mask_sampler.sample_advanced("disable", seed, adv_steps, new_latent_image, i, i + 1, return_with_leftover_noise, recovery_mode="ratio additional")
|
||||
|
||||
del new_latent_image['noise_mask']
|
||||
|
||||
return (new_latent_image, )
|
||||
|
||||
|
||||
class RegionalPrompt:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"mask": ("MASK", {"tooltip": "region mask"}),
|
||||
"advanced_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "sampler for specified region"}),
|
||||
},
|
||||
"optional": {
|
||||
"variation_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Sets the extra seed to be used for noise variation."}),
|
||||
"variation_strength": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Sets the strength of the noise variation."}),
|
||||
"variation_method": (["linear", "slerp"], {"tooltip": "Sets how the original noise and extra noise are blended together."}),
|
||||
}
|
||||
"mask": ("MASK", ),
|
||||
"advanced_sampler": ("KSAMPLER_ADVANCED", ),
|
||||
},
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("regional prompts. (Can be used in the RegionalSampler.)", )
|
||||
|
||||
RETURN_TYPES = ("REGIONAL_PROMPTS", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Regional"
|
||||
|
||||
@staticmethod
|
||||
def doit(mask, advanced_sampler, variation_seed=0, variation_strength=0.0, variation_method="linear"):
|
||||
regional_prompt = core.REGIONAL_PROMPT(mask, advanced_sampler, variation_seed=variation_seed, variation_strength=variation_strength, variation_method=variation_method)
|
||||
def doit(self, mask, advanced_sampler):
|
||||
regional_prompt = core.REGIONAL_PROMPT(mask, advanced_sampler)
|
||||
return ([regional_prompt], )
|
||||
|
||||
|
||||
@@ -197,19 +203,16 @@ class CombineRegionalPrompts:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"regional_prompts1": ("REGIONAL_PROMPTS", {"tooltip": "input regional_prompts. (Connecting to the input slot increases the number of additional slots.)"}),
|
||||
"regional_prompts1": ("REGIONAL_PROMPTS", ),
|
||||
},
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("Combined REGIONAL_PROMPTS", )
|
||||
|
||||
RETURN_TYPES = ("REGIONAL_PROMPTS", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Regional"
|
||||
|
||||
@staticmethod
|
||||
def doit(**kwargs):
|
||||
def doit(self, **kwargs):
|
||||
res = []
|
||||
for k, v in kwargs.items():
|
||||
res += v
|
||||
@@ -221,19 +224,16 @@ class CombineConditionings:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"conditioning1": ("CONDITIONING", { "tooltip": "input conditionings. (Connecting to the input slot increases the number of additional slots.)" }),
|
||||
"conditioning1": ("CONDITIONING", ),
|
||||
},
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("Combined conditioning", )
|
||||
|
||||
RETURN_TYPES = ("CONDITIONING", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(**kwargs):
|
||||
def doit(self, **kwargs):
|
||||
res = []
|
||||
for k, v in kwargs.items():
|
||||
res += v
|
||||
@@ -245,19 +245,16 @@ class ConcatConditionings:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"conditioning1": ("CONDITIONING", { "tooltip": "input conditionings. (Connecting to the input slot increases the number of additional slots.)" }),
|
||||
"conditioning1": ("CONDITIONING", ),
|
||||
},
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("Concatenated conditioning", )
|
||||
|
||||
RETURN_TYPES = ("CONDITIONING", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
@staticmethod
|
||||
def doit(**kwargs):
|
||||
def doit(self, **kwargs):
|
||||
conditioning_to = list(kwargs.values())[0]
|
||||
|
||||
for k, conditioning_from in list(kwargs.items())[1:]:
|
||||
@@ -282,35 +279,29 @@ class RegionalSampler:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
|
||||
"seed_2nd": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Additional noise seed. The behavior is determined by seed_2nd_mode."}),
|
||||
"seed_2nd_mode": (["ignore", "fixed", "seed+seed_2nd", "seed-seed_2nd", "increment", "decrement", "randomize"], {"tooltip": "application method of seed_2nd. 1) ignore: Do not use seed_2nd. In the base only sampling stage, the seed is applied as a noise seed, and in the regional sampling stage, denoising is performed as it is without additional noise. 2) Others: In the base only sampling stage, the seed is applied as a noise seed, and once it is closed so that there is no leftover noise, new noise is added with seed_2nd and the regional samping stage is performed. a) fixed: Use seed_2nd as it is as an additional noise seed. b) seed+seed_2nd: Apply the value of seed+seed_2nd as an additional noise seed. c) seed-seed_2nd: Apply the value of seed-seed_2nd as an additional noise seed. d) increment: Not implemented yet. Same with fixed. e) decrement: Not implemented yet. Same with fixed. f) randomize: Not implemented yet. Same with fixed."}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
|
||||
"base_only_steps": ("INT", {"default": 2, "min": 0, "max": 10000, "tooltip": "total sampling steps"}),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
|
||||
"samples": ("LATENT", {"tooltip": "input latent image"}),
|
||||
"base_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "The sampler applied outside the area set by the regional_prompt."}),
|
||||
"regional_prompts": ("REGIONAL_PROMPTS", {"tooltip": "The prompt applied to each region"}),
|
||||
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000, "tooltip": "To smooth the seams of the region boundaries, expand the mask set in regional_prompts by the overlap_factor amount to overlap with other regions."}),
|
||||
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled", "tooltip": "At each step, restore the noise outside the mask area to its original state, as per the principle of inpainting. This option is provided for backward compatibility, and it is recommended to always set it to true."}),
|
||||
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between", "tooltip": "..._sde or uni_pc and other special samplers are used, the region is not properly denoised, and it causes a phenomenon that destroys the overall harmony. To compensate for this, a recovery operation is performed using another sampler. This requires a longer time for sampling because a second sampling is performed at each step in each region using a special sampler. 1) DISABLE: Disable this feature. 2) ratio additional: After performing the denoise amount to be performed in the step with the sampler set in the region, the recovery sampler is additionally applied by the additional_sigma_ratio. If you use this option, the total denoise amount increases by additional_sigma_ratio. 3) ratio between: The denoise amount to be performed in the step with the sampler set in the region and the denoise amount to be applied to the recovery sampler are divided by additional_sigma_ratio, and denoise is performed for each denoise amount. If you use this option, the total denoise amount does not change."}),
|
||||
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"], {"tooltip": "1) AUTO: Automatically set the recovery sampler. If the sampler is uni_pc, uni_pc_bh2, dpmpp_sde, dpmpp_sde_gpu, the dpm_fast sampler is selected If the sampler is dpmpp_2m_sde, dpmpp_2m_sde_gpu, dpmpp_3m_sde, dpmpp_3m_sde_gpu, the dpmpp_2m sampler is selected. 2) Others: Manually set the recovery sampler."}),
|
||||
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Multiplier of noise schedule to be applied according to additional_mode."}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"seed_2nd": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"seed_2nd_mode": (["ignore", "fixed", "seed+seed_2nd", "seed-seed_2nd", "increment", "decrement", "randomize"], ),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"base_only_steps": ("INT", {"default": 2, "min": 0, "max": 10000}),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"samples": ("LATENT", ),
|
||||
"base_sampler": ("KSAMPLER_ADVANCED", ),
|
||||
"regional_prompts": ("REGIONAL_PROMPTS", ),
|
||||
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000}),
|
||||
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between"}),
|
||||
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"],),
|
||||
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("result latent", )
|
||||
|
||||
RETURN_TYPES = ("LATENT", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Regional"
|
||||
|
||||
@staticmethod
|
||||
def separated_sample(*args, **kwargs):
|
||||
return separated_sample(*args, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def mask_erosion(samples, mask, grow_mask_by):
|
||||
mask = mask.clone()
|
||||
@@ -329,13 +320,8 @@ class RegionalSampler:
|
||||
|
||||
return mask_erosion[:, :, :w, :h].round()
|
||||
|
||||
@staticmethod
|
||||
def doit(seed, seed_2nd, seed_2nd_mode, steps, base_only_steps, denoise, samples, base_sampler, regional_prompts, overlap_factor, restore_latent,
|
||||
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):
|
||||
|
||||
samples = samples.copy()
|
||||
samples['samples'] = comfy.sample.fix_empty_latent_channels(base_sampler.params[0], samples['samples'])
|
||||
|
||||
if restore_latent:
|
||||
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
|
||||
else:
|
||||
@@ -358,12 +344,7 @@ class RegionalSampler:
|
||||
if seed_2nd_mode == 'ignore':
|
||||
leftover_noise = True
|
||||
|
||||
noise = Noise_RandomNoise(seed).generate_noise(samples)
|
||||
|
||||
for rp in regional_prompts:
|
||||
noise = rp.touch_noise(noise)
|
||||
|
||||
samples = base_sampler.sample_advanced(True, seed, adv_steps, samples, start_at_step, start_at_step + base_only_steps, leftover_noise, recovery_mode="DISABLE", noise=noise)
|
||||
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
|
||||
@@ -381,21 +362,15 @@ class RegionalSampler:
|
||||
|
||||
if not leftover_noise:
|
||||
add_noise = True
|
||||
noise = Noise_RandomNoise(seed).generate_noise(samples)
|
||||
|
||||
for rp in regional_prompts:
|
||||
noise = rp.touch_noise(noise)
|
||||
else:
|
||||
add_noise = False
|
||||
noise = None
|
||||
|
||||
for i in range(start_at_step+base_only_steps, adv_steps):
|
||||
core.update_node_status(unique_id, f"{i}/{steps} steps | ", ((i-start_at_step)*region_len)/total)
|
||||
|
||||
new_latent_image['noise_mask'] = inv_mask
|
||||
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image,
|
||||
start_at_step=i, end_at_step=i + 1, return_with_leftover_noise=True,
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio, noise=noise)
|
||||
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:
|
||||
@@ -451,38 +426,32 @@ class RegionalSamplerAdvanced:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled", "tooltip": "Whether to add noise"}),
|
||||
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
|
||||
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000, "tooltip": "The starting step of the sampling to be applied at this node within the range of 'steps'."}),
|
||||
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000, "tooltip": "The step at which sampling applied at this node will stop within the range of steps (if greater than steps, sampling will continue only up to steps)."}),
|
||||
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000, "tooltip": "To smooth the seams of the region boundaries, expand the mask set in regional_prompts by the overlap_factor amount to overlap with other regions."}),
|
||||
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled", "tooltip": "At each step, restore the noise outside the mask area to its original state, as per the principle of inpainting. This option is provided for backward compatibility, and it is recommended to always set it to true."}),
|
||||
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled", "tooltip": "Whether to return the latent with noise remaining if the noise has not been completely removed according to the noise schedule, or to completely remove the noise before returning it."}),
|
||||
"latent_image": ("LATENT", {"tooltip": "input latent image"}),
|
||||
"base_sampler": ("KSAMPLER_ADVANCED", {"tooltip": "The sampler applied outside the area set by the regional_prompt."}),
|
||||
"regional_prompts": ("REGIONAL_PROMPTS", {"tooltip": "The prompt applied to each region"}),
|
||||
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between", "tooltip": "..._sde or uni_pc and other special samplers are used, the region is not properly denoised, and it causes a phenomenon that destroys the overall harmony. To compensate for this, a recovery operation is performed using another sampler. This requires a longer time for sampling because a second sampling is performed at each step in each region using a special sampler. 1) DISABLE: Disable this feature. 2) ratio additional: After performing the denoise amount to be performed in the step with the sampler set in the region, the recovery sampler is additionally applied by the additional_sigma_ratio. If you use this option, the total denoise amount increases by additional_sigma_ratio. 3) ratio between: The denoise amount to be performed in the step with the sampler set in the region and the denoise amount to be applied to the recovery sampler are divided by additional_sigma_ratio, and denoise is performed for each denoise amount. If you use this option, the total denoise amount does not change."}),
|
||||
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"], {"tooltip": "1) AUTO: Automatically set the recovery sampler. If the sampler is uni_pc, uni_pc_bh2, dpmpp_sde, dpmpp_sde_gpu, the dpm_fast sampler is selected If the sampler is dpmpp_2m_sde, dpmpp_2m_sde_gpu, dpmpp_3m_sde, dpmpp_3m_sde_gpu, the dpmpp_2m sampler is selected. 2) Others: Manually set the recovery sampler."}),
|
||||
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Multiplier of noise schedule to be applied according to additional_mode."}),
|
||||
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
|
||||
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000}),
|
||||
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000}),
|
||||
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
|
||||
"latent_image": ("LATENT", ),
|
||||
"base_sampler": ("KSAMPLER_ADVANCED", ),
|
||||
"regional_prompts": ("REGIONAL_PROMPTS", ),
|
||||
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between"}),
|
||||
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"],),
|
||||
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("result latent", )
|
||||
|
||||
RETURN_TYPES = ("LATENT", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Regional"
|
||||
|
||||
@staticmethod
|
||||
def doit(add_noise, noise_seed, steps, start_at_step, end_at_step, overlap_factor, restore_latent, return_with_leftover_noise, latent_image, base_sampler, regional_prompts,
|
||||
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):
|
||||
|
||||
new_latent_image = latent_image.copy()
|
||||
new_latent_image['samples'] = comfy.sample.fix_empty_latent_channels(base_sampler.params[0], new_latent_image['samples'])
|
||||
|
||||
if restore_latent:
|
||||
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
|
||||
else:
|
||||
@@ -498,6 +467,7 @@ class RegionalSamplerAdvanced:
|
||||
end_at_step = min(steps, end_at_step)
|
||||
total = (end_at_step - start_at_step) * region_len
|
||||
|
||||
new_latent_image = latent_image.copy()
|
||||
base_latent_image = None
|
||||
region_masks = {}
|
||||
|
||||
@@ -506,16 +476,9 @@ class RegionalSamplerAdvanced:
|
||||
|
||||
cur_add_noise = True if i == start_at_step and add_noise else False
|
||||
|
||||
if cur_add_noise:
|
||||
noise = Noise_RandomNoise(noise_seed).generate_noise(new_latent_image)
|
||||
for rp in regional_prompts:
|
||||
noise = rp.touch_noise(noise)
|
||||
else:
|
||||
noise = None
|
||||
|
||||
new_latent_image['noise_mask'] = inv_mask
|
||||
new_latent_image = base_sampler.sample_advanced(cur_add_noise, noise_seed, steps, new_latent_image, i, i + 1, True,
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio, noise=noise)
|
||||
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
|
||||
|
||||
if restore_latent:
|
||||
del new_latent_image['noise_mask']
|
||||
@@ -572,32 +535,25 @@ class KSamplerBasicPipe:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required":
|
||||
{"basic_pipe": ("BASIC_PIPE", {"tooltip": "basic_pipe input for sampling"}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "tooltip": "classifier free guidance value"}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "sampler"}),
|
||||
"scheduler": (core.SCHEDULERS, {"tooltip": "noise schedule"}),
|
||||
"latent_image": ("LATENT", {"tooltip": "input latent image"}),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned."}),
|
||||
},
|
||||
"optional":
|
||||
{
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
|
||||
}
|
||||
{"basic_pipe": ("BASIC_PIPE",),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"latent_image": ("LATENT", ),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
}
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("passthrough input basic_pipe", "result latent", "VAE in basic_pipe")
|
||||
|
||||
RETURN_TYPES = ("BASIC_PIPE", "LATENT", "VAE")
|
||||
FUNCTION = "sample"
|
||||
|
||||
CATEGORY = "ImpactPack/sampling"
|
||||
CATEGORY = "sampling"
|
||||
|
||||
@staticmethod
|
||||
def sample(basic_pipe, seed, steps, cfg, sampler_name, scheduler, latent_image, denoise=1.0, scheduler_func_opt=None):
|
||||
def sample(self, basic_pipe, seed, steps, cfg, sampler_name, scheduler, latent_image, denoise=1.0):
|
||||
model, clip, vae, positive, negative = basic_pipe
|
||||
latent = impact_sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise, scheduler_func=scheduler_func_opt)
|
||||
latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)[0]
|
||||
return basic_pipe, latent, vae
|
||||
|
||||
|
||||
@@ -605,79 +561,38 @@ class KSamplerAdvancedBasicPipe:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required":
|
||||
{"basic_pipe": ("BASIC_PIPE", {"tooltip": "basic_pipe input for sampling"}),
|
||||
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enable", "label_off": "disable", "tooltip": "Whether to add noise"}),
|
||||
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "tooltip": "Random seed to use for generating CPU noise for sampling."}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "total sampling steps"}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "tooltip": "classifier free guidance value"}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "sampler"}),
|
||||
"scheduler": (core.SCHEDULERS, {"tooltip": "noise schedule"}),
|
||||
"latent_image": ("LATENT", {"tooltip": "input latent image"}),
|
||||
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000, "tooltip": "The starting step of the sampling to be applied at this node within the range of 'steps'."}),
|
||||
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000, "tooltip": "The step at which sampling applied at this node will stop within the range of steps (if greater than steps, sampling will continue only up to steps)."}),
|
||||
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enable", "label_off": "disable", "tooltip": "Whether to return the latent with noise remaining if the noise has not been completely removed according to the noise schedule, or to completely remove the noise before returning it."}),
|
||||
},
|
||||
"optional":
|
||||
{
|
||||
"scheduler_func_opt": ("SCHEDULER_FUNC", {"tooltip": "[OPTIONAL] Noise schedule generation function. If this is set, the scheduler widget will be ignored."}),
|
||||
}
|
||||
{"basic_pipe": ("BASIC_PIPE",),
|
||||
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enable", "label_off": "disable"}),
|
||||
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"latent_image": ("LATENT", ),
|
||||
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
|
||||
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000}),
|
||||
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enable", "label_off": "disable"}),
|
||||
}
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("passthrough input basic_pipe", "result latent", "VAE in basic_pipe")
|
||||
|
||||
RETURN_TYPES = ("BASIC_PIPE", "LATENT", "VAE")
|
||||
FUNCTION = "sample"
|
||||
|
||||
CATEGORY = "ImpactPack/sampling"
|
||||
CATEGORY = "sampling"
|
||||
|
||||
@staticmethod
|
||||
def sample(basic_pipe, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise=1.0, scheduler_func_opt=None):
|
||||
def sample(self, basic_pipe, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise=1.0):
|
||||
model, clip, vae, positive, negative = basic_pipe
|
||||
|
||||
latent = separated_sample(model, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, start_at_step, end_at_step, return_with_leftover_noise, scheduler_func=scheduler_func_opt)
|
||||
if add_noise:
|
||||
add_noise = "enable"
|
||||
else:
|
||||
add_noise = "disable"
|
||||
|
||||
if return_with_leftover_noise:
|
||||
return_with_leftover_noise = "enable"
|
||||
else:
|
||||
return_with_leftover_noise = "disable"
|
||||
|
||||
latent = nodes.KSamplerAdvanced().sample(model, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise)[0]
|
||||
return basic_pipe, latent, vae
|
||||
|
||||
|
||||
class GITSSchedulerFuncProvider:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"coeff": ("FLOAT", {"default": 1.20, "min": 0.80, "max": 1.50, "step": 0.05, "tooltip": "coeff factor of GITS Scheduler"}),
|
||||
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "denoise amount for noise schedule"}),
|
||||
}
|
||||
}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("Returns a function that generates a noise schedule using GITSScheduler. This can be used in place of a predetermined noise schedule to dynamically generate a noise schedule based on the steps.",)
|
||||
|
||||
RETURN_TYPES = ("SCHEDULER_FUNC",)
|
||||
CATEGORY = "ImpactPack/sampling"
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
@staticmethod
|
||||
def doit(coeff, denoise):
|
||||
def f(model, sampler, steps):
|
||||
if 'GITSScheduler' not in nodes.NODE_CLASS_MAPPINGS:
|
||||
raise Exception("[Impact Pack] ComfyUI is an outdated version. Cannot use GITSScheduler.")
|
||||
|
||||
scheduler = nodes.NODE_CLASS_MAPPINGS['GITSScheduler']()
|
||||
return scheduler.get_sigmas(coeff, steps, denoise)[0]
|
||||
|
||||
return (f, )
|
||||
|
||||
|
||||
class NegativeConditioningPlaceholder:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {}}
|
||||
|
||||
OUTPUT_TOOLTIPS = ("This is a Placeholder for the FLUX model that does not use Negative Conditioning.",)
|
||||
|
||||
RETURN_TYPES = ("CONDITIONING",)
|
||||
CATEGORY = "ImpactPack/sampling"
|
||||
|
||||
FUNCTION = "doit"
|
||||
|
||||
@staticmethod
|
||||
def doit():
|
||||
return ("NegativePlaceholder", )
|
||||
|
||||
+27
-211
@@ -5,75 +5,50 @@ import torch
|
||||
import comfy
|
||||
import sys
|
||||
import nodes
|
||||
import re
|
||||
import impact.core as core
|
||||
from server import PromptServer
|
||||
import inspect
|
||||
|
||||
|
||||
class GeneralSwitch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
dyn_inputs = {"input1": (any_typ, {"lazy": True, "tooltip": "Any input. When connected, one more input slot is added."}), }
|
||||
if core.is_execution_model_version_supported():
|
||||
stack = inspect.stack()
|
||||
if stack[2].function == 'get_input_info' and stack[3].function == 'add_node':
|
||||
for x in range(2, 200):
|
||||
dyn_inputs[f"input{x}"] = (any_typ, {"lazy": True})
|
||||
|
||||
inputs = {"required": {
|
||||
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1, "tooltip": "The input number you want to output among the inputs"}),
|
||||
"sel_mode": ("BOOLEAN", {"default": False, "label_on": "select_on_prompt", "label_off": "select_on_execution", "forceInput": False,
|
||||
"tooltip": "In the case of 'select_on_execution', the selection is dynamically determined at the time of workflow execution. 'select_on_prompt' is an option that exists for older versions of ComfyUI, and it makes the decision before the workflow execution."}),
|
||||
return {"required": {
|
||||
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
|
||||
"sel_mode": ("BOOLEAN", {"default": True, "label_on": "select_on_prompt", "label_off": "select_on_execution", "forceInput": False}),
|
||||
},
|
||||
"optional": {
|
||||
"input1": (any_typ,),
|
||||
},
|
||||
"optional": dyn_inputs,
|
||||
"hidden": {"unique_id": "UNIQUE_ID", "extra_pnginfo": "EXTRA_PNGINFO"}
|
||||
}
|
||||
|
||||
return inputs
|
||||
|
||||
RETURN_TYPES = (any_typ, "STRING", "INT")
|
||||
RETURN_NAMES = ("selected_value", "selected_label", "selected_index")
|
||||
OUTPUT_TOOLTIPS = ("Output is generated only from the input chosen by the 'select' value.", "Slot label of the selected input slot", "Outputs the select value as is")
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def check_lazy_status(self, *args, **kwargs):
|
||||
selected_index = int(kwargs['select'])
|
||||
input_name = f"input{selected_index}"
|
||||
|
||||
print(f"SELECTED: {input_name}")
|
||||
|
||||
return [input_name]
|
||||
|
||||
@staticmethod
|
||||
def doit(*args, **kwargs):
|
||||
def doit(self, *args, **kwargs):
|
||||
selected_index = int(kwargs['select'])
|
||||
input_name = f"input{selected_index}"
|
||||
|
||||
selected_label = input_name
|
||||
node_id = kwargs['unique_id']
|
||||
nodelist = kwargs['extra_pnginfo']['workflow']['nodes']
|
||||
for node in nodelist:
|
||||
if str(node['id']) == node_id:
|
||||
inputs = node['inputs']
|
||||
|
||||
if 'extra_pnginfo' in kwargs and kwargs['extra_pnginfo'] is not None:
|
||||
nodelist = kwargs['extra_pnginfo']['workflow']['nodes']
|
||||
for node in nodelist:
|
||||
if str(node['id']) == node_id:
|
||||
inputs = node['inputs']
|
||||
for slot in inputs:
|
||||
if slot['name'] == input_name and 'label' in slot:
|
||||
selected_label = slot['label']
|
||||
|
||||
for slot in inputs:
|
||||
if slot['name'] == input_name and 'label' in slot:
|
||||
selected_label = slot['label']
|
||||
|
||||
break
|
||||
else:
|
||||
print(f"[Impact-Pack] The switch node does not guarantee proper functioning in API mode.")
|
||||
break
|
||||
|
||||
if input_name in kwargs:
|
||||
return kwargs[input_name], selected_label, selected_index
|
||||
return (kwargs[input_name], selected_label, selected_index)
|
||||
else:
|
||||
print(f"ImpactSwitch: invalid select index (ignored)")
|
||||
return None, "", selected_index
|
||||
return (None, "", selected_index)
|
||||
|
||||
|
||||
class LatentSwitch:
|
||||
@classmethod
|
||||
@@ -145,44 +120,23 @@ class GeneralInversedSwitch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1, "tooltip": "The output number you want to send from the input"}),
|
||||
"input": (any_typ, {"tooltip": "Any input. When connected, one more input slot is added."}),
|
||||
|
||||
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
|
||||
"input": (any_typ,),
|
||||
},
|
||||
"optional": {
|
||||
"sel_mode": ("BOOLEAN", {"default": False, "label_on": "select_on_prompt", "label_off": "select_on_execution", "forceInput": False,
|
||||
"tooltip": "In the case of 'select_on_execution', the selection is dynamically determined at the time of workflow execution. 'select_on_prompt' is an option that exists for older versions of ComfyUI, and it makes the decision before the workflow execution."}),
|
||||
},
|
||||
"hidden": {"prompt": "PROMPT", "unique_id": "UNIQUE_ID"},
|
||||
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ByPassTypeTuple((any_typ, ))
|
||||
OUTPUT_TOOLTIPS = ("Output occurs only from the output selected by the 'select' value.\nWhen slots are connected, additional slots are created.", )
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, select, prompt, unique_id, input, **kwargs):
|
||||
if core.is_execution_model_version_supported:
|
||||
from comfy_execution.graph import ExecutionBlocker
|
||||
else:
|
||||
print("[Impact Pack] InversedSwitch: ComfyUI is outdated. The 'select_on_execution' mode cannot function properly.")
|
||||
|
||||
def doit(self, select, input, unique_id):
|
||||
res = []
|
||||
|
||||
# search max output count in prompt
|
||||
cnt = 0
|
||||
for x in prompt.values():
|
||||
for y in x.get('inputs', {}).values():
|
||||
if isinstance(y, list) and len(y) == 2:
|
||||
if y[0] == unique_id:
|
||||
cnt = max(cnt, y[1])
|
||||
|
||||
for i in range(0, cnt + 1):
|
||||
for i in range(0, select):
|
||||
if select == i+1:
|
||||
res.append(input)
|
||||
elif core.is_execution_model_version_supported:
|
||||
res.append(ExecutionBlocker(None))
|
||||
else:
|
||||
res.append(None)
|
||||
|
||||
@@ -236,10 +190,9 @@ class ImpactLogger:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"data": (any_typ,),
|
||||
"text": ("STRING", {"multiline": True}),
|
||||
"data": (any_typ, ""),
|
||||
},
|
||||
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO", "unique_id": "UNIQUE_ID"},
|
||||
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
|
||||
}
|
||||
|
||||
CATEGORY = "ImpactPack/Debug"
|
||||
@@ -249,7 +202,7 @@ class ImpactLogger:
|
||||
RETURN_TYPES = ()
|
||||
FUNCTION = "doit"
|
||||
|
||||
def doit(self, data, text, prompt, extra_pnginfo, unique_id):
|
||||
def doit(self, data, prompt, extra_pnginfo):
|
||||
shape = ""
|
||||
if hasattr(data, "shape"):
|
||||
shape = f"{data.shape} / "
|
||||
@@ -260,13 +213,12 @@ class ImpactLogger:
|
||||
|
||||
# for x in prompt:
|
||||
# if 'inputs' in x and 'populated_text' in x['inputs']:
|
||||
# print(f"PROMPT: {x['10']['inputs']['populated_text']}")
|
||||
# print(f"PROMP: {x['10']['inputs']['populated_text']}")
|
||||
#
|
||||
# for x in extra_pnginfo['workflow']['nodes']:
|
||||
# if x['type'] == 'ImpactWildcardProcessor':
|
||||
# print(f" WV : {x['widgets_values'][1]}\n")
|
||||
|
||||
PromptServer.instance.send_sync("impact-node-feedback", {"node_id": unique_id, "widget_name": "text", "type": "TEXT", "value": f"{data}"})
|
||||
return {}
|
||||
|
||||
|
||||
@@ -392,26 +344,6 @@ class ImageBatchToImageList:
|
||||
return (images, )
|
||||
|
||||
|
||||
class MakeMaskList:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {"mask1": ("MASK",), }}
|
||||
|
||||
RETURN_TYPES = ("MASK",)
|
||||
OUTPUT_IS_LIST = (True,)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, **kwargs):
|
||||
masks = []
|
||||
|
||||
for k, v in kwargs.items():
|
||||
masks.append(v)
|
||||
|
||||
return (masks, )
|
||||
|
||||
|
||||
class MakeImageList:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -457,31 +389,6 @@ class MakeImageBatch:
|
||||
return (image1,)
|
||||
|
||||
|
||||
class MakeMaskBatch:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {"mask1": ("MASK",), }}
|
||||
|
||||
RETURN_TYPES = ("MASK",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, **kwargs):
|
||||
mask1 = kwargs['mask1']
|
||||
del kwargs['mask1']
|
||||
masks = [utils.make_3d_mask(value) for value in kwargs.values()]
|
||||
|
||||
if len(masks) == 0:
|
||||
return (mask1,)
|
||||
else:
|
||||
for mask2 in masks:
|
||||
if mask1.shape[1:] != mask2.shape[1:]:
|
||||
mask2 = comfy.utils.common_upscale(mask2.movedim(-1, 1), mask1.shape[2], mask1.shape[1], "lanczos", "center").movedim(1, -1)
|
||||
mask1 = torch.cat((mask1, mask2), dim=0)
|
||||
return (mask1,)
|
||||
|
||||
|
||||
class ReencodeLatent:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -578,94 +485,3 @@ class StringSelector:
|
||||
selected = lines[select % len(lines)]
|
||||
|
||||
return (selected, )
|
||||
|
||||
|
||||
class StringListToString:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"join_with": ("STRING", {"default": "\\n"}),
|
||||
"string_list": ("STRING", {"forceInput": True}),
|
||||
}
|
||||
}
|
||||
|
||||
INPUT_IS_LIST = True
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, join_with, string_list):
|
||||
# convert \\n to newline character
|
||||
if join_with[0] == "\\n":
|
||||
join_with[0] = "\n"
|
||||
|
||||
joined_text = join_with[0].join(string_list)
|
||||
|
||||
return (joined_text,)
|
||||
|
||||
|
||||
class WildcardPromptFromString:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"string": ("STRING", {"forceInput": True}),
|
||||
"delimiter": ("STRING", {"multiline": False, "default": "\\n" }),
|
||||
"prefix_all": ("STRING", {"multiline": False}),
|
||||
"postfix_all": ("STRING", {"multiline": False}),
|
||||
"restrict_to_tags": ("STRING", {"multiline": False}),
|
||||
"exclude_tags": ("STRING", {"multiline": False})
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING", "STRING",)
|
||||
RETURN_NAMES = ("wildcard", "segs_labels",)
|
||||
FUNCTION = "doit"
|
||||
|
||||
CATEGORY = "ImpactPack/Util"
|
||||
|
||||
def doit(self, string, delimiter, prefix_all, postfix_all, restrict_to_tags, exclude_tags):
|
||||
# convert \\n to newline character
|
||||
if delimiter == "\\n":
|
||||
delimiter = "\n"
|
||||
|
||||
# some sanity checks and normalization for later processing
|
||||
if prefix_all is None:
|
||||
prefix_all = ""
|
||||
if postfix_all is None:
|
||||
postfix_all = ""
|
||||
if restrict_to_tags is None:
|
||||
restrict_to_tags = ""
|
||||
if exclude_tags is None:
|
||||
exclude_tags = ""
|
||||
|
||||
restrict_to_tags = restrict_to_tags.split(", ")
|
||||
exclude_tags = exclude_tags.split(", ")
|
||||
|
||||
# build the wildcard prompt per list entry
|
||||
output = ["[LAB]"]
|
||||
labels = []
|
||||
for x in string.split(delimiter):
|
||||
label = str(len(labels) + 1)
|
||||
labels.append(label)
|
||||
x = x.split(", ")
|
||||
# restrict to tags
|
||||
if restrict_to_tags != [""]:
|
||||
x = list(set(x) & set(restrict_to_tags))
|
||||
# remove tags
|
||||
if exclude_tags != [""]:
|
||||
x = list(set(x) - set(exclude_tags))
|
||||
# next row: <LABEL> <PREFIX> <TAGS> <POSTFIX>
|
||||
prompt_for_seg = f'[{label}] {prefix_all} {", ".join(x)} {postfix_all}'.strip()
|
||||
output.append(prompt_for_seg)
|
||||
output = "\n".join(output)
|
||||
|
||||
# clean string: fixup double spaces, commas etc.
|
||||
output = re.sub(r' ,', ',', output)
|
||||
output = re.sub(r' +', ' ', output)
|
||||
output = re.sub(r',,+', ',', output)
|
||||
output = re.sub(r'\n, ', '\n', output)
|
||||
|
||||
return output, ", ".join(labels)
|
||||
|
||||
+14
-36
@@ -5,8 +5,11 @@ import numpy as np
|
||||
import folder_paths
|
||||
import nodes
|
||||
from . import config
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageFilter
|
||||
from scipy.ndimage import zoom
|
||||
import comfy
|
||||
import comfy.ldm.cascade as cascade
|
||||
from comfy_extras import nodes_stable_cascade
|
||||
|
||||
|
||||
class TensorBatchBuilder:
|
||||
@@ -125,7 +128,7 @@ def to_pil(image):
|
||||
|
||||
def to_tensor(image):
|
||||
if isinstance(image, Image.Image):
|
||||
return torch.from_numpy(np.array(image)) / 255.0
|
||||
return torch.from_numpy(np.array(image))
|
||||
if isinstance(image, torch.Tensor):
|
||||
return image
|
||||
if isinstance(image, np.ndarray):
|
||||
@@ -182,8 +185,7 @@ def tensor_paste(image1, image2, left_top, mask):
|
||||
_tensor_check_image(image2)
|
||||
_tensor_check_mask(mask)
|
||||
if image2.shape[1:3] != mask.shape[1:3]:
|
||||
mask = resize_mask(mask.squeeze(dim=3), image2.shape[1:3]).unsqueeze(dim=3)
|
||||
# raise ValueError(f"Inconsistent size: Image ({image2.shape[1:3]}) != Mask ({mask.shape[1:3]})")
|
||||
raise ValueError(f"Inconsistent size: Image ({image2.shape[1:3]}) != Mask ({mask.shape[1:3]})")
|
||||
|
||||
x, y = left_top
|
||||
_, h1, w1, _ = image1.shape
|
||||
@@ -475,17 +477,6 @@ def crop_ndarray4(npimg, crop_region):
|
||||
crop_tensor4 = crop_ndarray4
|
||||
|
||||
|
||||
def crop_ndarray3(npimg, crop_region):
|
||||
x1 = crop_region[0]
|
||||
y1 = crop_region[1]
|
||||
x2 = crop_region[2]
|
||||
y2 = crop_region[3]
|
||||
|
||||
cropped = npimg[:, y1:y2, x1:x2]
|
||||
|
||||
return cropped
|
||||
|
||||
|
||||
def crop_ndarray2(npimg, crop_region):
|
||||
x1 = crop_region[0]
|
||||
y1 = crop_region[1]
|
||||
@@ -501,13 +492,19 @@ def crop_image(image, crop_region):
|
||||
return crop_tensor4(image, crop_region)
|
||||
|
||||
|
||||
def to_latent_image(pixels, vae):
|
||||
def to_latent_image(pixels, vae, compression=None):
|
||||
x = pixels.shape[1]
|
||||
y = pixels.shape[2]
|
||||
if pixels.shape[1] != x or pixels.shape[2] != y:
|
||||
pixels = pixels[:, :x, :y, :]
|
||||
|
||||
vae_encode = nodes.VAEEncode()
|
||||
if hasattr(nodes.VAEEncode, "vae_encode_crop_pixels"):
|
||||
# backward compatibility
|
||||
print(f"[Impact Pack] ComfyUI is outdated.")
|
||||
pixels = vae_encode.vae_encode_crop_pixels(pixels)
|
||||
t = vae.encode(pixels[:, :, :, :3])
|
||||
return {"samples": t}
|
||||
|
||||
return vae_encode.encode(vae, pixels)[0]
|
||||
|
||||
@@ -536,16 +533,6 @@ def make_3d_mask(mask):
|
||||
return mask
|
||||
|
||||
|
||||
def make_4d_mask(mask):
|
||||
if len(mask.shape) == 3:
|
||||
return mask.unsqueeze(0)
|
||||
|
||||
elif len(mask.shape) == 2:
|
||||
return mask.unsqueeze(0).unsqueeze(0)
|
||||
|
||||
return mask
|
||||
|
||||
|
||||
def is_same_device(a, b):
|
||||
a_device = torch.device(a) if isinstance(a, str) else a
|
||||
b_device = torch.device(b) if isinstance(b, str) else b
|
||||
@@ -565,8 +552,7 @@ from torchvision.transforms.functional import to_pil_image
|
||||
|
||||
|
||||
def resize_mask(mask, size):
|
||||
mask = make_4d_mask(mask)
|
||||
resized_mask = torch.nn.functional.interpolate(mask, size=size, mode='bilinear', align_corners=False)
|
||||
resized_mask = torch.nn.functional.interpolate(mask.unsqueeze(0), size=size, mode='bilinear', align_corners=False)
|
||||
return resized_mask.squeeze(0)
|
||||
|
||||
|
||||
@@ -578,14 +564,6 @@ def apply_mask_alpha_to_pil(decoded_pil, mask):
|
||||
return decoded_rgba
|
||||
|
||||
|
||||
def flatten_mask(all_masks):
|
||||
merged_mask = (all_masks[0] * 255).to(torch.uint8)
|
||||
for mask in all_masks[1:]:
|
||||
merged_mask |= (mask * 255).to(torch.uint8)
|
||||
|
||||
return merged_mask
|
||||
|
||||
|
||||
def try_install_custom_node(custom_node_url, msg):
|
||||
try:
|
||||
import cm_global
|
||||
|
||||
+23
-110
@@ -7,12 +7,8 @@ import yaml
|
||||
import numpy as np
|
||||
import threading
|
||||
from impact import utils
|
||||
from impact import config
|
||||
|
||||
|
||||
wildcards_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "wildcards"))
|
||||
|
||||
RE_WildCardQuantifier = re.compile(r"(?P<quantifier>\d+)#__(?P<keyword>[\w.\-+/*\\]+)__", re.IGNORECASE)
|
||||
wildcard_lock = threading.Lock()
|
||||
wildcard_dict = {}
|
||||
|
||||
@@ -29,7 +25,7 @@ def get_wildcard_dict():
|
||||
|
||||
|
||||
def wildcard_normalize(x):
|
||||
return x.replace("\\", "/").replace(' ', '-').lower()
|
||||
return x.replace("\\", "/").lower()
|
||||
|
||||
|
||||
def read_wildcard(k, v):
|
||||
@@ -41,9 +37,6 @@ def read_wildcard(k, v):
|
||||
new_key = f"{k}/{k2}"
|
||||
new_key = wildcard_normalize(new_key)
|
||||
read_wildcard(new_key, v2)
|
||||
elif isinstance(v, str):
|
||||
k = wildcard_normalize(k)
|
||||
wildcard_dict[k] = [v]
|
||||
|
||||
|
||||
def read_wildcard_dict(wildcard_path):
|
||||
@@ -53,62 +46,32 @@ def read_wildcard_dict(wildcard_path):
|
||||
if file.endswith('.txt'):
|
||||
file_path = os.path.join(root, file)
|
||||
rel_path = os.path.relpath(file_path, wildcard_path)
|
||||
key = wildcard_normalize(os.path.splitext(rel_path)[0])
|
||||
key = os.path.splitext(rel_path)[0].replace('\\', '/').lower()
|
||||
|
||||
try:
|
||||
with open(file_path, 'r', encoding="ISO-8859-1") as f:
|
||||
lines = f.read().splitlines()
|
||||
wildcard_dict[key] = lines
|
||||
except yaml.reader.ReaderError:
|
||||
except UnicodeDecodeError:
|
||||
with open(file_path, 'r', encoding="UTF-8", errors="ignore") as f:
|
||||
lines = f.read().splitlines()
|
||||
wildcard_dict[key] = lines
|
||||
elif file.endswith('.yaml'):
|
||||
file_path = os.path.join(root, file)
|
||||
with open(file_path, 'r') as f:
|
||||
yaml_data = yaml.load(f, Loader=yaml.FullLoader)
|
||||
|
||||
try:
|
||||
with open(file_path, 'r', encoding="ISO-8859-1") as f:
|
||||
yaml_data = yaml.load(f, Loader=yaml.FullLoader)
|
||||
except yaml.reader.ReaderError as e:
|
||||
with open(file_path, 'r', encoding="UTF-8", errors="ignore") as f:
|
||||
yaml_data = yaml.load(f, Loader=yaml.FullLoader)
|
||||
|
||||
for k, v in yaml_data.items():
|
||||
read_wildcard(k, v)
|
||||
for k, v in yaml_data.items():
|
||||
read_wildcard(k, v)
|
||||
|
||||
return wildcard_dict
|
||||
|
||||
|
||||
def process_comment_out(text):
|
||||
lines = text.split('\n')
|
||||
|
||||
lines0 = []
|
||||
flag = False
|
||||
for line in lines:
|
||||
if line.lstrip().startswith('#'):
|
||||
flag = True
|
||||
continue
|
||||
|
||||
if len(lines0) == 0:
|
||||
lines0.append(line)
|
||||
elif flag:
|
||||
lines0[-1] += ' ' + line
|
||||
flag = False
|
||||
else:
|
||||
lines0.append(line)
|
||||
|
||||
return '\n'.join(lines0)
|
||||
|
||||
|
||||
def process(text, seed=None):
|
||||
text = process_comment_out(text)
|
||||
|
||||
if seed is not None:
|
||||
random.seed(seed)
|
||||
random_gen = np.random.default_rng(seed)
|
||||
|
||||
local_wildcard_dict = get_wildcard_dict()
|
||||
|
||||
def replace_options(string):
|
||||
replacements_found = False
|
||||
|
||||
@@ -121,7 +84,6 @@ def process(text, seed=None):
|
||||
select_sep = ' '
|
||||
range_pattern = r'(\d+)(-(\d+))?'
|
||||
range_pattern2 = r'-(\d+)'
|
||||
wildcard_pattern = r"__([\w.\-+/*\\]+)__"
|
||||
|
||||
if len(multi_select_pattern) > 1:
|
||||
r = re.match(range_pattern, options[0])
|
||||
@@ -147,13 +109,7 @@ def process(text, seed=None):
|
||||
|
||||
if select_range is not None and len(multi_select_pattern) == 2:
|
||||
# PATTERN: count$$
|
||||
matches = re.findall(wildcard_pattern, multi_select_pattern[1])
|
||||
if len(options) == 1 and matches:
|
||||
# count$$<single wildcard>
|
||||
options = local_wildcard_dict.get(matches[0])
|
||||
else:
|
||||
# count$$opt1|opt2|...
|
||||
options[0] = multi_select_pattern[1]
|
||||
options[0] = multi_select_pattern[1]
|
||||
elif select_range is not None and len(multi_select_pattern) == 3:
|
||||
# PATTERN: count$$ sep $$
|
||||
select_sep = multi_select_pattern[1]
|
||||
@@ -200,6 +156,7 @@ def process(text, seed=None):
|
||||
return replaced_string, replacements_found
|
||||
|
||||
def replace_wildcard(string):
|
||||
local_wildcard_dict = get_wildcard_dict()
|
||||
pattern = r"__([\w.\-+/*\\]+)__"
|
||||
matches = re.findall(pattern, string)
|
||||
|
||||
@@ -213,11 +170,11 @@ def process(text, seed=None):
|
||||
replacements_found = True
|
||||
string = string.replace(f"__{match}__", replacement, 1)
|
||||
elif '*' in keyword:
|
||||
subpattern = keyword.replace('*', '.*').replace('+', '\\+')
|
||||
subpattern = keyword.replace('*', '.*').replace('+','\+')
|
||||
total_patterns = []
|
||||
found = False
|
||||
for k, v in local_wildcard_dict.items():
|
||||
if re.match(subpattern, k) is not None or re.match(subpattern, k+'/') is not None:
|
||||
if re.match(subpattern, k) is not None:
|
||||
total_patterns += v
|
||||
found = True
|
||||
|
||||
@@ -235,15 +192,6 @@ def process(text, seed=None):
|
||||
stop_unwrap = False
|
||||
while not stop_unwrap and replace_depth > 1:
|
||||
replace_depth -= 1 # prevent infinite loop
|
||||
|
||||
option_quantifier = [e.groupdict() for e in RE_WildCardQuantifier.finditer(text)]
|
||||
for match in option_quantifier:
|
||||
keyword = match['keyword'].lower()
|
||||
quantifier = int(match['quantifier']) if match['quantifier'] else 1
|
||||
replacement = '__|__'.join([keyword,] * quantifier)
|
||||
wilder_keyword = keyword.replace('*', '\\*')
|
||||
RE_TEMP = re.compile(fr"(?P<quantifier>\d+)#__(?P<keyword>{wilder_keyword})__", re.IGNORECASE)
|
||||
text = RE_TEMP.sub(f"__{replacement}__", text)
|
||||
|
||||
# pass1: replace options
|
||||
pass1, is_replaced1 = replace_options(text)
|
||||
@@ -339,22 +287,10 @@ def resolve_lora_name(lora_name_cache, name):
|
||||
return x
|
||||
|
||||
|
||||
def process_with_loras(wildcard_opt, model, clip, clip_encoder=None, seed=None, processed=None):
|
||||
"""
|
||||
process wildcard text including loras
|
||||
|
||||
:param wildcard_opt: wildcard text
|
||||
:param model: model
|
||||
:param clip: clip
|
||||
:param clip_encoder: you can pass custom encoder such as adv_cliptext_encode
|
||||
:param seed: seed for populating
|
||||
:param processed: output variable - [pass1, pass2, pass3] will be saved into passed list
|
||||
:return: model, clip, conditioning
|
||||
"""
|
||||
|
||||
def process_with_loras(wildcard_opt, model, clip, clip_encoder=None):
|
||||
lora_name_cache = []
|
||||
|
||||
pass1 = process(wildcard_opt, seed)
|
||||
pass1 = process(wildcard_opt)
|
||||
loras = extract_lora_values(pass1)
|
||||
pass2 = remove_lora_tags(pass1)
|
||||
|
||||
@@ -415,17 +351,12 @@ def process_with_loras(wildcard_opt, model, clip, clip_encoder=None, seed=None,
|
||||
else:
|
||||
result = cur
|
||||
|
||||
if processed is not None:
|
||||
processed.append(pass1)
|
||||
processed.append(pass2)
|
||||
processed.append(pass3)
|
||||
|
||||
return model, clip, result
|
||||
|
||||
|
||||
def starts_with_regex(pattern, text):
|
||||
regex = re.compile(pattern)
|
||||
return regex.match(text)
|
||||
return bool(regex.match(text))
|
||||
|
||||
|
||||
def split_to_dict(text):
|
||||
@@ -507,33 +438,15 @@ def process_wildcard_for_segs(wildcard):
|
||||
|
||||
return 'LAB', WildcardChooserDict(items)
|
||||
|
||||
else:
|
||||
match = starts_with_regex(r"\[(ASC-SIZE|DSC-SIZE|ASC|DSC|RND)\]", wildcard)
|
||||
|
||||
if match:
|
||||
mode = match[1]
|
||||
items = split_string_with_sep(wildcard[len(match[0]):])
|
||||
|
||||
if mode == 'RND':
|
||||
random.shuffle(items)
|
||||
return mode, WildcardChooser(items, True)
|
||||
else:
|
||||
return mode, WildcardChooser(items, False)
|
||||
elif starts_with_regex(r"\[(ASC|DSC|RND)\]", wildcard):
|
||||
mode = wildcard[1:4]
|
||||
items = split_string_with_sep(wildcard[5:])
|
||||
|
||||
if mode == 'RND':
|
||||
random.shuffle(items)
|
||||
return mode, WildcardChooser(items, True)
|
||||
else:
|
||||
return None, WildcardChooser([(None, wildcard)], False)
|
||||
return mode, WildcardChooser(items, False)
|
||||
|
||||
|
||||
def wildcard_load():
|
||||
global wildcard_dict
|
||||
wildcard_dict = {}
|
||||
|
||||
with wildcard_lock:
|
||||
read_wildcard_dict(wildcards_path)
|
||||
|
||||
try:
|
||||
read_wildcard_dict(config.get_config()['custom_wildcards'])
|
||||
except Exception as e:
|
||||
print(f"[Impact Pack] Failed to load custom wildcards directory.")
|
||||
|
||||
print(f"[Impact Pack] Wildcards loading done.")
|
||||
else:
|
||||
return None, WildcardChooser([(None, wildcard)], False)
|
||||
|
||||
Vendored
+10
-16
@@ -5,9 +5,6 @@
|
||||
import comfy
|
||||
import torch
|
||||
|
||||
from comfy import sampler_helpers
|
||||
|
||||
|
||||
class Unsampler:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
@@ -42,27 +39,25 @@ class Unsampler:
|
||||
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
|
||||
noise_mask = None
|
||||
if "noise_mask" in latent:
|
||||
noise_mask = comfy.sampler_helpers.prepare_mask(latent["noise_mask"], noise.shape, device)
|
||||
noise_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)
|
||||
|
||||
conds0 = \
|
||||
{"positive": comfy.sampler_helpers.convert_cond(positive),
|
||||
"negative": comfy.sampler_helpers.convert_cond(negative)}
|
||||
positive = comfy.sample.convert_cond(positive)
|
||||
negative = comfy.sample.convert_cond(negative)
|
||||
|
||||
conds = {}
|
||||
for k in conds0:
|
||||
conds[k] = list(map(lambda a: a.copy(), conds0[k]))
|
||||
|
||||
models, inference_memory = comfy.sampler_helpers.get_additional_models(conds, model.model_dtype())
|
||||
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(model, steps=steps, device=device, sampler=sampler_name,
|
||||
sampler = comfy.samplers.KSampler(real_model, steps=steps, device=device, sampler=sampler_name,
|
||||
scheduler=scheduler, denoise=1.0, model_options=model.model_options)
|
||||
|
||||
sigmas = sampler.sigmas.flip(0) + 0.0001
|
||||
sigmas = sigmas = sampler.sigmas.flip(0) + 0.0001
|
||||
|
||||
pbar = comfy.utils.ProgressBar(steps)
|
||||
|
||||
@@ -78,9 +73,8 @@ class Unsampler:
|
||||
samples /= samples.std()
|
||||
samples = samples.cpu()
|
||||
|
||||
comfy.sampler_helpers.cleanup_additional_models(models)
|
||||
comfy.sample.cleanup_additional_models(models)
|
||||
|
||||
out = latent.copy()
|
||||
out["samples"] = samples
|
||||
return (out,)
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
[project]
|
||||
name = "comfyui-impact-pack"
|
||||
description = "This extension offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler."
|
||||
version = "7.5"
|
||||
license = { file = "LICENSE.txt" }
|
||||
dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
|
||||
# Used by Comfy Registry https://comfyregistry.org
|
||||
|
||||
[tool.comfy]
|
||||
PublisherId = "drltdata"
|
||||
DisplayName = "ComfyUI Impact Pack"
|
||||
Icon = ""
|
||||
@@ -4,5 +4,3 @@ piexif
|
||||
transformers
|
||||
opencv-python-headless
|
||||
GitPython
|
||||
scipy>=1.11.4
|
||||
numpy<2
|
||||
|
||||
Reference in New Issue
Block a user