Skip to content
Back to skills

Pytorch Grad Cam

ASecurity

"Guides PyTorch grad-cam workflows for class activation maps,

  • 247 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 9, 2026
datapythongobashgitapibackend

Works with

  • cli
  • api

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

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

Scanned September 9, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Pytorch Grad Cam?

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

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

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: pytorch-grad-cam
description: "Guides PyTorch grad-cam workflows for class activation maps,
  model/task adaptation, CAM metrics, method selection, and troubleshooting."
disable-model-invocation: true
metadata:
  disco-role: operating
license: MIT
---

# PyTorch Grad-CAM Repo Skill

Use this repo skill for the `grad-cam` Python distribution, imported as
`pytorch_grad_cam`, when a task involves class activation maps, pixel
attribution, PyTorch vision explainability, CAM method selection, custom model
targets, reshape transforms, ROAD/ARCC metrics, Deep Feature Factorization, or
troubleshooting CAM outputs.

## Package identity and installation

- Install package: `pip install grad-cam`
- Import package: `import pytorch_grad_cam`
- Core dependency family: PyTorch, TorchVision, NumPy, OpenCV, ttach,
  matplotlib, SciPy, scikit-learn, Pillow, tqdm.
- Optional workflow dependencies: `timm` for Swin examples,
  `transformers` for CLIP/HuggingFace examples, vendor packages for HPU.

Minimal public import check:

```bash
python - <<'PY'
from importlib.metadata import version
from pytorch_grad_cam import GradCAM, ScoreCAM, AblationCAM, FinerCAM
print("grad-cam", version("grad-cam"))
print(GradCAM, ScoreCAM, AblationCAM, FinerCAM)
PY
```

For a safe diagnostic that does not download models, run
[`scripts/check_grad_cam_environment.py`](scripts/check_grad_cam_environment.py).
For method names and installed signatures, run
[`scripts/inspect_cam_methods.py`](scripts/inspect_cam_methods.py).

Read [`references/package-overview.md`](references/package-overview.md) for the
verified package surface, dependencies, and workflow map. Read
[`references/troubleshooting.md`](references/troubleshooting.md) when install,
import, optional dependency, device, or source-independence issues appear. Read
[`references/repo-provenance.md`](references/repo-provenance.md) before deciding
whether this skill is stale for another checkout.

## Route map

### Core CAM generation

Read [`sub-skills/cam-generation/SKILL.md`](sub-skills/cam-generation/SKILL.md)
when the task asks to produce Grad-CAM/CAM heatmaps for a PyTorch classifier,
choose target layers, target classes, smoothing options, guided backpropagation,
batch behavior, or a safe single-image smoke test.

Common triggers: "run GradCAM on my model", "overlay a heatmap", "why is my CAM
blank", "use aug_smooth/eigen_smooth", "combine CAM with guided backprop", or
"test GradCAM without downloading ImageNet weights".

### Model/task adaptation

Read
[`sub-skills/model-task-adaptation/SKILL.md`](sub-skills/model-task-adaptation/SKILL.md)
when activations or outputs are not ordinary CNN classification logits: ViT,
Swin, CLIP, HuggingFace vision models, object detection, semantic segmentation,
embeddings/similarity, custom target callables, `reshape_transform`, or
`FasterRCNNBoxScoreTarget` / `SemanticSegmentationTarget`.

### Metrics, evaluation, and factorization

Read
[`sub-skills/metrics-and-evaluation/SKILL.md`](sub-skills/metrics-and-evaluation/SKILL.md)
for ROAD metrics, confidence-change metrics, ARCC, RefineCAM,
Deep Feature Factorization, or tasks that compare/tune explanations rather than
only creating one heatmap.

### Method and API selection

Read [`sub-skills/methods-and-api/SKILL.md`](sub-skills/methods-and-api/SKILL.md)
for expert method tradeoffs, installed class signatures, lifecycle/context
manager behavior, method-specific gotchas, device/backends, FinerCAM,
SegEigenCAM, ShapleyCAM, KPCA-CAM, AblationCAM variants, or low-level API
questions.

## Operating rules

1. Build workflows around a user's model, input tensor, target layer(s), and
   target scalar(s). CAM methods explain a scalar output with respect to a
   spatial activation tensor.
2. Do not rely on original repository examples, notebooks, or images at
   runtime. Use the bundled references and scripts in this skill tree.
3. Prefer safe synthetic checks before downloading pretrained weights or large
   datasets. The bundled smoke scripts use tiny in-memory models and tensors.
4. Treat `ScoreCAM` and `AblationCAM` as potentially expensive because they use
   many forward passes; set `cam.batch_size` deliberately.
5. Use a `with CAMClass(...) as cam:` block when possible so hooks are released.
6. Keep backend claims precise: CPU verifies the core API; CUDA/MPS/HPU require
   matching framework/vendor runtimes for real device execution.
7. If a task needs CLIP/Swin/HuggingFace or external pretrained models, surface
   the optional dependency and network/model-cache requirement before running.

Files in this skill

  • SKILL.md4.5 KB
  • references/package-overview.md3.8 KB
  • references/repo-provenance.md1.4 KB
  • references/repo-routing-metadata.json330 B
  • references/troubleshooting.md2.9 KB
  • scripts/check_grad_cam_environment.py2.6 KB
  • scripts/inspect_cam_methods.py2.1 KB
  • sub-skills/cam-generation/SKILL.md2.5 KB
  • sub-skills/cam-generation/references/cam-workflows.md3.1 KB
  • sub-skills/cam-generation/references/troubleshooting.md1.9 KB
  • sub-skills/cam-generation/scripts/tiny_cam_smoke.py2.7 KB
  • sub-skills/methods-and-api/SKILL.md1.7 KB
  • sub-skills/methods-and-api/references/api-signatures.md2.2 KB
  • sub-skills/methods-and-api/references/backend-and-lifecycle.md1.7 KB
  • sub-skills/methods-and-api/references/methods-reference.md2.4 KB
  • sub-skills/methods-and-api/references/troubleshooting.md1.5 KB
  • sub-skills/metrics-and-evaluation/SKILL.md1.5 KB
  • sub-skills/metrics-and-evaluation/references/metrics-and-factorization.md1.9 KB
  • sub-skills/metrics-and-evaluation/references/refinecam-and-arcc.md1.2 KB
  • sub-skills/metrics-and-evaluation/references/troubleshooting.md1.4 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.