A Python Library for Visualizing Keras Model that covers a variety of Layers
Project description
LayerViz
A Python Library for Visualizing Keras Models covering a variety of Layers.
Table of Contents
Installation
Install
Use python package manager (pip) to install LayerViz.
pip install LayerViz
Upgrade
Use python package manager (pip) to upgrade LayerViz.
pip install LayerViz --upgrade
Usage
from libname imoprt layerviz
# create your model here
# model = ...
layerviz(model, file_format='png')
Parameters
layerviz(model, file_name='graph', file_format=None, view=False, settings=None)
model: a Keras model instance.file_name: where to save the visualization.file_format: file format to save 'pdf', 'png'.view: open file after process if True.settings: a dictionary of available settings.
Note :
- set
file_format='png'orfile_format='pdf'to save visualization file.- use
view=Trueto open visualization file.- use settings to customize output image.
Settings
you can customize settings for your output image. here is the default settings dictionary:
recurrent_layers = ['LSTM', 'GRU']
main_settings = {
# ALL LAYERS
'MAX_NEURONS': 10,
'ARROW_COLOR': '#707070',
# INPUT LAYERS
'INPUT_DENSE_COLOR': '#2ecc71',
'INPUT_EMBEDDING_COLOR': 'black',
'INPUT_EMBEDDING_FONT': 'white',
'INPUT_GRAYSCALE_COLOR': 'black:white',
'INPUT_GRAYSCALE_FONT': 'white',
'INPUT_RGB_COLOR': '#e74c3c:#3498db',
'INPUT_RGB_FONT': 'white',
'INPUT_LAYER_COLOR': 'black',
'INPUT_LAYER_FONT': 'white',
# HIDDEN LAYERS
'HIDDEN_DENSE_COLOR': '#3498db',
'HIDDEN_CONV_COLOR': '#5faad0',
'HIDDEN_CONV_FONT': 'black',
'HIDDEN_POOLING_COLOR': '#8e44ad',
'HIDDEN_POOLING_FONT': 'white',
'HIDDEN_FLATTEN_COLOR': '#2c3e50',
'HIDDEN_FLATTEN_FONT': 'white',
'HIDDEN_DROPOUT_COLOR': '#f39c12',
'HIDDEN_DROPOUT_FONT': 'black',
'HIDDEN_ACTIVATION_COLOR': '#00b894',
'HIDDEN_ACTIVATION_FONT': 'black',
'HIDDEN_LAYER_COLOR': 'black',
'HIDDEN_LAYER_FONT': 'white',
# RECURRENT LAYERS
'RECURRENT_LAYER_COLOR': '#9b59b6',
'RECURRENT_LAYER_FONT': 'white',
# OUTPUT LAYER
'OUTPUT_DENSE_COLOR': '#e74c3c',
'OUTPUT_LAYER_COLOR': 'black',
'OUTPUT_LAYER_FONT': 'white',
}
for layer_type in recurrent_layers:
main_settings[layer_type + '_COLOR'] = '#9b59b6'
settings = {**main_settings, **settings} if settings is not None else {**main_settings}
max_neurons = settings['MAX_NEURONS']
Note:
- set
'MAX_NEURONS': Noneto disable max neurons constraint. - see list of color names here.
my_settings = {
'MAX_NEURONS': None,
'INPUT_DENSE_COLOR': 'teal',
'HIDDEN_DENSE_COLOR': 'gray',
'OUTPUT_DENSE_COLOR': 'crimson'
}
# model = ...
layerviz(model, file_format='png', settings=my_settings)
Sample Usage
📖 Resource: The architecture we're using below is a scaled-down version of VGG-16, a convolutional neural network which came 2nd in the 2014 ImageNet classification competition.
For reference, the model we're using replicates TinyVGG, the computer vision architecture which fuels the CNN explainer webpage.
from keras import models, layers
from libname import layerviz
import tensorflow as tf
model_1 = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(filters=10,
kernel_size=3, # can also be (3, 3)
activation="relu",
input_shape=(224, 224, 3)), # first layer specifies input shape (height, width, colour channels)
tf.keras.layers.Conv2D(10, 3, activation="relu"),
tf.keras.layers.MaxPool2D(pool_size=2, # pool_size can also be (2, 2)
padding="valid"), # padding can also be 'same'
tf.keras.layers.Conv2D(10, 3, activation="relu"),
tf.keras.layers.Conv2D(10, 3, activation="relu"), # activation='relu' == tf.keras.layers.Activations(tf.nn.relu)
tf.keras.layers.MaxPool2D(2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(1, activation="sigmoid") # binary activation output
])
layerviz(model_1, file_name='sample1', file_format='png')
from IPython.display import Image
Image('sample1.png')
Supported layers
-
Core layers
- Input object
- Dense layer
- Activation layer
- Embedding layer
- Masking layer
- Lambda layer
-
Convolution layers
- Conv1D layer
- Conv2D layer
- Conv3D layer
- SeparableConv1D layer
- SeparableConv2D layer
- DepthwiseConv2D layer
- Conv1DTranspose layer
- Conv2DTranspose layer
- Conv3DTranspose layer
-
Pooling layers
- MaxPooling1D layer
- MaxPooling2D layer
- MaxPooling3D layer
- AveragePooling1D layer
- AveragePooling2D layer
- AveragePooling3D layer
- GlobalMaxPooling1D layer
- GlobalMaxPooling2D layer
- GlobalMaxPooling3D layer
- GlobalAveragePooling1D layer
- GlobalAveragePooling2D layer
- GlobalAveragePooling3D layer
-
Reshaping layers
- Reshape layer
- Flatten layer
- RepeatVector layer
- Permute layer
- Cropping1D layer
- Cropping2D layer
- Cropping3D layer
- UpSampling1D layer
- UpSampling2D layer
- UpSampling3D layer
- ZeroPadding1D layer
- ZeroPadding2D layer
- ZeroPadding3D layer
-
Regularization layers
- Dropout layer
- SpatialDropout1D layer
- SpatialDropout2D layer
- SpatialDropout3D layer
- GaussianDropout layer
- GaussianNoise layer
- ActivityRegularization layer
- AlphaDropout layer
-
Recurrent Layers
- LSTM
- GRU
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file LayerViz-0.1.1.tar.gz.
File metadata
- Download URL: LayerViz-0.1.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2efacaf201c6c0a19e1209a8190d04f07ad6dc54ee4791d258c4c395e01ef8d7
|
|
| MD5 |
7de391363ab95d873a4cf87c80381594
|
|
| BLAKE2b-256 |
b9e27057545af5e5ab427ba5ed8757e459aeebf041b9a8eac7b92f108bf4d0f6
|
File details
Details for the file LayerViz-0.1.1-py3-none-any.whl.
File metadata
- Download URL: LayerViz-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7c31a76173e7e4b8f159b3a2a029b4fe1da8a5bcdadf4a20bf7ac872e780e29
|
|
| MD5 |
bd302fb21004b0bed959f4157ec5dfdf
|
|
| BLAKE2b-256 |
0b7ba8b6ad0e5e4a5a915864c97663c78a46899fee59345a36e5698085f315a3
|