Skip to content
Back to skills

Cam Generation

ASecurity

"Routes core pytorch-grad-cam heatmap generation, target layer

  • 247 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 9, 2026
testingpythonapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned September 9, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill cam-generation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cam Generation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cam Generation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-cam-generation/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-cam-generation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cam-generation
description: "Routes core pytorch-grad-cam heatmap generation, target layer
  selection, smoothing, guided backprop, and safe smoke-test workflows."
disable-model-invocation: true
metadata:
  disco-role: operating
license: MIT
---

# CAM Generation

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.

## First read/run

- Read [`references/cam-workflows.md`](references/cam-workflows.md) for the
  core GradCAM pattern, target layer choices, smoothing, guided backprop, batch
  behavior, and output validation.
- Read [`references/troubleshooting.md`](references/troubleshooting.md) when a
  CAM is blank, slow, wrong-shaped, on the wrong device, or leaking hooks.
- Run [`scripts/tiny_cam_smoke.py`](scripts/tiny_cam_smoke.py) to verify the
  installed package with a tiny in-memory CNN and no external weights.

## Core workflow

1. Put the model in `eval()` mode and choose one or more spatial target layers.
2. Prepare an input tensor shaped like the model expects, usually `B x C x H x W`.
3. 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)]`.
4. Construct the CAM object once, preferably in a `with` block:

   ```python
   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)
   ```

5. Overlay a single CAM using `show_cam_on_image`, ensuring the base image is
   `np.float32` in `[0, 1]`.

## Common decisions

- Use `aug_smooth=True` for test-time augmentation smoothing; expect slower
  runtime.
- Use `eigen_smooth=True` to denoise by projecting `activations * weights`.
- Set `cam.batch_size` for `ScoreCAM` and `AblationCAM` because they perform
  many forward passes.
- Use a list of target layers when uncertain; outputs are averaged across
  selected layers.
- Route ViT/Swin/CLIP, detection, segmentation, and embeddings to
  `model-task-adaptation` because they need reshape transforms or custom
  target callables.
- Route method tradeoffs and exact signatures to `methods-and-api`.
- Route ROAD/ARCC/DFF and explanation scoring to `metrics-and-evaluation`.

Files in this skill

  • SKILL.md2.5 KB
  • references/cam-workflows.md3.1 KB
  • references/troubleshooting.md1.9 KB
  • scripts/tiny_cam_smoke.py2.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.