Skip to main content

Keras Explain

This package includes the majority of explanation tools for explaining Keras models predictions. Currently, only models with images on input are supported. It supports following approaches:

Gradient methods:

Model-independent methods:

All approaches are easy to apply to your model in two lines of code. If you have any suggestion for new approaches to be included in the package please do not hesitate to suggest. Also all improvements suggestions, bug reports and bug fixes are welcome.

Right now we are in the process of implementing the following approaches:

  • Meaningful perturbation by Fong et al.
  • Layer-wise relevance propagation - we are adding layers that are not supported yet.

Usage

Gradient methods

GradCam

from keras_explain.grad_cam import GradCam

explainer = GradCam(model, layer=None)
exp = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class
  • layer - (optional) The index (index in model.layers) of the layer which prediction is explained. If not specified the last layer prediction is explained automatically.

Output:

  • exp - explanation. GradCam mark only features which contribute to the classification in a target class.

Guided GradCam

from keras_explain.grad_cam import GuidedGradCam

explainer = GuidedGradCam(model, lyer=None)
exp = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class
  • layer - (optional) The index (index in model.layers) of the layer which prediction is explained. If not specified the last layer prediction is explained automatically.

Output:

  • exp - explanation. GuidedGradCam mark only features which contribute to the classification in a target class.

Guided back-propagation

from keras_explain.guided_bp import GuidedBP

explainer = GuidedBP(model)
exp = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class

Output:

  • exp - explanation. Guided back-propagation mark only features which contribute to the classification in a target class.

Integrated gradients

from keras_explain.integrated_gradients import IntegratedGradients

explainer = IntegratedGradients(model)
exp = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class

Output:

  • exp - explanation. Integrated gradients mark only features which contribute to the classification in a target class.

Saliency

from keras_explain.saliency import Saliency

explainer = Saliency(model, layer=None)
exp = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class
  • layer - (optional) The index (index in model.layers) of the layer which prediction is explained. If not specified the last layer prediction is explained automatically.

Output:

  • exp - explanation. Saliency mark only features which contribute to the classification in a target class.

Layer-wise relevance propagation [BETA]

This approach does not support all layers yet. We are currently implementing missing layers. If you wish you can implement any layer support yourself and submit it as a pull request. Since implementation is very custom any suggestion for improvement is welcome.

from keras_explain.lrp import LRP

explainer = LRP(model)
exp = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class

Output:

  • exp - explanation. LRP mark only features which contribute to the classification in a target class.

###Model independent approaches

Prediction difference

from keras_explain.prediction_diff import PredictionDiff

explainer = PredictionDiff(model)
exp_pos, exp_neg = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class

Output:

  • exp_pos - explanation with marked features which contribute to the classification in a target class.
  • exp_neg - explanation with marked features which contribute against the classification in a target class.

Basic graying out

from keras_explain.graying_out import GrayingOut

explainer = GrayingOut(model)
exp_pos, exp_neg = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class

Output:

  • exp_pos - explanation with marked features which contribute to the classification in a target class.
  • exp_neg - explanation with marked features which contribute against the classification in a target class.

LIME

from keras_explain.lime_ribeiro import Lime

explainer = Lime(model)
exp_pos, exp_neg = explainer.explain(image, target_class)

Parameters:

  • model - Keras model which is explained
  • image - input which prediction is explained
  • target_class - approach explains prediction for a target class

Output:

  • exp_pos - explanation with marked features which contribute to the classification in a target class.
  • exp_neg - explanation with marked features which contribute against the classification in a target class.

Metadata

Release files for keras-explain 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keras-explain 0.0.1
File Size Uploaded
keras-explain-0.0.1.tar.gz 22.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keras-explain 0.0.1
File Interpreter ABI Platform
keras_explain-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.4 kB

Release files / keras-explain-0.0.1.tar.gz

Download URL keras-explain-0.0.1.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0a03f143b7c7965d6024593cb33e158573eb7cc9f6612d04d2f1cea729d9d80f
BLAKE2b-256 checksum
How to use checksums
d635b9b3f20e66b5ec0458112af67565689b3ee77faeb52a12d69ad61cd35ef5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.3

Release files / keras_explain-0.0.1-py3-none-any.whl

Download URL keras_explain-0.0.1-py3-none-any.whl
Size 27.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c517ecfc39e34e5a677479b321f681bedba825196dbd7d34867f6a25bce15e3
BLAKE2b-256 checksum
How to use checksums
1f38bc42ad08465f796e34ac8944762d7e8580f3f31364c49d29cbadf46aa97b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.3

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page