Giter Club home page Giter Club logo

gradcam's Introduction

GradCAM

Tensorflow 2.0 implementation of GradCAM

This is a GradCAM implementation of pretrained models and also custom trained model

output.jpg

Instructions

Select any image and run:

    $ python pretrained_gradcam.py --image images/rugby.jpeg

Pretrained Models

All pretrained models listed below -

 - VGG16 
 - VGG19
 - ResNet50
 - InceptionV3 
 - InceptionResNetV2
 - Xception
 - MobileNet
 - MobileNetV2
 - DenseNet
 - NASNet
 - EfficientNet | Link - https://github.com/qubvel/efficientnet
 
 > NOTE - You need to install `EfficientNet` seperately from the given link because 
   it's not included in keras application.

You can choose any of the above models, default VGG16:

    $ python pretrained_gradcam.py --image images/rugby.jpeg --model VGG16

For specific layer GradCAM run below command:

> model.summary()

Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         [(None, 224, 224, 3)]     0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, 224, 224, 64)      1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, 224, 224, 64)      36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 112, 112, 64)      0         
_________________________________________________________________
block2_conv1 (Conv2D)        (None, 112, 112, 128)     73856     
_________________________________________________________________
block2_conv2 (Conv2D)        (None, 112, 112, 128)     147584    
_________________________________________________________________
block2_pool (MaxPooling2D)   (None, 56, 56, 128)       0         

....
....

Selected the first conv layer of VGG16:

    $ python pretrained_gradcam.py --image images/rugby.jpeg --model VGG16 --layer block1_conv1

Custom Model

Run this command to work with your own trained model:

    $ python custom_gradcam.py --image [image] --model [model] --width [w] --height [h] --layer [layer]

Reference

Grad-CAM: Visualize class activation maps with Keras, TensorFlow, and Deep Learning @pyimagesearch

Thanks ❤️ @jrosebr1


gradcam's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

gradcam's Issues

Why the guided gradients?

Hi, could you explain the use of the guided gradients (below) with respect to the Selvaraju et al. 2019 paper? Do these guided gradients refer to the Guided Backpropagation part? I also don't see you using ReLU at any point?

# compute the guided gradients
castConvOutputs = tf.cast(convOutputs > 0, "float32")
castGrads = tf.cast(grads > 0, "float32")
guidedGrads = castConvOutputs * castGrads * grads

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.