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

本站现有博文323篇,共被浏览795878

本站已经建立2493天!

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