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

本站现有博文322篇,共被浏览792761

本站已经建立2489天!

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