yarahal / keravis

A high-level API for feature visualizations in Keras

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

keravis

keravis is a high-level API for CNN visualizations in Keras. It supports visualizations of:

  1. Convolutional layer activations
  2. Feature space visualizations
  3. Saliency maps
  4. Class model visualizations
  5. Feature visualizations through image patches

with support for nested pretrained models.

This is a hobby project and is not optimized for serious use.

Installation

You can install keravis using pip

pip install keravis

Sample Visualizations

Feature Space Visualizations

A t-SNE visualization of the feature space of the penultimate layer of a small CNN trained on MNIST is shown below

from keravis import feature_space
feature_space(model,X=x_test[:5000],y=y_test[:5000],kind='tsne')

tsne1

Saliency Maps

Saliency maps of samples of ImageNet through VGG16 are shown below

Guided Backprop
from keravis import saliency_guided_backprop
saliency_guided_backprop(model,test_img,class_idx=test_label,vistype='next')

saliency_guided_vgg saliency_guided_vgg2

Guided Grad-CAM
from keravis import saliency_grad_cam
saliency_grad_cam(model,test_img,class_idx=test_label,vistype='overlay')

saliency_gradcam_vgg4 saliency_gradcam_vgg3

Occlusion
from keravis import saliency_occlusion
saliency_occlusion(model,test_img,class_idx=test_label,vistype='overlay')

saliency_occlusion_vgg2 saliency_occlusion_vgg

Class Model Visualizations

Class score maximization on VGG16

from keravis import class_model
class_model(model,class_idx=14)

class_model_vgg_14_5 class_model_vgg_14_4

Feature Visualizations

Image patches which maximally activate a neuron in a small CNN trained on MNIST are shown below

from keravis import image_patches
image_patches(model,'conv2d_1',X=x_test)

image

References

[1] Simonyan, Karen, Andrea Vedaldi, and Andrew Zisserman. "Deep inside convolutional networks: Visualising image classification models and saliency maps." arXiv preprint arXiv:1312.6034 (2013).
[2] Selvaraju, Ramprasaath R., et al. "Grad-cam: Visual explanations from deep networks via gradient-based localization." Proceedings of the IEEE international conference on computer vision. 2017.
[3] Zeiler, Matthew D., and Rob Fergus. "Visualizing and understanding convolutional networks." European conference on computer vision. Springer, Cham, 2014.

About

A high-level API for feature visualizations in Keras

License:GNU General Public License v3.0


Languages

Language:Python 100.0%