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

本站现有博文309篇,共被浏览730961

本站已经建立2367天!

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