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

本站现有博文321篇,共被浏览766755

本站已经建立2447天!

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