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

本站现有博文327篇,共被浏览833643

本站已经建立2538天!

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