EADST

Paddle Class Activation Mapping with PPMA

Paddle Class Activation Mapping with PPMA.

Using Class Activation Mapping(CAM) to check the model explainability and draw the heatmap.

After trained the model with PaddleClas, the following code can be used to check the heatmap of the infer image.

import os
from ppma import cam # pip install ppma 
from ppcls.arch import build_model
import cv2

def heatmap(img_path, config, label=None):
    model = build_model(config)
    # print(model) # check the model blocks and layers
    target_layer = model.blocks6[-1] # last layer from last block                       
    cam_extractor = cam.GradCAMPlusPlus(model, target_layer)
    activation_map = cam_extractor(img_path, label=label)   
    cam_image = cam.overlay(img_path, activation_map)   
    cv2.imwrite("res_{}".format(os.path.basename(img_path)), cam_image)
    print("Finished")


if __name__ == "__main__":
    img_path = 'vw.jpg' 
    # config file YAML "Arch" part
    config = {'Arch': {'name': 'PPLCNet_x1_0', 
                       'pretrained': './output/v9c/PPLCNet_x1_0/latest', 
                       'class_num': 110, 
                       'use_ssld': True, 
                       'lr_mult_list': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], 
                       'infer_add_softmax': False
                      }
             }
    label = 48 # image gound truth
    heatmap(img_path, config, label)

Reference:

Paddle Model Analysis

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
hf Use Translation 第一性原理 PyTorch LLM Clash ModelScope SAM Qwen Bin Knowledge 财报 GIT ChatGPT scipy XGBoost Quantize Card 继承 Qwen2.5 Django 论文速读 VPN Conda Pillow Windows 自我改进 Hilton Vim Freesound Distillation Disk tqdm C++ Animate Python SQL NameSilo Proxy OpenAI TensorFlow WebCrawler COCO CAM JSON 域名 Agent Paper Firewall FastAPI UI HuggingFace 多进程 Michelin Nginx Linux Augmentation Attention Algorithm 关于博主 FlashAttention 个人博客 logger Permission Logo Random RL 公式 ResNet-50 WAN LoRA Bitcoin Breakpoint Search 强化学习 CC Shortcut Llama Password BeautifulSoup Excel Github VGG-16 Data Review 递归学习法 Gemma IndexTTS2 CV 算法题 uwsgi Tiktoken CLAP VSCode Math 证件照 YOLO Bipartite tar 云服务器 git Crawler Hotel Dataset GoogLeNet RGB RAR 签证 FP16 Numpy Heatmap EXCEL BTC FP32 API InvalidArgumentError mmap Baidu v2ray Jetson QWEN Transformers AI HaggingFace BF16 LaTeX transformers 阿里云 GGML Magnet Plate 搞笑 DeepStream 版权 Miniforge CSV 多线程 Quantization uWSGI Diagram 图形思考法 FP64 Markdown llama.cpp Anaconda 音频 Bert diffusers Claude Pickle Image2Text News v0.dev PIP Hungarian MD5 GPTQ 飞书 TensorRT Statistics DeepSeek NLTK Vmess GPT4 Ptyhon Jev TTS 净利润 API网关 Base64 CUDA Streamlit NLP Qwen2 Git Plotly Template 论文 图标 CEIR Docker TSV CTC OpenCV Tensor Land 腾讯云 Harness torchinfo 报税 Pandas SVR Color Sklearn ms-swift SQLite Zip printf Safetensors XML Rebuttal Mixtral OCR Website PDB Google FP8 Domain Tracking LLAMA git-lfs Video Pytorch UNIX Food ONNX Ubuntu Datetime SPIE PyCharm 顶会 icon LeetCode Interview Input Jupyter 长期记忆 Cloudreve PDF Web Paddle
站点统计

本站现有博文340篇,共被浏览1027634次

本站已经建立2721天!

热门文章
文章归档
回到顶部