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

本站现有博文327篇,共被浏览832728

本站已经建立2537天!

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