BD Cache Mask
Don't re-run the segmentation just to keep the same mask
- mask
- mask
- status
Masks are the cheap-looking thing that turns out to be expensive. A SAM3 call, a human parser, a background removal - each one loads a model, runs it, and produces a mask that probably isn't going to change while you fiddle with everything after it. BD Cache Mask freezes that mask so the segmentation only runs once. On later runs the whole upstream chain is skipped and the cached mask loads straight back - no model reload, no inference, just the mask.
It's the same lazy-evaluation design as the other BD cache nodes: on a hit, check_lazy_status tells ComfyUI "I don't need my inputs," and the engine skips the upstream branch entirely. The file format is PNG, which is ideal for a single-channel mask - lossless, and you can eyeball it in the output folder.
One structural difference from its siblings: the mask input is optional, not required. That's deliberate. Because the whole point is that a cached mask doesn't need its upstream, this node happily stands alone with just a cache_name and seed and loads from disk. The tooltip spells it out - "Input mask - optional when cache exists." You can even build a workflow where the mask source is disconnected and the cache node is the only thing feeding your inpaint/composite chain.
The inputs
- mask - optional MASK input to cache. Leave it unwired when you're purely loading.
- cache_name - label (default
cached_mask). Make it meaningful if you cache several masks, likehair_maskorskin_zone. - seed - the invalidation key; the filename is hashed from it. Change it to force a fresh segmentation run.
- force_refresh - True to ignore the cache and regenerate/overwrite.
- name_prefix - optional path prefix under
output/BrainDead_Cache/.
Outputs: mask (MASK) and status (STRING). Wire mask into whatever consumes masks downstream - inpaint setups, the BD parts pipeline, a mask-flatten for game textures - and it behaves as a passthrough.
The workflow shape
[SAM3 / human parser / rmbg] → [BD Cache Mask] → [inpaint or composite chain]
cache_name: "character_cutout"
seed: 42
The first run pays for the segmentation and writes the PNG. Every run after that - including the ones where you change nothing but the sampler seed two branches over - skips the segmentation model entirely. If you're iterating on an inpaint where the mask is the one thing you don't want to change, this is exactly the node.
Installing it
Part of BizaNator/ComfyUI-BrainDead (BrainDeadGuild). ComfyUI Manager → search "BrainDead" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/BizaNator/ComfyUI-BrainDead
cd ComfyUI-BrainDead
pip install -r requirements.txt
Restart; it's under 🧠BrainDead/Cache.
Gotchas
The seed-keying trap from the rest of the family applies: change the source image but not the cache seed and you'll get the old mask back with zero warnings. That's not a bug, it's the feature - but it's why you want to wire your workflow seed into the cache seed when the mask genuinely depends on the image. Also, since the mask input is optional, it's easy to build a graph where the mask source is long gone and the cache is doing all the work. That's fine - just remember that "delete the cache file" (via BD Clear Cache) is how you get the upstream back in the loop.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| cache_name | STRING | cached_mask | — |
| seed | INT | 00–18446744073709550000 | — |
| force_refresh | BOOLEAN | false | Force regeneration even if cache exists |
| maskopt | MASK | Input mask - optional when cache exists | |
| name_prefixopt | STRING | Prefix for cache filename |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| status | STRING | — |