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

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

本站已经建立2637天!

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