UI はローカライズ済みです。スキルの紹介と説明文書は選択した言語へ AI が自動翻訳し、コード・コマンド・パス・専門用語は原文のままです。原作者の文書が優先されます。
スキルを探す
開発・技術 · SKILL.md

cam-generation

cam-generation

Routes 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

スキルの説明

GitHub

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

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:

    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.
保存したスキル