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

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

本站已经建立2517天!

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