ComfyUI > Nodes > KJNodes for ComfyUI > FilterZeroMasksAndCorrespondingImages

ComfyUI Node: FilterZeroMasksAndCorrespondingImages

Class Name

FilterZeroMasksAndCorrespondingImages

Category
KJNodes/masking
Author
kijai (Account age: 2192days)
Extension
KJNodes for ComfyUI
Latest Updated
2024-06-25
Github Stars
0.35K

How to Install KJNodes for ComfyUI

Install this extension via the ComfyUI Manager by searching for KJNodes for ComfyUI
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter KJNodes for ComfyUI in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • High-speed GPU machines
  • 200+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 50+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

FilterZeroMasksAndCorrespondingImages Description

FilterZeroMasksAndCorrespondingImages: Filters out zero masks and their corresponding images to optimize processing and improve dataset quality.

FilterZeroMasksAndCorrespondingImages:

The FilterZeroMasksAndCorrespondingImages node is designed to process a set of masks and their corresponding images, filtering out masks that contain no non-zero values (i.e., masks that are entirely zero). This node is particularly useful in scenarios where you need to ensure that only relevant masks and their associated images are processed further, thereby optimizing computational resources and improving the quality of the results. By separating non-zero masks from zero masks, this node helps in maintaining a clean dataset, which is crucial for tasks such as image segmentation, object detection, and other AI-driven image processing applications.

FilterZeroMasksAndCorrespondingImages Input Parameters:

masks

This parameter represents the list of masks that you want to filter. Each mask is typically a binary or grayscale image where non-zero values indicate areas of interest. The function of this parameter is to provide the node with the data it needs to identify and separate non-zero masks from zero masks. There are no specific minimum, maximum, or default values for this parameter as it depends on the dataset you are working with.

original_images

This optional parameter represents the list of original images corresponding to the masks. If provided, the node will also filter and return the images associated with the non-zero masks. This ensures that the images and masks remain synchronized after filtering. If the number of original images does not match the number of masks, a warning will be issued, and the images will be ignored. There are no specific minimum, maximum, or default values for this parameter as it depends on the dataset you are working with.

FilterZeroMasksAndCorrespondingImages Output Parameters:

non_zero_masks_out

This output parameter contains the stack of masks that have non-zero values. These are the masks that passed the filtering criteria and are considered relevant for further processing. The function of this parameter is to provide a clean set of masks that can be used in subsequent image processing tasks.

non_zero_mask_images_out

This output parameter contains the stack of original images corresponding to the non-zero masks. This ensures that the images remain synchronized with their respective masks after filtering. If the original_images parameter was not provided or ignored due to a mismatch in the number of images and masks, this output will be None.

zero_mask_images_out

This output parameter contains the stack of original images corresponding to the zero masks. These are the images associated with masks that were entirely zero and thus filtered out. If the original_images parameter was not provided or ignored, this output will be None.

zero_mask_images_out_indexes

This output parameter contains the indexes of the zero masks in the original list. This helps in identifying which masks were filtered out and can be useful for debugging or further analysis. If the original_images parameter was not provided or ignored, this output will be None.

FilterZeroMasksAndCorrespondingImages Usage Tips:

  • Ensure that the number of original images matches the number of masks to avoid warnings and ensure that the images are processed correctly.
  • Use this node to clean your dataset before performing computationally intensive tasks like training a model or running complex image processing algorithms.
  • If you are only interested in the masks and not the corresponding images, you can omit the original_images parameter to simplify the output.

FilterZeroMasksAndCorrespondingImages Common Errors and Solutions:

[WARNING] ignore input: original_images, due to number of original_images ({imgs_num}) is not equal to number of masks ({masks_num})

  • Explanation: This warning occurs when the number of original images provided does not match the number of masks. The node requires an equal number of images and masks to process them correctly.
  • Solution: Ensure that the number of original images matches the number of masks before passing them to the node. If you do not need to process the images, you can omit the original_images parameter.

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

  • Explanation: This error occurs when the masks or images are not all on the same device (e.g., some are on the CPU and others on the GPU).
  • Solution: Ensure that all masks and images are on the same device before passing them to the node. You can use .to(device) to move tensors to the desired device.

ValueError: zero-dimensional tensor (at position 0) cannot be concatenated

  • Explanation: This error occurs when there are no non-zero masks to stack, resulting in an empty tensor.
  • Solution: Ensure that your dataset contains at least one non-zero mask. If your dataset is expected to have zero masks, handle this case separately to avoid passing an empty list to the node.

FilterZeroMasksAndCorrespondingImages Related Nodes

Go back to the extension to check out more related nodes.
KJNodes for ComfyUI
RunComfy

© Copyright 2024 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals.