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

本站现有博文320篇,共被浏览759224

本站已经建立2427天!

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