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

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

本站已经建立2616天!

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