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

本站现有博文321篇,共被浏览776948

本站已经建立2468天!

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