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

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

本站已经建立2719天!

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