https://github.com/amir22010/tf-explain
Interpretability Methods for tf.keras models with Tensorflow 2.0
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
✓DOI references
Found 1 DOI reference(s) in README -
✓Academic publication links
Links to: arxiv.org, plos.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.5%) to scientific vocabulary
Last synced: 10 months ago
·
JSON representation
Repository
Interpretability Methods for tf.keras models with Tensorflow 2.0
Basic Info
- Host: GitHub
- Owner: Amir22010
- License: mit
- Language: Python
- Default Branch: master
- Homepage: https://tf-explain.readthedocs.io
- Size: 679 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Fork of sicara/tf-explain
Created almost 7 years ago
· Last pushed almost 7 years ago
https://github.com/Amir22010/tf-explain/blob/master/
# tf-explain
[](https://pypi.org/project/tf-explain/)
[](https://travis-ci.org/sicara/tf-explain)
[](https://tf-explain.readthedocs.io/en/latest/?badge=latest)


[](https://github.com/python/black)
__tf-explain__ implements interpretability methods as Tensorflow 2.0 callbacks to __ease neural network's understanding__.
## Installation
__tf-explain__ is available on PyPi as an alpha release. To install it:
```bash
virtualenv venv -p python3.6
pip install tf-explain
```
tf-explain is compatible with Tensorflow 2. It is not declared as a dependency
to let you choose between CPU and GPU versions. Additionally to the previous install, run:
```bash
# For CPU version
pip install tensorflow==2.0.0-beta1
# For GPU version
pip install tensorflow-gpu==2.0.0-beta1
```
## Available Methods
1. [Activations Visualization](#activations-visualization)
2. [Occlusion Sensitivity](#occlusion-sensitivity)
3. [Grad CAM (Class Activation Maps)](#grad-cam)
4. [SmoothGrad](#smoothgrad)
### Activations Visualization
> Visualize how a given input comes out of a specific activation layer
```python
from tf_explain.callbacks.activations_visualization import ActivationsVisualizationCallback
model = [...]
callbacks = [
ActivationsVisualizationCallback(
validation_data=(x_val, y_val),
layers_name=["activation_1"],
output_dir=output_dir,
),
]
model.fit(x_train, y_train, batch_size=2, epochs=2, callbacks=callbacks)
```
### Occlusion Sensitivity
> Visualize how parts of the image affects neural network's confidence by occluding parts iteratively
```python
from tf_explain.callbacks.occlusion_sensitivity import OcclusionSensitivityCallback
model = [...]
callbacks = [
OcclusionSensitivityCallback(
validation_data=(x_val, y_val),
class_index=0,
patch_size=4,
output_dir=output_dir,
),
]
model.fit(x_train, y_train, batch_size=2, epochs=2, callbacks=callbacks)
```
Occlusion Sensitivity for Tabby class (stripes differentiate tabby cat from other ImageNet cat classes)
### Grad CAM
> Visualize how parts of the image affects neural network's output by looking into the activation maps
From [Grad-CAM: Visual Explanations from Deep Networks
via Gradient-based Localization](https://arxiv.org/abs/1610.02391)
```python
from tf_explain.callbacks.grad_cam import GradCAMCallback
model = [...]
callbacks = [
GradCAMCallback(
validation_data=(x_val, y_val),
layer_name="activation_1",
class_index=0,
output_dir=output_dir,
)
]
model.fit(x_train, y_train, batch_size=2, epochs=2, callbacks=callbacks)
```
### SmoothGrad
> Visualize stabilized gradients on the inputs towards the decision
From [SmoothGrad: removing noise by adding noise](https://arxiv.org/abs/1706.03825)
```python
from tf_explain.callbacks.smoothgrad import SmoothGradCallback
model = [...]
callbacks = [
SmoothGradCallback(
validation_data=(x_val, y_val),
class_index=0,
num_samples=20,
noise=1.,
output_dir=output_dir,
)
]
model.fit(x_train, y_train, batch_size=2, epochs=2, callbacks=callbacks)
```
## Visualizing the results
When you use the callbacks, the output files are created in the `logs` directory.
You can see them in tensorboard with the following command: `tensorboard --logdir logs`
## Roadmap
- [ ] Subclassing API Support
- [ ] Additional Methods
- [ ] [GradCAM++](https://arxiv.org/abs/1710.11063)
- [ ] [Integrated Gradients](https://arxiv.org/abs/1703.01365)
- [ ] [Guided SmoothGrad](https://arxiv.org/abs/1706.03825)
- [ ] [LRP](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0130140)
- [ ] Auto-generated API Documentation & Documentation Testing
Owner
- Name: Amir Khan
- Login: Amir22010
- Kind: user
- Location: India
- Repositories: 3
- Profile: https://github.com/Amir22010
working on developing a state of art AI solutions mainly in computer vision, chat bots and nlp domain. building an awesome AI as a professional developer 😍.