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

本站现有博文328篇,共被浏览854809

本站已经建立2562天!

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