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

本站现有博文333篇,共被浏览922610

本站已经建立2628天!

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