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

本站现有博文332篇,共被浏览892316

本站已经建立2594天!

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