keras-visualizer


Namekeras-visualizer JSON
Version 3.2.0 PyPI version JSON
download
home_pagehttps://github.com/lordmahyar/keras-visualizer
SummaryA Keras Model Visualizer
upload_time2024-05-09 21:51:04
maintainerNone
docs_urlNone
authorMahyar Amiri
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Keras Visualizer

![LOGO](logo.png)

[![PyPI](https://img.shields.io/pypi/v/keras-visualizer?label=PyPI&logo=pypi&logoColor=FFE873)](https://pypi.org/project/keras-visualizer)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/keras-visualizer?label=Downloads&color=blue)](https://pypistats.org/packages/keras-visualizer)
[![GitHub - License](https://img.shields.io/github/license/mahyar-amiri/django-comment-system?label=License&color=blue)](LICENSE)
[![Virgool.io](https://img.shields.io/static/v1?label=Virgool.io&message=keras-visualizer&color=blue)](https://vrgl.ir/5KSoN)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mahyar-amiri/keras-visualizer/)

A Python Library for Visualizing Keras Models.

## Table of Contents

<!-- TOC -->

* [Keras Visualizer](#keras-visualizer)
    * [Table of Contents](#table-of-contents)
    * [Installation](#installation)
        * [Install](#install)
        * [Upgrade](#upgrade)
    * [Usage](#usage)
    * [Parameters](#parameters)
    * [Settings](#settings)
    * [Examples](#examples)
        * [Example 1](#example-1)
        * [Example 2](#example-2)
        * [Example 3](#example-3)
    * [Supported layers](#supported-layers)

<!-- TOC -->

## Installation

### Install

Use python package manager (pip) to install Keras Visualizer.

```bash
pip install keras-visualizer
```

### Upgrade

Use python package manager (pip) to upgrade Keras Visualizer.

```bash
pip install keras-visualizer --upgrade
```

## Usage

```python
from keras_visualizer import visualizer

# create your model here
# model = ...

visualizer(model, file_format='png')
```

## Parameters

```python
visualizer(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'` or `file_format='pdf'` to save visualization file.
> - use `view=True` to open visualization file.
> - use [settings](#settings) to customize output image.

## Settings

you can customize settings for your output image. here is the default settings dictionary:

```python
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',
    # OUTPUT LAYER
    'OUTPUT_DENSE_COLOR': '#e74c3c',
    'OUTPUT_LAYER_COLOR': 'black',
    'OUTPUT_LAYER_FONT': 'white',
}
```

**Note**:

* set `'MAX_NEURONS': None` to disable max neurons constraint.
* see list of color names [here](https://graphviz.org/doc/info/colors.html).

```python
from keras_visualizer import visualizer

my_settings = {
    'MAX_NEURONS': None,
    'INPUT_DENSE_COLOR': 'teal',
    'HIDDEN_DENSE_COLOR': 'gray',
    'OUTPUT_DENSE_COLOR': 'crimson'
}

# model = ...

visualizer(model, file_format='png', settings=my_settings)
```

## Examples

you can use simple examples as `.py` or `.ipynb` format in [examples directory](examples).

### Example 1

```python
from keras import models, layers
from keras_visualizer import visualizer

model = models.Sequential([
    layers.Dense(64, activation='relu', input_shape=(8,)),
    layers.Dense(6, activation='softmax'),
    layers.Dense(32),
    layers.Dense(9, activation='sigmoid')
])

visualizer(model, file_format='png', view=True)
```

![example 1](examples/example1_output.png)

---

### Example 2

```python
from keras import models, layers
from keras_visualizer import visualizer

model = models.Sequential()
model.add(layers.Conv2D(64, (3, 3), input_shape=(28, 28, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Flatten())
model.add(layers.Dense(3))
model.add(layers.Dropout(0.5))
model.add(layers.Activation('sigmoid'))
model.add(layers.Dense(1))

visualizer(model, file_format='png', view=True)
```

![example 2](examples/example2_output.png)

---

### Example 3

```python
from keras import models, layers
from keras_visualizer import visualizer

model = models.Sequential()
model.add(layers.Embedding(64, output_dim=256))
model.add(layers.LSTM(128))
model.add(layers.Dense(1, activation='sigmoid'))

visualizer(model, file_format='png', view=True)
```

![example 3](examples/example3_output.png)

## Supported layers

[Explore list of **keras layers**](https://keras.io/api/layers/)

1. Core layers
    - [x] Input object
    - [x] Dense layer
    - [x] Activation layer
    - [ ] Embedding layer
    - [ ] Masking layer
    - [ ] Lambda layer

2. Convolution layers
    - [x] Conv1D layer
    - [x] Conv2D layer
    - [x] Conv3D layer
    - [x] SeparableConv1D layer
    - [x] SeparableConv2D layer
    - [x] DepthwiseConv2D layer
    - [x] Conv1DTranspose layer
    - [x] Conv2DTranspose layer
    - [x] Conv3DTranspose layer

3. Pooling layers
    - [x] MaxPooling1D layer
    - [x] MaxPooling2D layer
    - [x] MaxPooling3D layer
    - [x] AveragePooling1D layer
    - [x] AveragePooling2D layer
    - [x] AveragePooling3D layer
    - [x] GlobalMaxPooling1D layer
    - [x] GlobalMaxPooling2D layer
    - [x] GlobalMaxPooling3D layer
    - [x] GlobalAveragePooling1D layer
    - [x] GlobalAveragePooling2D layer
    - [x] GlobalAveragePooling3D layer

4. Reshaping layers
    - [ ] Reshape layer
    - [x] Flatten layer
    - [ ] RepeatVector layer
    - [ ] Permute layer
    - [ ] Cropping1D layer
    - [ ] Cropping2D layer
    - [ ] Cropping3D layer
    - [ ] UpSampling1D layer
    - [ ] UpSampling2D layer
    - [ ] UpSampling3D layer
    - [ ] ZeroPadding1D layer
    - [ ] ZeroPadding2D layer
    - [ ] ZeroPadding3D layer

5. Regularization layers
    - [x] Dropout layer
    - [x] SpatialDropout1D layer
    - [x] SpatialDropout2D layer
    - [x] SpatialDropout3D layer
    - [x] GaussianDropout layer
    - [ ] GaussianNoise layer
    - [ ] ActivityRegularization layer
    - [x] AlphaDropout layer

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lordmahyar/keras-visualizer",
    "name": "keras-visualizer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Mahyar Amiri",
    "author_email": "mmaahhyyaarr@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/16/e6/09f94c01993ddac9ff66ca5933b3a0b0b057431d6c5c1b35c3474c90722d/keras_visualizer-3.2.0.tar.gz",
    "platform": null,
    "description": "# Keras Visualizer\r\n\r\n![LOGO](logo.png)\r\n\r\n[![PyPI](https://img.shields.io/pypi/v/keras-visualizer?label=PyPI&logo=pypi&logoColor=FFE873)](https://pypi.org/project/keras-visualizer)\r\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/keras-visualizer?label=Downloads&color=blue)](https://pypistats.org/packages/keras-visualizer)\r\n[![GitHub - License](https://img.shields.io/github/license/mahyar-amiri/django-comment-system?label=License&color=blue)](LICENSE)\r\n[![Virgool.io](https://img.shields.io/static/v1?label=Virgool.io&message=keras-visualizer&color=blue)](https://vrgl.ir/5KSoN)\r\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mahyar-amiri/keras-visualizer/)\r\n\r\nA Python Library for Visualizing Keras Models.\r\n\r\n## Table of Contents\r\n\r\n<!-- TOC -->\r\n\r\n* [Keras Visualizer](#keras-visualizer)\r\n    * [Table of Contents](#table-of-contents)\r\n    * [Installation](#installation)\r\n        * [Install](#install)\r\n        * [Upgrade](#upgrade)\r\n    * [Usage](#usage)\r\n    * [Parameters](#parameters)\r\n    * [Settings](#settings)\r\n    * [Examples](#examples)\r\n        * [Example 1](#example-1)\r\n        * [Example 2](#example-2)\r\n        * [Example 3](#example-3)\r\n    * [Supported layers](#supported-layers)\r\n\r\n<!-- TOC -->\r\n\r\n## Installation\r\n\r\n### Install\r\n\r\nUse python package manager (pip) to install Keras Visualizer.\r\n\r\n```bash\r\npip install keras-visualizer\r\n```\r\n\r\n### Upgrade\r\n\r\nUse python package manager (pip) to upgrade Keras Visualizer.\r\n\r\n```bash\r\npip install keras-visualizer --upgrade\r\n```\r\n\r\n## Usage\r\n\r\n```python\r\nfrom keras_visualizer import visualizer\r\n\r\n# create your model here\r\n# model = ...\r\n\r\nvisualizer(model, file_format='png')\r\n```\r\n\r\n## Parameters\r\n\r\n```python\r\nvisualizer(model, file_name='graph', file_format=None, view=False, settings=None)\r\n```\r\n\r\n- `model` : a Keras model instance.\r\n- `file_name` : where to save the visualization.\r\n- `file_format` : file format to save 'pdf', 'png'.\r\n- `view` : open file after process if True.\r\n- `settings` : a dictionary of available settings.\r\n\r\n> **Note :**\r\n> - set `file_format='png'` or `file_format='pdf'` to save visualization file.\r\n> - use `view=True` to open visualization file.\r\n> - use [settings](#settings) to customize output image.\r\n\r\n## Settings\r\n\r\nyou can customize settings for your output image. here is the default settings dictionary:\r\n\r\n```python\r\nsettings = {\r\n    # ALL LAYERS\r\n    'MAX_NEURONS': 10,\r\n    'ARROW_COLOR': '#707070',\r\n    # INPUT LAYERS\r\n    'INPUT_DENSE_COLOR': '#2ecc71',\r\n    'INPUT_EMBEDDING_COLOR': 'black',\r\n    'INPUT_EMBEDDING_FONT': 'white',\r\n    'INPUT_GRAYSCALE_COLOR': 'black:white',\r\n    'INPUT_GRAYSCALE_FONT': 'white',\r\n    'INPUT_RGB_COLOR': '#e74c3c:#3498db',\r\n    'INPUT_RGB_FONT': 'white',\r\n    'INPUT_LAYER_COLOR': 'black',\r\n    'INPUT_LAYER_FONT': 'white',\r\n    # HIDDEN LAYERS\r\n    'HIDDEN_DENSE_COLOR': '#3498db',\r\n    'HIDDEN_CONV_COLOR': '#5faad0',\r\n    'HIDDEN_CONV_FONT': 'black',\r\n    'HIDDEN_POOLING_COLOR': '#8e44ad',\r\n    'HIDDEN_POOLING_FONT': 'white',\r\n    'HIDDEN_FLATTEN_COLOR': '#2c3e50',\r\n    'HIDDEN_FLATTEN_FONT': 'white',\r\n    'HIDDEN_DROPOUT_COLOR': '#f39c12',\r\n    'HIDDEN_DROPOUT_FONT': 'black',\r\n    'HIDDEN_ACTIVATION_COLOR': '#00b894',\r\n    'HIDDEN_ACTIVATION_FONT': 'black',\r\n    'HIDDEN_LAYER_COLOR': 'black',\r\n    'HIDDEN_LAYER_FONT': 'white',\r\n    # OUTPUT LAYER\r\n    'OUTPUT_DENSE_COLOR': '#e74c3c',\r\n    'OUTPUT_LAYER_COLOR': 'black',\r\n    'OUTPUT_LAYER_FONT': 'white',\r\n}\r\n```\r\n\r\n**Note**:\r\n\r\n* set `'MAX_NEURONS': None` to disable max neurons constraint.\r\n* see list of color names [here](https://graphviz.org/doc/info/colors.html).\r\n\r\n```python\r\nfrom keras_visualizer import visualizer\r\n\r\nmy_settings = {\r\n    'MAX_NEURONS': None,\r\n    'INPUT_DENSE_COLOR': 'teal',\r\n    'HIDDEN_DENSE_COLOR': 'gray',\r\n    'OUTPUT_DENSE_COLOR': 'crimson'\r\n}\r\n\r\n# model = ...\r\n\r\nvisualizer(model, file_format='png', settings=my_settings)\r\n```\r\n\r\n## Examples\r\n\r\nyou can use simple examples as `.py` or `.ipynb` format in [examples directory](examples).\r\n\r\n### Example 1\r\n\r\n```python\r\nfrom keras import models, layers\r\nfrom keras_visualizer import visualizer\r\n\r\nmodel = models.Sequential([\r\n    layers.Dense(64, activation='relu', input_shape=(8,)),\r\n    layers.Dense(6, activation='softmax'),\r\n    layers.Dense(32),\r\n    layers.Dense(9, activation='sigmoid')\r\n])\r\n\r\nvisualizer(model, file_format='png', view=True)\r\n```\r\n\r\n![example 1](examples/example1_output.png)\r\n\r\n---\r\n\r\n### Example 2\r\n\r\n```python\r\nfrom keras import models, layers\r\nfrom keras_visualizer import visualizer\r\n\r\nmodel = models.Sequential()\r\nmodel.add(layers.Conv2D(64, (3, 3), input_shape=(28, 28, 3), activation='relu'))\r\nmodel.add(layers.MaxPooling2D((2, 2)))\r\nmodel.add(layers.Flatten())\r\nmodel.add(layers.Dense(3))\r\nmodel.add(layers.Dropout(0.5))\r\nmodel.add(layers.Activation('sigmoid'))\r\nmodel.add(layers.Dense(1))\r\n\r\nvisualizer(model, file_format='png', view=True)\r\n```\r\n\r\n![example 2](examples/example2_output.png)\r\n\r\n---\r\n\r\n### Example 3\r\n\r\n```python\r\nfrom keras import models, layers\r\nfrom keras_visualizer import visualizer\r\n\r\nmodel = models.Sequential()\r\nmodel.add(layers.Embedding(64, output_dim=256))\r\nmodel.add(layers.LSTM(128))\r\nmodel.add(layers.Dense(1, activation='sigmoid'))\r\n\r\nvisualizer(model, file_format='png', view=True)\r\n```\r\n\r\n![example 3](examples/example3_output.png)\r\n\r\n## Supported layers\r\n\r\n[Explore list of **keras layers**](https://keras.io/api/layers/)\r\n\r\n1. Core layers\r\n    - [x] Input object\r\n    - [x] Dense layer\r\n    - [x] Activation layer\r\n    - [ ] Embedding layer\r\n    - [ ] Masking layer\r\n    - [ ] Lambda layer\r\n\r\n2. Convolution layers\r\n    - [x] Conv1D layer\r\n    - [x] Conv2D layer\r\n    - [x] Conv3D layer\r\n    - [x] SeparableConv1D layer\r\n    - [x] SeparableConv2D layer\r\n    - [x] DepthwiseConv2D layer\r\n    - [x] Conv1DTranspose layer\r\n    - [x] Conv2DTranspose layer\r\n    - [x] Conv3DTranspose layer\r\n\r\n3. Pooling layers\r\n    - [x] MaxPooling1D layer\r\n    - [x] MaxPooling2D layer\r\n    - [x] MaxPooling3D layer\r\n    - [x] AveragePooling1D layer\r\n    - [x] AveragePooling2D layer\r\n    - [x] AveragePooling3D layer\r\n    - [x] GlobalMaxPooling1D layer\r\n    - [x] GlobalMaxPooling2D layer\r\n    - [x] GlobalMaxPooling3D layer\r\n    - [x] GlobalAveragePooling1D layer\r\n    - [x] GlobalAveragePooling2D layer\r\n    - [x] GlobalAveragePooling3D layer\r\n\r\n4. Reshaping layers\r\n    - [ ] Reshape layer\r\n    - [x] Flatten layer\r\n    - [ ] RepeatVector layer\r\n    - [ ] Permute layer\r\n    - [ ] Cropping1D layer\r\n    - [ ] Cropping2D layer\r\n    - [ ] Cropping3D layer\r\n    - [ ] UpSampling1D layer\r\n    - [ ] UpSampling2D layer\r\n    - [ ] UpSampling3D layer\r\n    - [ ] ZeroPadding1D layer\r\n    - [ ] ZeroPadding2D layer\r\n    - [ ] ZeroPadding3D layer\r\n\r\n5. Regularization layers\r\n    - [x] Dropout layer\r\n    - [x] SpatialDropout1D layer\r\n    - [x] SpatialDropout2D layer\r\n    - [x] SpatialDropout3D layer\r\n    - [x] GaussianDropout layer\r\n    - [ ] GaussianNoise layer\r\n    - [ ] ActivityRegularization layer\r\n    - [x] AlphaDropout layer\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Keras Model Visualizer",
    "version": "3.2.0",
    "project_urls": {
        "Homepage": "https://github.com/lordmahyar/keras-visualizer"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c807717bc527b756b10e60dcbdd5b457a0adb6df3315e0d3845fe05c7c22d772",
                "md5": "60c39997476406b3fb91702a471b52ce",
                "sha256": "28236f7726a560da8063b6db348dc162088770fdd46601d88666a87bf2c0b869"
            },
            "downloads": -1,
            "filename": "keras_visualizer-3.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "60c39997476406b3fb91702a471b52ce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7079,
            "upload_time": "2024-05-09T21:51:00",
            "upload_time_iso_8601": "2024-05-09T21:51:00.243466Z",
            "url": "https://files.pythonhosted.org/packages/c8/07/717bc527b756b10e60dcbdd5b457a0adb6df3315e0d3845fe05c7c22d772/keras_visualizer-3.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "16e609f94c01993ddac9ff66ca5933b3a0b0b057431d6c5c1b35c3474c90722d",
                "md5": "30ad338abcfc0ea3790d4410b6277e4e",
                "sha256": "4b175e62958ca4ae1733c57fc11d983a0907a0e78367da42705d9375f86fa503"
            },
            "downloads": -1,
            "filename": "keras_visualizer-3.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "30ad338abcfc0ea3790d4410b6277e4e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 613613,
            "upload_time": "2024-05-09T21:51:04",
            "upload_time_iso_8601": "2024-05-09T21:51:04.686453Z",
            "url": "https://files.pythonhosted.org/packages/16/e6/09f94c01993ddac9ff66ca5933b3a0b0b057431d6c5c1b35c3474c90722d/keras_visualizer-3.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-09 21:51:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lordmahyar",
    "github_project": "keras-visualizer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "keras-visualizer"
}
        
Elapsed time: 0.24672s