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

本站现有博文320篇,共被浏览759208

本站已经建立2427天!

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