Coder Social home page Coder Social logo

vizgradcam's Introduction

VizGradCAM

VizGradCam is the fastest way to visualize GradCAM in Keras models. GradCAM helps with providing visual explainability of trained models and may serve as an important step in ensuring that engineers observe the regions that contributed to certain inference results.

Most tutorials or function features similar methods but requires the name of the last convolutional layer, performing the upscaling of heatmap and superimposing it on the original image. In this repository, we aim to combine all of those tasks.

Usage

This function can be imported or simply copied out into your script where required. Specific usage can be found in the sample Jupyter Notebook.

"""
Function Parameters:
    model        : Compiled Model with Weights Loaded
    image        : Image to Perform Inference On 
    plot_results : True - Function Plots using PLT
                   False - Returns Heatmap Array
    interpolant  : Interpolant Value that Describes The Superimposition Ratio
                   Between Image and Heatmap
"""
VizGradCAM(model, image, plot_results=True, interpolant=0.5)

Sample Usage

# Import Function
from gradcam import VizGradCAM

# Load Your Favourite Image
test_img = img_to_array(load_img("monkey.jpeg" , target_size=(224,224)))

# Use The Function - Boom!
VizGradCAM(EfficientNetB4(weights="imagenet"), test_img))

Results

plot_results=True plot_results=False

More Information

This function is inspired by Keras' GradCAM tuturial here and the original paper, Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization can be found here.

Tested / Supported Models

This function works with Keras CNN models and most Keras Applications / Based Models. This means that it will work even if you used include_top=False to add your own final dense layers for transfer learning on some of the models listed below. In GradCAM, we are looking to target gradients flowing into the last convolutional layer.

Model Architecture Support Dimension
VGG16 (224,224)
VGG19 (224,224)
DenseNet121 (224,224)
DenseNet169 (224,224)
ResNet50 (224,224)
ResNet101 (224,224)
ResNet152 (224,224)
ResNet50V2 (224,224)
ResNet101V2 (224,224)
ResNet152V2 (224,224)
MobileNet (224,224)
MobileNetV2 (224,224)
Xception (299,299)
InceptionV3 (299,299)
InceptionResNetV2 (299,299)
EfficientNetB0 (224,224)
EfficientNetB1 (240,240)
EfficientNetB2 (260,260)
EfficientNetB3 (300,300)
EfficientNetB4 (380,380)
EfficientNetB5 (456,456)
EfficientNetB6 (528,528)
EfficientNetB7 (600,600)

vizgradcam's People

Contributors

gkeechin avatar

Watchers

 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.