Skip to main content

Architecture visualization of Keras models

Project description

visualkeras

Introduction

Visualkeras is a Python package to help visualize Keras neural network architectures. It allows easy styling to fit most needs. As of now it only supports layered style architecture generation which is great for CNNs (Convolutional Neural Networks).

Installation

To install the current release:

pip install visualkeras

To update visual to the latest version, add --upgrade flag to the above commands.

Usage

Generating neural network architectures is easy:

import visualkeras

model = ...

visualkeras.layered_view(model).show() # display using your system viewer
visualkeras.layered_view(model, to_file='output.png') # write to disk
visualkeras.layered_view(model, to_file='output.png').show() # write and show

To help unerstand some of the most important parameters we are going to use a VGG16 CNN architecture (see example.py).

Default
visualkeras.layered_view(model)

Default view of a VGG16 CNN

Flat Style
visualkeras.layered_view(model, draw_volume=False)

Flat view of a VGG16 CNN

Spacing and logic grouping

The global distance between two layers can be controlled with spacing. To generate logical groups a special dummy keras layer visualkeras.SpacingDummyLayer() can be added.

model = ...
...
model.add(visualkeras.SpacingDummyLayer(spacing=100))
...

visualkeras.layered_view(model, spacing=0)

Spaced and grouped view of a VGG16 CNN

Custom color map

It is possible to provide a custom color map for fill and outline per layer type.

from tensorflow.python.keras.layers import Dense, Conv2D, Flatten, Dropout, MaxPooling2D, ZeroPadding2D
from collections import defaultdict

color_map = defaultdict(dict)
color_map[Conv2D]['fill'] = 'orange'
color_map[ZeroPadding2D]['fill'] = 'gray'
color_map[Dropout]['fill'] = 'pink'
color_map[MaxPooling2D]['fill'] = 'red'
color_map[Dense]['fill'] = 'green'
color_map[Flatten]['fill'] = 'teal'

visualkeras.layered_view(model, color_map=color_map)

Custom colored view of a VGG16 CNN

Hiding layers

Some models may consist of too many layers to visualize or to comprehend the model. In this case it can be helpful to hide (ignore) certain layers of the keras model without modifying it. Visualkeras allows ignoring layers by their type (type_ignore) or index in the keras layer sequence (index_ignore).

visualkeras.layered_view(model, type_ignore=[ZeroPadding2D, Dropout, Flatten])

Simplified view of a VGG16 CNN

Scaling dimensions

Visualkeras computes the size of each layer by the output shape. Values are transformed into pixels. Then, scaling is applied. By default visualkeras will enlarge the x and y dimension and reduce the size of the z dimensions as this has deemed visually most appealing. However, it is possible to control scaling using scale_xy and scale_z. Additionally, to prevent to small or large options minimum and maximum values can be set (min_xy, min_z, max_xy, max_z).

visualkeras.layered_view(model, scale_xy=1, scale_z=1, max_z=1000)

True scale view of a VGG16 CNN Note: Scaled models may hide the true complexity of a layer, but are visually more appealing.

Planned features

  • Translucent layers
  • Graph view for dense networks

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

visualkeras-0.0.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

visualkeras-0.0.1-py3.7.egg (8.3 kB view details)

Uploaded Egg

visualkeras-0.0.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file visualkeras-0.0.1.tar.gz.

File metadata

  • Download URL: visualkeras-0.0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

File hashes

Hashes for visualkeras-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3d578c2fa78a0534a130a16b4bffc4055e241878fc6def3a9ebb35f98400a8e3
MD5 4444a06c3e7899e2e17d00815041b40f
BLAKE2b-256 4fc41b97c60392eb61af27ebdcb9cb7f8540469d9d1dce33e2e9879fb2211586

See more details on using hashes here.

File details

Details for the file visualkeras-0.0.1-py3.7.egg.

File metadata

  • Download URL: visualkeras-0.0.1-py3.7.egg
  • Upload date:
  • Size: 8.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

File hashes

Hashes for visualkeras-0.0.1-py3.7.egg
Algorithm Hash digest
SHA256 266e8bbffbd8f794dd74ea08caee9de44cd72791c2381afbdad48d499a4622c5
MD5 768fc11c97f2c46122fefc261e8883b2
BLAKE2b-256 6818766d0e6ced2db6b5312d305614922935ca18496c41ef6165cb16b3f1ba28

See more details on using hashes here.

File details

Details for the file visualkeras-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: visualkeras-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

File hashes

Hashes for visualkeras-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0020b55e343202151ba58590022a3b13ac08fb3d4355476009c5d2207a299159
MD5 6c53540828be09ba4a329ca99e45de50
BLAKE2b-256 3c7d86ba86f710378e753ed690048710bf917b9121b7c6c5f5b07ec5323c4adc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page