brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
cam-generationRoutes core pytorch-grad-cam heatmap generation, target layer selection, smoothing, guided backprop, and safe smoke-test workflows.
Independent GitHub snapshot · Automated classification · Original documentation governs
Use this sub-skill when a user wants to create class activation maps for a PyTorch image/classification-style model, overlay heatmaps on images, choose class targets, apply smoothing, combine CAM with guided backpropagation, or run a safe no-download smoke test.
references/cam-workflows.md for the
core GradCAM pattern, target layer choices, smoothing, guided backprop, batch
behavior, and output validation.references/troubleshooting.md when a
CAM is blank, slow, wrong-shaped, on the wrong device, or leaking hooks.scripts/tiny_cam_smoke.py to verify the
installed package with a tiny in-memory CNN and no external weights.Put the model in eval() mode and choose one or more spatial target layers.
Prepare an input tensor shaped like the model expects, usually B x C x H x W.
Choose targets. Use targets=None for each batch member's top class, or a
list such as [ClassifierOutputTarget(class_id) for _ in range(batch_size)].
Construct the CAM object once, preferably in a with block:
from pytorch_grad_cam import GradCAM
from pytorch_grad_cam.utils.model_targets import ClassifierOutputTarget
target_layers = [model.layer4[-1]]
targets = [ClassifierOutputTarget(281)]
with GradCAM(model=model, target_layers=target_layers) as cam:
grayscale_cam = cam(input_tensor=input_tensor, targets=targets)
Overlay a single CAM using show_cam_on_image, ensuring the base image is
np.float32 in [0, 1].
aug_smooth=True for test-time augmentation smoothing; expect slower
runtime.eigen_smooth=True to denoise by projecting activations * weights.cam.batch_size for ScoreCAM and AblationCAM because they perform
many forward passes.model-task-adaptation because they need reshape transforms or custom
target callables.methods-and-api.metrics-and-evaluation.