Giter Site home page Giter Site logo

grad-cam-pytorch's Introduction

Grad-CAM with PyTorch

PyTorch implementation of Grad-CAM (Gradient-weighted Class Activation Mapping) [1]. Grad-CAM localizes and highlights discriminative regions that convolutional neural networks-based models activate to predict visual concepts. This repo contains only an implementation for image classification models.

Dependencies

  • Python 2.7
  • PyTorch 0.2.0
  • torchvision
  • click
  • opencv

Usage

python main.py --help
  • --image-path: a path to an image (required)
  • --arch: a model name from torchvision.models, e.g., 'resnet152' (required)
  • --topk: the number of classes to generate (default: 3)
  • --cuda/--no-cuda: GPU or CPU

The command above generates, for top k classes:

  • Vanilla backproped gradients
  • Guided backproped gradients
  • Deconvolved gradients
  • Grad-CAM
  • Guided Grad-CAM

The guided-* do not support F.relu but only nn.ReLU in this codes. For instance, off-the-shelf inception_v3 cannot cut off negative gradients during backward operation (#2).

Examples

layer4.2 of torchvision.models.resnet152

bull mastiff tiger cat boxer
Probability 0.54285 0.19302 0.10428
Grad-CAM [1]
Vanilla backpropagation
"Deconvnet" [2]
Guided backpropagation [2]
Guided Grad-CAM [1]

Grad-CAM visualization of bull mastiff

Model resnet152 vgg19 vgg19_bn inception_v3 densenet201
Input 224x224 224x224 224x224 299x299 224x224
Grad-CAM [1]

References

[1] R. R. Selvaraju, A. Das, R. Vedantam, M. Cogswell, D. Parikh, and D. Batra. "Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization". arXiv, 2016
[2] J. T. Springenberg, A. Dosovitskiy, T. Brox, and M. Riedmiller. "Striving for Simplicity: The All Convolutional Net". arXiv, 2014

grad-cam-pytorch's People

Contributors

kazuto1011 avatar

Watchers

Gromit Park avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.