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

本站现有博文333篇,共被浏览913645

本站已经建立2616天!

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