Skip to content

Commit

Permalink
Merge pull request #2 from keisen/develop
Browse files Browse the repository at this point in the history
Release v0.2.0
  • Loading branch information
keisen authored Jan 29, 2020
2 parents 5ec083f + 54302c5 commit 65478b5
Show file tree
Hide file tree
Showing 24 changed files with 982 additions and 549 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ venv.bak/

# Add by keisen
*.swp
examples/**/*.gif
examples/core*
examples/sandbox.ipynb
/*.ipynb
.node-version
*.nbconvert.ipynb
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
dist: xenial
branches:
except:
- gh-pages
language: python
python:
- "3.5"
- "3.6"
- "3.7"
env:
- TF_VERSION=2.0.0 TF_KERAS_VIS_MAX_STEPS=3
- TF_VERSION=2.0.1 TF_KERAS_VIS_MAX_STEPS=3
- TF_VERSION=2.1.0 TF_KERAS_VIS_MAX_STEPS=3
install:
- pip install -U pip
- pip install -U --force-reinstall -e .[development,examples] tensorflow==$TF_VERSION
script:
- PYTHONPATH=$PWD:$PYTHONPATH py.test
- jupyter-nbconvert --ExecutePreprocessor.timeout=600 --to notebook --execute examples/attentions.ipynb
- jupyter-nbconvert --ExecutePreprocessor.timeout=600 --to notebook --execute examples/visualize_dense_layer.ipynb
- jupyter-nbconvert --ExecutePreprocessor.timeout=600 --to notebook --execute examples/visualize_conv_filters.ipynb
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM tensorflow/tensorflow:2.1.0-py3

# Default ENV Settings
ARG TF_KERAS_VIS_VERSION=0.2.0

# Setting for jupyter
RUN export JUPYTER_HOME=/root/.jupyter && \
export JUPYTER_CONF=$JUPYTER_HOME/jupyter_notebook_config.py && \
mkdir -p $JUPYTER_HOME && \
touch $JUPYTER_CONF && \
echo 'c.NotebookApp.allow_root = True' >> $JUPYTER_CONF && \
echo 'c.NotebookApp.ip = "0.0.0.0"' >> $JUPYTER_CONF && \
echo 'c.NotebookApp.token = ""' >> $JUPYTER_CONF

# Install essential python libraries
RUN pip install --no-cache-dir \
tf-keras-vis==$TF_KERAS_VIS_VERSION \
numpy scipy imageio pillow \
jupyterlab matplotlib
19 changes: 19 additions & 0 deletions Dockerfile-gpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM tensorflow/tensorflow:2.1.0-gpu-py3

# Default ENV Settings
ARG TF_KERAS_VIS_VERSION=0.2.0

# Setting for jupyter
RUN export JUPYTER_HOME=/root/.jupyter && \
export JUPYTER_CONF=$JUPYTER_HOME/jupyter_notebook_config.py && \
mkdir -p $JUPYTER_HOME && \
touch $JUPYTER_CONF && \
echo 'c.NotebookApp.allow_root = True' >> $JUPYTER_CONF && \
echo 'c.NotebookApp.ip = "0.0.0.0"' >> $JUPYTER_CONF && \
echo 'c.NotebookApp.token = ""' >> $JUPYTER_CONF

# Install essential python libraries
RUN pip install --no-cache-dir \
tf-keras-vis==$TF_KERAS_VIS_VERSION \
numpy scipy imageio pillow \
jupyterlab matplotlib
42 changes: 16 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# tf-keras-vis
tf-keras-vis is a visualization toolkit for debugging Keras models with Tensorflow 2.0, but not original Keras.
[![Downloads](https://pepy.tech/badge/tf-keras-vis)](https://pepy.tech/project/tf-keras-vis)
[![PyPI version](https://badge.fury.io/py/tf-keras-vis.svg)](https://badge.fury.io/py/tf-keras-vis)
[![Build Status](https://travis-ci.org/keisen/tf-keras-vis.svg?branch=master)](https://travis-ci.org/keisen/tf-keras-vis)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

tf-keras-vis is a visualization toolkit for debugging Keras models with Tensorflow2, but not original Keras.

The features of tf-keras-vis are based on [keras-vis](https://github.com/raghakot/keras-vis), but tf-keras-vis's APIs doesn't have compatibility with keras-vis's because, instead of getting it, we prioritized to get following features.

Expand All @@ -16,44 +21,29 @@ And then we will add some algorisms such as below.

## Requirements

* Python 3.6+
* (tensorflow or tensorflow-gpu) >= 2.0
* Python 3.5, 3.6 or 3.7
* tensorflow>=2.0.0


## Installation

* PyPI

```bash
$ pip install tf-keras-vis
$ pip install tf-keras-vis tensorflow
```

* Sources
* Docker

```bash
$ cd tf-keras-vis
$ pip install -e .
```

Or

```bash
$ cd tf-keras-vis
$ python setup.py install
$ docker pull keisen/tf-keras-vis
```


## Usage

T.B.D.

For now, Please see [examples/activation_maximization.ipynb](https://github.com/keisen/tf-keras-vis/blob/master/examples/activation_maximization.ipynb) and [examples/attention.ipynb](https://github.com/keisen/tf-keras-vis/blob/master/examples/attention.ipynb).
When you want to run jupyter notebook, we recommend that install tf-keras-vis such as follow:
For now, Please see [examples/attentions.ipynb](https://github.com/keisen/tf-keras-vis/blob/master/examples/attentions.ipynb), [examples/visualize_dense_layer.ipynb](https://github.com/keisen/tf-keras-vis/blob/master/examples/visualize_dense_layer.ipynb) and [examples/visualize_conv_filters.ipynb](https://github.com/keisen/tf-keras-vis/blob/master/examples/visualize_conv_filters.ipynb).

```bash
$ cd tf-keras-vis
$ pip install -e .[examples]
```
T.B.D.


## API Documentation
Expand All @@ -63,6 +53,6 @@ T.B.D

## Known Issues

* With InceptionV3 ActivationMaximization doesn't work well, that's, it might generate meanninglessly bulr image.
* With cascading model gradcam doesn't work well, that's, it might occur some error.
* Unsupport `channels-first` models and datas.
* With InceptionV3, ActivationMaximization doesn't work well, that's, it might generate meanninglessly bulr image.
* With cascading model, Gradcam doesn't work well, that's, it might occur some error.
* Unsupported `channels-first` models and datas.
43 changes: 0 additions & 43 deletions docker/Dockerfile-with-cpu

This file was deleted.

51 changes: 0 additions & 51 deletions docker/Dockerfile-with-gpu

This file was deleted.

383 changes: 0 additions & 383 deletions examples/activation_maximization.ipynb

This file was deleted.

16 changes: 9 additions & 7 deletions examples/attention.ipynb → examples/attentions.ipynb

Large diffs are not rendered by default.

Binary file added examples/images/activation_maximization.0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
209 changes: 209 additions & 0 deletions examples/visualize_conv_filters.ipynb

Large diffs are not rendered by default.

283 changes: 283 additions & 0 deletions examples/visualize_dense_layer.ipynb

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ description-file = README.md
[flake8]
exclude =
.git
.venv
__pycache__
dist/*
docker/*
examples/*
max-line-length = 100
max-complexity = 10
Expand All @@ -18,10 +18,10 @@ spaces_before_comment = 2
[isort]
skip =
.git
.venv
__pycache__
build
deprecated
dist
docker
examples

[pyls]
configurationSources = ['flake8']
Expand All @@ -31,13 +31,12 @@ addopts =
-v
--durations=10
--cache-clear
--cov=ml/
--cov=tf_keras_vis/
--cov-report=term-missing

[coverage:run]
omit =
tests/*
.venv/*
__pycache__/*

[coverage:report]
Expand Down
12 changes: 4 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="tf-keras-vis",
version="0.1.0",
version="0.2.0",
author="keisen",
author_email="[email protected]",
description="Neural network visualization toolkit for tf.keras",
Expand All @@ -18,15 +18,11 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
python_requires='>=3.5, <3.8',
install_requires=['numpy', 'scipy', 'imageio', 'pillow'],
extras_require={
'cpu': ['tensorflow >= 2.0'],
'gpu': ['tensorflow-gpu >= 2.0'],
'development': [
'flake8', 'isort==4.3.*', 'yapf==0.28.*', 'pytest', 'pytest-pep8', 'pytest-xdist',
'pytest-cov'
],
'development':
['flake8', 'isort', 'yapf', 'pytest', 'pytest-pep8', 'pytest-xdist', 'pytest-cov'],
'examples': ['jupyterlab', 'matplotlib'],
},
include_package_data=True,
Expand Down
40 changes: 40 additions & 0 deletions tests/tf-keras-vis/test__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import numpy as np
import pytest
import tensorflow as tf
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential

from tf_keras_vis import ModelVisualization


@pytest.fixture(scope="function", autouse=True)
def model():
return Sequential([Dense(5, input_shape=(3, )), Dense(2, activation='softmax')])


class MockVisualizer(ModelVisualization):
def __call__(self):
pass


def change_activation(model):
model.layers[-1].activation = tf.keras.activations.linear


def test__init__(model):
mock = MockVisualizer(model)
assert mock.model != model
assert np.array_equal(mock.model.get_weights()[0], model.get_weights()[0])

mock = MockVisualizer(model, clone=False)
assert mock.model == model

mock = MockVisualizer(model, change_activation)
assert mock.model != model
assert mock.model.layers[-1].activation == tf.keras.activations.linear
assert model.layers[-1].activation == tf.keras.activations.softmax

another_model = Sequential([Dense(5, input_shape=(3, ))])
mock = MockVisualizer(model, lambda m: another_model)
assert mock.model != model
assert mock.model == another_model
Loading

0 comments on commit 65478b5

Please sign in to comment.