项目作者: ahatamiz

项目描述 :
Model-agnostic Class Activation Map Generator
高级语言: Python
项目地址: git://github.com/ahatamiz/CAMs.git
创建时间: 2020-11-30T17:32:51Z
项目社区:https://github.com/ahatamiz/CAMs

开源协议:Apache License 2.0

下载


Model-agnostic Class Activation Map Generator

This repository contains a model-agnostic module for generating Class Activation Maps (CAMs) in Pytorch.

Our implemented CAM module can be used with any pretrained networks, given the name of the target layer before global average pooling. The demo provided below serves as a working example.

Demo

We have trained a ResNet-34 on STL-10 dataset. Please download the pretrained weights using this link.

You can pass the following arguments:

  1. parser.add_argument('--target_layer', default='layer4', type=str) # Name of the target layer (before the pooling layer)
  2. parser.add_argument('--final_layer', default='fc', type=str) # Name of the last classification layer
  3. parser.add_argument('--device', default='0', type=str) # Desired device id

Simply run the following for the demo:

  1. python main.py --target_layer=layer4 --final_layer=fc --device=0

The following represents the expected outputs using the provided sample test images:

Environment Setup

We have implemented the module in Pytorch (>1.6.0). You can install the requirments by running the following:

  1. pip install -r requirments.txt

Refrence

If you find this code useful, please consider citinng this repository:

  1. @misc{OpenSourceCode1,
  2. author = {Hatamizadeh, Ali},
  3. title = {Model-agnostic Class Activation Map Generator},
  4. year = {2020},
  5. publisher = {GitHub},
  6. journal = {GitHub repository},
  7. howpublished = {\url{https://github.com/ahatamiz/CAMs}}
  8. }