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

本站现有博文324篇,共被浏览808901

本站已经建立2511天!

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