Nodes/Mask Tensor I/O/Save Mask Tensor
ComfyUI Node

Save Mask Tensor

Stop re-segmenting the same video every time you tweak a denoise

By swanjohn99·Created a day ago·Updated about 13 hours ago· 0
Save Mask Tensor
  • masks
  • masks
filename_prefixsam3_masks
subfoldermasks

If you've built anything around SAM 3, you know the shape of the problem. Text-prompt "the man's jacket", SAM 3 hands you a mask, you feed it into an inpaint pass - and then you spend the next hour nudging denoise and mask blur while the segmentation model re-runs from scratch on every single queue. On a still image that's tolerable. On a video it's insulting: SAM 3 is the slow part of the workflow, and it needs Triton on Windows just to run.

Save Mask Tensor writes the mask to disk as a .pt tensor and passes it straight through, so you segment once and then iterate on everything downstream. It's a mask_io node from the small pack swanjohn99/comfyUIcostumNodes.

Why a file, and not just a PNG

ComfyUI's MASK type is a float tensor shaped [B, H, W] with values 0–1. The moment you round-trip that through a grayscale PNG you've quantized it to 8 bits - 256 levels for a mask whose whole job is a smooth gradient at the edge of a feathered region or a hair strand. Soft masks come back banded, and you're now inpainting against a slightly different mask than the one you approved.

A .pt keeps the floats exactly as they were - which is why the same repo also ships Save/Load nodes for MiniMax H3 AV latents. This pack is about not losing data on the way to disk.

What it does, mechanically

The node normalizes whatever mask you feed it to [B, H, W] - a bare [H, W], a [B, 1, H, W], or a [B, H, W, 1] all get squeezed into shape - casts to float32, and calls torch.save on it. Files land in output/<subfolder>/<prefix>_00001.pt, five-digit counter, incrementing from whatever already exists so nothing gets overwritten (delete _00005 and the next save reuses that number). It's an output node, so it always runs, and it returns the mask unchanged.

You also get a download button on the node itself, added by the pack's javascript: a picker of the .pt files in your subfolder with size and timestamp, and bulk download or delete. You'll want it, because these files pile up.

The inputs that matter

  • masks - the MASK to save, and the thing that comes back out the other side. Wire your segmenter (or the composite/blur chain) in, then wire the output onward into your mask consumers. It's a pass-through, not a dead end.
  • filename_prefix - default sam3_masks. Slashes get sanitized to underscores, so this names the file, not a second folder.
  • subfolder - default masks, relative to ComfyUI's output/ directory. Whatever you type here is what Load Mask Tensor has to be set to later.

One output: masks (MASK), the same tensor you put in.

Install

Clone it into your custom nodes and restart:

cd ComfyUI/custom_nodes
git clone https://github.com/swanjohn99/comfyUIcostumNodes

Then restart ComfyUI. There is nothing else to install - no pip step, no model download. The pyproject.toml declares no dependencies and the code only uses Comfy's own torch and folder_paths. It's set up for the Comfy Registry (display name Mask Tensor I/O), so Manager may find it under that name; if the search comes up empty, clone it.

Where people get burned

The files multiply. Every run of an output node writes a new numbered file, and the counter only goes up. A graph you queue forty times leaves forty masks in output/masks. Nothing cleans them up but you, which is what the download button's delete mode is for.

Masks live in output/, not input/. That's deliberate - output survives restarts and shows up in the UI's output browser - but it means your masks sit in the same directory tree as your renders, and a "clean up output" habit will happily take them with it.

Subfolder mismatch is the classic follow-up error. Save to masks/shot04, then load with masks still in the other node's field, and you get a FileNotFoundError naming a path you don't recognize. Match them.

A .pt is a pickled torch tensor, not a safetensors file. It's the author's own format. Don't load .pt files that came from a stranger on the internet; the loader asks torch for weights_only=True, which is the safe mode, but that's a guardrail, not a reason to trust random binaries.

And if the console prints Unsupported MASK shape, an upstream node handed over a 4-D tensor with more than one channel - a genuinely different kind of mask, not a bug here.

Categorymask_io

Inputs (3)

NameTypeDefaultDescription
masksMASK
filename_prefixSTRINGsam3_masks
subfolderSTRINGmasks

Outputs (1)

NameTypeDescription
masksMASK