Nodes/creative-code/Gradient Saliency Visualizer
ComfyUI Node

Gradient Saliency Visualizer

See What a Classifier Actually Looked At

By cvlases·Created 6 months ago·Updated 3 months ago· 0
Gradient Saliency Visualizer
  • image
  • saliency_output
  • original_resized
model_namevgg16
methodIntegrated Gradients
output_modeheatmap_overlay
class_index-1
smoothgrad_samples25
smoothgrad_noise0.15
ig_steps50
input_size224
use_smoothgradfalse

If you want to know why a neural net said "labrador" instead of "dachshund," this is the node. Gradient Saliency Visualizer - class SaliencyMap - is the no-frills scientific sibling in the creative-code pack: it runs a gradient-based saliency method on an ImageNet classifier and hands you the raw attention map. No artistic composition modes, no colormap dropdown, no captions. Just the evidence, in a few output styles.

Where the pack's other node (SaliencyArt) turns attention into art, this one treats it as data. It's the one you reach for when you're diagnosing a misclassification, comparing what two architectures latch onto, or just curious what VGG "sees" in a photo of your dog. The mechanism is the same in all three pack nodes: the model is a torchvision CNN (VGG16/19, ResNet50/101, DenseNet121, InceptionV3, MobileNetV3), and the map is the gradient of the model's confidence in a class with respect to each input pixel - high gradient means that pixel pushed the verdict.

The inputs that matter

  • method - the six from the pack: Vanilla Gradients, SmoothGrad, Integrated Gradients, Blur IG, Guided IG, XRAI. Default Integrated Gradients is a solid, principled choice; it traces from a black baseline to the image and accumulates gradients along the way.
  • output_mode - this is what makes the node different from its siblings. heatmap_overlay (default) blends a viridis heatmap over the resized original; grayscale_mask gives you the bare attention map in white-on-black; diverging_mask uses PAIR's diverging colormap, which shows both positive and negative attribution - regions that actively pushed the verdict the other way; overlay_and_mask returns a three-panel strip: original | overlay | grayscale mask.
  • class_index - -1 (default) auto-picks the model's top prediction; set 0–999 to probe any specific ImageNet class.
  • input_size - 224 for most models, but the tooltip says it plainly: use 299 for InceptionV3, which was trained at that resolution.

The knobs you'll actually touch after that: smoothgrad_samples (5–100) and smoothgrad_noise (0.01–0.5) control the SmoothGrad noise-averaging, and ig_steps (10–300) is how many interpolation steps the IG-family methods take - more steps, more accurate, slower. Note use_smoothgrad is off by default here (the art node defaults it on), so your first map may look like static. Flip it on for a cleaner, more readable result.

Outputs and where they go

Two IMAGE outputs. saliency_output is the rendered map - wire it to Preview or Save. original_resized is the input resized to what the model actually consumed (e.g. 224×224), which is genuinely useful: save it next to the map so you can compare at the true resolution rather than your original's.

Installing it

ComfyUI Manager, search creative-code, install. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/cvlases/creative-code-comfyui
pip install saliency torchvision matplotlib

Restart, and it lives under creative-code/explainability. First run pulls the model weights via torchvision (~500MB for VGG16) and caches them; the author developed on an M-series MacBook, so CPU-only is fine. No checkpoint, no manual model files.

Where people get burned

  • You're feeding it a classifier, not a diffusion model. It won't "explain" a Stable Diffusion render - the input is a plain IMAGE and the brain is an ImageNet CNN. If you're trying to attribute a diffusion output, this isn't the tool (gradient saliency doesn't map cleanly onto transformer/diffusion architectures anyway).
  • First run downloads weights. On a fresh install it looks frozen while torchvision fetches a few hundred MB. It's not stuck, it's downloading.
  • XRAI is noticeably slower than the gradient methods, and ig_steps at the max with SmoothGrad on will make you wait. 50 steps is a fine default; drop it if queues feel heavy.
  • Watch the "creative-code" name collision when installing - there's an unrelated GLSL-shader CreativeCode pack with a nearly identical title. Clone cvlases/creative-code-comfyui.
Categorycreative-code/explainability

Inputs (10)

NameTypeDefaultDescription
imageIMAGE
model_nameCOMBOvgg167 options: vgg16, vgg19, resnet50, resnet101, inception_v3, mobilenet_v3_large, +1
methodCOMBOIntegrated Gradients6 options: Vanilla Gradients, SmoothGrad, Integrated Gradients, Blur IG, Guided IG, XRAI
output_modeCOMBOheatmap_overlay4 options: heatmap_overlay, grayscale_mask, diverging_mask, overlay_and_mask
class_indexINT-1-1–999
smoothgrad_samplesINT255–100
smoothgrad_noiseFLOAT0.150.01–0.5
ig_stepsINT5010–300
input_sizeINT224224–512Use 299 for InceptionV3
use_smoothgradoptBOOLEANfalse

Outputs (2)

NameTypeDescription
saliency_outputIMAGE
original_resizedIMAGE