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

本站现有博文311篇,共被浏览740093

本站已经建立2377天!

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