cam-generation
Routes core pytorch-grad-cam heatmap generation, target layer selection, smoothing, guided backprop, and safe smoke-test workflows.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- cam-generation
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Routes core pytorch-grad-cam heatmap generation, target layer selection, smoothing, guided backprop, and safe smoke-test workflows.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/cam-workflows.md3.1 KB
- 参考文档references/troubleshooting.md1.9 KB
- 脚本scripts/tiny_cam_smoke.py2.7 KB
03 SKILL.md 正文
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.mdfor the core GradCAM pattern, target layer choices, smoothing, guided backprop, batch behavior, and output validation. - Read
references/troubleshooting.mdwhen a CAM is blank, slow, wrong-shaped, on the wrong device, or leaking hooks. - Run
scripts/tiny_cam_smoke.pyto verify the installed package with a tiny in-memory CNN and no external weights.
Core workflow
-
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=Nonefor 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
withblock: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 isnp.float32in[0, 1].
Common decisions
- Use
aug_smooth=Truefor test-time augmentation smoothing; expect slower runtime. - Use
eigen_smooth=Trueto denoise by projectingactivations * weights. - Set
cam.batch_sizeforScoreCAMandAblationCAMbecause 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-adaptationbecause 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.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).