Metadata-Version: 2.4
Name: visualkeras
Version: 0.3.0
Summary: Architecture visualization of Keras models
Home-page: https://github.com/paulgavrikov/visualkeras
Author: Paul Gavrikov, Santosh Patapati
Author-email: Paul Gavrikov <paul.gavrikov@hs-offenburg.de>, Santosh Patapati <santosh.patapati@stonybrook.edu>
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pillow>=6.2.0
Requires-Dist: numpy>=1.18.1
Requires-Dist: aggdraw>=1.3.11
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: setuptools; extra == "dev"
Requires-Dist: black>=24.0; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"
Requires-Dist: isort>=5.12; extra == "dev"
Requires-Dist: pre-commit>=3.5; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# visualkeras for Keras / TensorFlow

[![Latest Version](https://img.shields.io/pypi/v/visualkeras.svg)](https://pypi.python.org/pypi/visualkeras)
[![Download Count](https://img.shields.io/pypi/dm/visualkeras.svg)](https://pypi.python.org/pypi/visualkeras)
[![CI](https://github.com/paulgavrikov/visualkeras/actions/workflows/ci.yaml/badge.svg)](https://github.com/paulgavrikov/visualkeras/actions/workflows/ci.yaml)
[![Documentation Status](https://readthedocs.org/projects/visualkeras/badge/?version=latest)](https://visualkeras.readthedocs.io/en/latest/?badge=latest)

Visualkeras is a Python package for visualizing Keras and TensorFlow model architectures. It supports several rendering styles, such as classic layered CNN diagrams, node-based visualizations, and LeNet-style visualizations. It is very easy to get started with visualkeras (see Quickstart), but also highly customizable for advanced users. For help in citing this project, refer [here](#citation-header).

[Release notes](https://github.com/paulgavrikov/visualkeras/blob/master/changelog/CHANGELOG.md)

## Installation

Install the latest published release:

```bash
pip install visualkeras
```

Install the latest `master` branch (potentially unstable):

```bash
pip install git+https://github.com/paulgavrikov/visualkeras
```

## Quick Start

```python
import visualkeras

model = ...

visualkeras.layered_view(model).show()
visualkeras.layered_view(model, to_file="model.png")
```

The recommended high-level API is `show(...)`, which selects a renderer by mode:

```python
import visualkeras
from tensorflow.keras import layers
from visualkeras.options import FunctionalOptions

img = visualkeras.show(
    model,
    mode="functional",
    options=FunctionalOptions(
        collapse_enabled=True,
        collapse_rules=[
            {"kind": "layer", "selector": layers.Dense, "repeat_count": 4},
            {
                "kind": "block",
                "selector": [layers.Dense, layers.Dropout],
                "repeat_count": 2,
                "annotation_position": "below",
            },
        ],
    ),
)
```

`show(...)` supports these modes:

- `layered`
- `graph`
- `functional`
- `lenet`

## Renderers

| Renderer | Best for | Entry point |
|---|---|---|
| Layered view | Sequential CNN-style diagrams | `visualkeras.layered_view(model)` |
| Graph view | General node-based visualizations | `visualkeras.graph_view(model)` |
| Functional view | Functional Keras models with multiple modalities, inputs, outputs, streams, etc.; this is the most flexible option | `visualkeras.functional_view(model)` |
| LeNet view | Classic feature map stack diagrams; inspired by [LeNet](https://en.wikipedia.org/wiki/LeNet) | `visualkeras.lenet_view(model)` |

## Examples

We provide basic examples here. Explamples with various options and customizations are covered in **the documentation**: <https://visualkeras.readthedocs.io/>.

### Layered view

```python
import tensorflow as tf
from tensorflow import keras
import visualkeras

model = keras.Sequential([
    keras.layers.Input(shape=(28, 28, 1)),
    keras.layers.Conv2D(32, (3, 3), activation="relu"),
    keras.layers.MaxPooling2D((2, 2)),
    keras.layers.Conv2D(64, (3, 3), activation="relu"),
    keras.layers.Flatten(),
    keras.layers.Dense(10, activation="softmax"),
])

visualkeras.layered_view(model).show()
```

![Default layered view](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/vgg16.png)

### Graph view

```python
import tensorflow as tf
from tensorflow import keras
import visualkeras

model = Sequential([
    Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
    MaxPooling2D((2, 2)),
    Dense(10, activation='softmax')
])

visualkeras.graph_view(model)
```

![Default graph-based view of a simple CNN](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/basic_graph.png)

### Functional view

```python
import tensorflow as tf
from tensorflow import keras
import visualkeras

inputs = keras.Input(shape=(16,))
x = keras.layers.Dense(32, activation='relu')(inputs)
x = keras.layers.Dense(32, activation='relu')(x)
outputs = keras.layers.Dense(10, activation='softmax')(x)

model = keras.Model(inputs=inputs, outputs=outputs)

visualkeras.functional_view(model)
```

![Default functional view of a model with multiple blocks](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/func_block.png)

### LeNet view

```python
import tensorflow as tf
from tensorflow import keras
import visualkeras

model = keras.Sequential([
    keras.layers.Input(shape=(28, 28, 1)),
    keras.layers.Conv2D(6, (5, 5), activation='tanh'),
    keras.layers.MaxPooling2D((2, 2)),
    keras.layers.Conv2D(16, (5, 5), activation='tanh'),
    keras.layers.MaxPooling2D((2, 2)),
    keras.layers.Flatten(),
    keras.layers.Dense(120, activation='tanh'),
    keras.layers.Dense(84, activation='tanh'),
    keras.layers.Dense(10, activation='softmax')
])

visualkeras.lenet_view(model)
```

![Default LeNet-style view](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/lenet.png)

## Documentation

Detailed documentation can be found in the documentation website: <https://visualkeras.readthedocs.io/>.

Particularly useful sections include:

- Quickstart: <https://visualkeras.readthedocs.io/en/latest/quickstart.html>
- Tutorials: <https://visualkeras.readthedocs.io/en/latest/tutorials/index.html>
- Examples: <https://visualkeras.readthedocs.io/en/latest/examples/index.html>
- API reference: <https://visualkeras.readthedocs.io/en/latest/api/index.html>
- Architecture guide: [ARCHITECTURE.md](ARCHITECTURE.md)

## Compatibility

| Scope | Status | Notes |
|---|---|---|
| Core package | Supported | Python 3.9+ |
| `tf.keras` workflows | Supported | Suggested usage |
| Standalone `keras` | Mostly supported | May vary by backend setup; fully supported with TensorFlow backend |

## Citation

If you find this project helpful for your research, please cite it:

```bibtex
@misc{Gavrikov2020VisualKeras,
  author = {Gavrikov, Paul and Patapati, Santosh},
  title = {visualkeras},
  year = {2020},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/paulgavrikov/visualkeras}},
}
```

## Contributing

- Issues: <https://github.com/paulgavrikov/visualkeras/issues>
- Contributing guide: `CONTRIBUTING.MD`
- Architecture guide: `ARCHITECTURE.md`

## Stay Updated

Sign up for the visualkeras mailing list here: <https://forms.gle/7eBZ1jCJ7Xsm6RvA7>

## License

Visualkeras is licensed under the MIT License. See `LICENSE`.
