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

本站现有博文338篇,共被浏览984573次

本站已经建立2697天!

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