Nodes/cgem156-ComfyUI๐ŸŒ/Grad Cam ๐ŸŒ
ComfyUI Node

Grad Cam ๐ŸŒ

See exactly where the tagger is looking when it assigns a tag

By laksjdjfยทCreated 2 years agoยทUpdated about a month agoยท 93
Grad Cam ๐ŸŒ
  • tagger
  • features
  • IMAGE
โ—„target_tagโ–บ
โ—„heat_map_alpha0.30โ–บ
โ—„intepolatebilinearโ–บ
โ—„negativeโ€”โ–บ

Grad-CAM is a classic computer-vision interpretability trick: run a classifier forward, then trace which pixels most influenced its decision for a specific output, and paint that as a heatmap over the original image. This node applies it to WD-tagger - point it at a specific tag, and it shows you exactly where in the image the tagger "looked" to decide that tag applied.

Why you'd actually use this

If you're captioning a LoRA dataset with WD-tagger and it keeps assigning a tag you don't understand - or missing one you expected - this is how you debug it visually instead of guessing. Point Grad-CAM at the confusing tag and you'll often see immediately whether the tagger is keying off the right region (a hairstyle, an accessory) or something dumb and coincidental (background clutter, a watermark). It's a niche tool, but for anyone doing serious dataset auditing before a training run, it turns "the tagger is being weird" into an actual answer.

Inputs and outputs

Required:

  • tagger - a WD_TAGGER from Load Tagger.
  • features - a WD-TAGGER-FEATURES value. This is produced upstream by another node in the same wd-tagger category that runs the tagger over your image and caches its internal activations - not one of the nodes covered in this batch, but you'll find it in the same section of the node menu.
  • target_tag - the specific tag you want explained, as a string (multiline field, but you're typically putting one tag in it).
  • heat_map_alpha - how strongly the heatmap overlay blends over the original image, 0-1, default 0.3.
  • intepolate - the interpolation mode used when the heatmap (computed at lower resolution than your image) gets scaled up to overlay it. Default bilinear.
  • negative - a boolean. Going by the name, this flips the visualization to highlight what pushed the tagger away from target_tag rather than toward it - useful when you want to know why an expected tag didn't fire.

Output is a single IMAGE - your source image with the heatmap composited on top at the alpha you set.

Installing it

ComfyUI Manager, search "cgem156-ComfyUI". Manual clone:

cd ComfyUI/custom_nodes
git clone https://github.com/laksjdjf/cgem156-ComfyUI

Restart ComfyUI. Nothing extra to download for this node specifically - the weight download happens back at Load Tagger.

Common issues

The most common early stumble is wiring order: features doesn't come from Load Tagger directly, it comes from a separate feature-extraction step run over your actual image, so if this node errors complaining about a missing or mismatched input, check that you've actually got that extraction node in the graph feeding it rather than trying to plug WD_TAGGER straight in. Beyond that, this is a genuinely niche corner of the pack with no meaningful community discussion to draw troubleshooting wisdom from - the honest advice is to treat unexpected heatmaps as data rather than bugs. If the highlighted region looks nonsensical for a tag you're confident about, that's often the interesting finding: taggers really do sometimes key off spurious correlations (a signature, a border, a common background element) rather than the thing you assumed, and that's exactly the kind of dataset problem this node exists to surface before it poisons a LoRA training run.

Categorycgem156 ๐ŸŒ/wd-tagger

Inputs (6)

NameTypeDefaultDescription
taggerWD_TAGGERโ€”
featuresWD-TAGGER-FEATURESโ€”
target_tagSTRINGโ€”
heat_map_alphaFLOAT0.300โ€“1โ€”
intepolateCOMBObilinear7 options: nearest, linear, bilinear, bicubic, trilinear, area, +1
negativeBOOLEANโ€”

Outputs (1)

NameTypeDescription
IMAGEIMAGEโ€”