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

本站现有博文338篇,共被浏览970742次

本站已经建立2682天!

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