jzhoubu / XAI-Project

Visualizer designed for human-eye to understand what CNN focus on during a classification task.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Human-eye on Deep Learning

Background

Hi, all, thanks for your interest.
This is my indepedent project at HKUST under supervision of Prof. Huamin Qu during 2018 Fall.

In 2018, we've come to the 5th year landmark of deep learning really starting to hit the mainstream. However, for the majority of people outside the academia, deep learning is still remaining as a mystory, a black box algorithm.
Believing deep learning makes much more sense only when it is trusted for the whole human being community, we build tools to help people visualize and understand what a deep learning model is doing during an image classification task.

Summary

This repo is designed for human-eye to visualize what excatly a CNN network focus on during an image classification task.
VIS is a tool which helps people visualize features inseide CNN model. This package include three advanced methods: ClassActivationMaps, SaliencyMaps, and GuidedBackPropagation.

News

  • Update(09/29/2018): Add Class Activation Maps module
  • Update(10/01/2018): Add Class Activation Maps demo to Gallery
  • Update(10/02/2018): Add Saliency Maps module
  • Update(10/03/2018): Add Saliency Maps demo to Gallery
  • Update(10/04/2018): Add Guided BackPropagation module
  • Update(10/04/2018): Add Guided BackPropagation demo to Gallery
  • Update(10/05/2018): Update Research Record
  • Update(11/05/2018): Add a practical case for 5002A3 [Link]
  • Update(1/12/2019): Add Usage module

Gallery

Class Activation Mapping [Paper]

Original image Probs: 0.670
Class: {mountain bike, all-terrain bike, off-roader}
Probs: 0.138
Class: {bicycle-built-for-two, tandem bicycle, tandem}
Probs: 0.066
Class: {unicycle, monocycle}
Probs: 0.045
Class: {seashore, coast, seacoast, sea-coast}
Original image
Probs: 0.575
Class: {sundial}
Probs: 0.098
Class: {palace}
Probs: 0.046
Class: {bow}
Probs: 0.045
Class: {stupa, tope}

Saliency Maps [Paper]

Original image Probs: 0.836
Class: {brown bear, bruin, Ursus arctos}
Probs: 0.159
Class: {American black bear, black bear, Ursus americanus, Euarctos americanus}
Probs: 0.003
Class: {sloth bear, Melursus ursinus, Ursus ursinus}
Probs: 0.001
Class: {wombat}
Original image
Probs: 0.938
Class: {bull mastiff}
Probs: 0.058
Class: {boxer}
Probs: 0.001
Class: {French bulldog}
Probs: 0.000
Class: {Brabancon griffon}

Guided BackPropagation [Paper]

Some of my codes is implemented based on utkuozbulak's work. My contributions are listed as below:

  • Fix bugs for up-to-date pytorch version
  • Solve problems for up-to-date CNN model, eg. ResNet, DenseNet
  • Re-organize as a package
Guided BackPropagation Guided BackPropagation with gray scale Guided BackPropagation with positive gradient Guided BackPropagation with negitive gradient
DenseNet 161
ResNet 152
VGG16_bn
VGG16
AlexNet

Usage

URL='https://raw.githubusercontent.com/utkuozbulak/pytorch-cnn-visualizations/master/input_images/snake.jpg'
image = Image.open(io.BytesIO(requests.get(URL).content))
vis=VIS(image,'resnet152')   # Class Parameters
vis.GuidedBackPropagation(type='norm') # Method Parameters
vis.plot()
Class Parameters:
  --image        input image, required PIL image object
  --model       CNN model,  if string, use a pretrained model from torchvision
  --verbose       bool, whether print information during processing
  --figsize       output figure size, default (18,18)
  --columns        output display columns number, default 5

Metod Parameters:
    ClassActivationMaps(topk=4,ratio=0.3,cm=cv2.COLORMAP_JET)
        --topk        number k of topk prediction, default 4
        --ratio        ratio of heatmap against original image, default 0.3
        --cm       type of heatmap, default cv2.COLORMAP_JET
    SaliencyMaps(topk=4,cm='hot')
        --topk        number k of topk prediction, default 4
        --cm       type of colormap, default 'hot'
    GuidedBackPropagation(topk=1,type='norm')
        --topk        number k of topk prediction, default 4
        --type        type of gradient to pass through, default 'norm'.

Reference

utkuozbulak/pytorch-cnn-visualizations

Sample code for the Class Activation Mapping

Learning Deep Features for Discriminative Localization

DeepTracker: Visualizing the Training Process of Convolutional Neural Networks

About

Visualizer designed for human-eye to understand what CNN focus on during a classification task.


Languages

Language:Python 100.0%