Nodes/ComfyUI-Apt_Preset/flow_tensor_Unify
ComfyUI Node

flow_tensor_Unify

Fix mismatched image/mask shapes before they crash your graph

By cardenluo·Created 2 years ago·Updated 18 days ago· 309
flow_tensor_Unify
  • image
  • mask
  • unified_image
  • unified_mask
keep_alphafalse

If you've ever hit a ComfyUI error along the lines of "sizes of tensors must match" because a mask came from one place and an image came from another, this node is built for exactly that moment. It takes an image and a mask that might not agree on resolution, batch size, or channel count, and reconciles them into a matched pair - unified_image and unified_mask - so whatever you wire them into next stops throwing shape errors.

How it works

Mismatched image/mask pairs are one of the most common friction points in ComfyUI inpainting and masking workflows: a mask you loaded separately, generated at a different resolution, or pulled from a different batch than the image it's supposed to apply to, and downstream nodes that expect the two to line up exactly. flow_tensor_Unify sits in front of that failure point and normalizes both inputs - resizing and/or batch-matching them against each other - before handing back a pair guaranteed to agree.

keep_alpha is the one real decision you make: with it on, an image's alpha channel is preserved through the unification process (useful if you're carrying transparency information you need later); with it off (the default), alpha gets dropped or folded into the RGB/mask handling instead. Both image and mask are optional inputs, so you can run this with just one of them if you only need to normalize a single tensor rather than a pair.

Inputs and output

  • keep_alpha (BOOLEAN, required, default false) - whether to preserve an image's alpha channel through the process.
  • image (IMAGE, optional).
  • mask (MASK, optional).
  • unified_image (IMAGE, output) - the reconciled image.
  • unified_mask (MASK, output) - the reconciled mask.

Installing it

Search ComfyUI-Apt_Preset in ComfyUI Manager and install, or manually: cd ComfyUI/custom_nodes && git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git, then restart. The README's own dependency step is "double-click install.bat" - Windows-first, with no requirements.txt visible elsewhere, so on Linux/Mac open that file to see what it installs and mirror it manually in your ComfyUI venv. This node is pure tensor plumbing and needs none of the pack's optional extras (GGUF, Advanced-ControlNet, nunchaku, downloaded models) - those serve other, unrelated corners of this large pack.

Common issues

If you're still getting shape-mismatch errors downstream after adding this node, check that you actually wired both image and mask into it - since both are optional, it's easy to leave one unconnected by accident and get a "unified" output that's really just a pass-through of whatever you did connect.

Watch what keep_alpha does to your output if your source images have transparency you care about - the default is off, so unless you flip it, expect alpha to not survive the trip through this node.

And the pack-wide caveat: this is one node in a large, actively developed package, and an import error elsewhere in the pack can take this node down too. If it's missing after install, check the ComfyUI console at boot for the actual traceback rather than re-checking your workflow first.

CategoryApt_Preset/flow

Inputs (3)

NameTypeDefaultDescription
keep_alphaBOOLEANfalse
imageoptIMAGE
maskoptMASK

Outputs (2)

NameTypeDescription
unified_imageIMAGE
unified_maskMASK