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

本站现有博文332篇,共被浏览875994

本站已经建立2583天!

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