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

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

本站已经建立2583天!

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