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

本站现有博文336篇,共被浏览946770

本站已经建立2657天!

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