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

本站现有博文337篇,共被浏览961754次

本站已经建立2673天!

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