A python package to visualize sequentail tensorflow model archtictures
Project description
Litten
Litten is a python package to visualize sequential Tensorflow(keras) neural network model architectures, Get layers summary in details, visualize conv layers filters and featurmaps.
Installation
To install latest version from PyPi
$ pip install litten
How to use it?
- Create your neural network archtictures
model = keras.models.Sequential(
[
keras.layers.Conv2D(filters = 32, kernel_size = 3, input_shape = [150, 150, 3]),
...
keras.layers.Dense(units = 2, activation = 'softmax')
]
)
# or using functional API
input = keras.Input(shape=(28, 28, 1), name="img")
...
output = keras.layers.Dense(units = 2, activation = 'softmax')(x)
model = keras.Model(input, output, name="Model")
- Import LayersSummary, ModelVisualizer and create objects
from litten import LayersSummary, ModelVisualizer
- To get Layers Summaries
summary = LayersSummary()
summary.show_layers_summaries(model)
Output:
=================================================================================================================
Layer 1: InputLayer | Attributes
----------------------------------------
built : True
sparse : False
ragged : False
batch_size : None
is_placeholder : True
=================================================================================================================
Layer 2: Conv2D | Attributes
----------------------------------------
rank : 2
filters : 16
groups : 1
kernel_size : (3, 3)
strides : (1, 1)
padding : valid
data_format : channels_last
dilation_rate : (1, 1)
activation : <function relu at 0x7f6b7038fee0>
use_bias : True
kernel_initializer : <keras.initializers.initializers_v2.GlorotUniform object at 0x7f6aee189610>
bias_initializer : <keras.initializers.initializers_v2.Zeros object at 0x7f6aee189af0>
kernel_regularizer : None
bias_regularizer : None
kernel_constraint : None
bias_constraint : None
built : True
=================================================================================================================
....
-
To visualize model architecture
ModelVisualizer.visualize_model( show_names=False, show_properties=False, show_connectors=False, pallete='default' )
Example 1
vis = ModelVisualizer(model) vis.visualize_model()
Example 2
vis.visualize_model(show_names=True)
Example 3
vis.visualize_model(show_names=True, show_connectors = True)
Exampel 4
vis.visualize_model(show_names=True, show_connectors = True, show_properties=True)
Example 5 You can choose one from these palettes
default
,red
,green
,blue
,yellow
,brown
,purple
,gray
vis.visualize_model(show_names=True, show_connectors=True, palette=<palette>)
-
To visualize Conv filters
ModelVisualizer.visualize_filters( cmap = 'gray' # matplotlib cmaps )
Example
vis = ModelVisualizer(model) vis.visualize_filters('Blues')
-
To visualize Features map
ModelVisualizer.visualize_featuremap( input_image, cmap = 'gray' # matplotlib cmaps )
Example
vis = ModelVisualizer(model) vis.visualize_featuremap(input_image, 'Blues')
Contributing to litten
To contribute to litten, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <branch_name>
. - Make your changes and commit them:
git commit -m '<commit_message>'
- Push to the original branch:
git push origin <project_name>/<location>
- Create the pull request.
Alternatively see the GitHub documentation on creating a pull request.
License
Open source licensed under the MIT license (see LICENSE file for details).
Tools
- Python
- PIL
- Matplotlib
- pytest
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.