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

本站现有博文319篇,共被浏览750024

本站已经建立2403天!

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