Metadata-Version: 2.1
Name: tf-explain
Version: 0.0.1a0
Summary: Interpretability Callbacks for Tensorflow 2.0
Home-page: https://github.com/sicara/tf-explain
Author: Raphaël Meudec
Author-email: raphaelm@sicara.com
License: MIT
Platform: UNKNOWN
Description-Content-Type: text/markdown
Requires-Dist: opencv-python (>=4.1.0.25)
Provides-Extra: tests
Requires-Dist: black (>=19.3b0) ; extra == 'tests'
Requires-Dist: pylint (>=2.3.1) ; extra == 'tests'
Requires-Dist: pytest (>=5.0.1) ; extra == 'tests'
Requires-Dist: pytest-timeout (>=1.3.3) ; extra == 'tests'
Requires-Dist: pytest-mock (>=1.10.4) ; extra == 'tests'
Requires-Dist: pytest-cov (>=2.7.1) ; extra == 'tests'
Requires-Dist: tox (>=3.13.2) ; extra == 'tests'

# tf-explain

[![Pypi Version](https://img.shields.io/pypi/v/tf-explain.svg)](https://pypi.org/project/tf-explain/)
[![Build Status](https://api.travis-ci.org/sicara/tf-explain.svg?branch=master)](https://travis-ci.org/sicara/tf-explain)
[![Documentation Status](https://readthedocs.org/projects/tf-explain/badge/?version=latest)](https://tf-explain.readthedocs.io/en/latest/?badge=latest)
![Python Versions](https://img.shields.io/badge/python-3.6%20|%203.7-%23EBBD68.svg)
![Tensorflow Versions](https://img.shields.io/badge/tensorflow-2.0.0--beta1-blue.svg)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](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)

### 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)
```

<p align="center">
    <img src="./docs/assets/activations_visualisation.png" width="400" />
</p>


### 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),
        patch_size=4,
        class_index=0,
        output_dir=output_dir,
    ),
]

model.fit(x_train, y_train, batch_size=2, epochs=2, callbacks=callbacks)
```

<div align="center">
    <img src="./docs/assets/occlusion_sensitivity.png" width="200" />
    <p style="color: grey; font-size:small; width:350px;">Occlusion Sensitivity for Tabby class (stripes differentiate tabby cat from other ImageNet cat classes)</p>
</div>

### 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)
```


<p align="center">
    <img src="./docs/assets/grad_cam.png" width="200" />
</p>


## Roadmap

Next features are listed as issues with the `roadmap` label.


