visualkeras 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. visualkeras-0.3.0/MANIFEST.in +1 -0
  2. visualkeras-0.3.0/PKG-INFO +253 -0
  3. visualkeras-0.3.0/README.md +211 -0
  4. {visualkeras-0.2.0 → visualkeras-0.3.0}/requirements-dev.txt +2 -0
  5. {visualkeras-0.2.0 → visualkeras-0.3.0}/setup.cfg +4 -4
  6. visualkeras-0.3.0/setup.py +44 -0
  7. visualkeras-0.3.0/tests/test_alpha_context.py +95 -0
  8. visualkeras-0.3.0/tests/test_caption_clearance.py +106 -0
  9. visualkeras-0.3.0/tests/test_end_to_end_file_output.py +56 -0
  10. visualkeras-0.3.0/tests/test_functional_helpers.py +1502 -0
  11. visualkeras-0.3.0/tests/test_functional_internal_integration.py +86 -0
  12. visualkeras-0.3.0/tests/test_functional_renderer.py +476 -0
  13. visualkeras-0.3.0/tests/test_functional_validation.py +127 -0
  14. visualkeras-0.3.0/tests/test_graph_helpers.py +288 -0
  15. visualkeras-0.3.0/tests/test_graph_renderer.py +308 -0
  16. visualkeras-0.3.0/tests/test_group_font_isolation.py +38 -0
  17. visualkeras-0.3.0/tests/test_group_selectors.py +28 -0
  18. visualkeras-0.3.0/tests/test_layer_utils_helpers.py +481 -0
  19. visualkeras-0.3.0/tests/test_layered_helpers.py +230 -0
  20. visualkeras-0.3.0/tests/test_layered_renderer.py +260 -0
  21. visualkeras-0.3.0/tests/test_lenet_helpers.py +503 -0
  22. visualkeras-0.3.0/tests/test_lenet_renderer.py +150 -0
  23. visualkeras-0.3.0/tests/test_logo_image_sources.py +29 -0
  24. visualkeras-0.3.0/tests/test_option_precedence.py +189 -0
  25. visualkeras-0.3.0/tests/test_option_validation.py +24 -0
  26. visualkeras-0.3.0/tests/test_options.py +429 -0
  27. visualkeras-0.3.0/tests/test_render_regressions.py +240 -0
  28. visualkeras-0.3.0/tests/test_renderer_advanced_paths.py +701 -0
  29. visualkeras-0.3.0/tests/test_shape_compatibility.py +69 -0
  30. visualkeras-0.3.0/tests/test_show.py +245 -0
  31. visualkeras-0.3.0/tests/test_structured_model_outputs.py +57 -0
  32. visualkeras-0.3.0/tests/test_utils_helpers.py +497 -0
  33. visualkeras-0.3.0/tests/test_version.py +30 -0
  34. {visualkeras-0.2.0 → visualkeras-0.3.0}/visualkeras/__init__.py +9 -0
  35. visualkeras-0.3.0/visualkeras/_version.py +1 -0
  36. visualkeras-0.3.0/visualkeras/functional.py +3480 -0
  37. visualkeras-0.3.0/visualkeras/graph.py +834 -0
  38. visualkeras-0.3.0/visualkeras/layer_utils.py +750 -0
  39. visualkeras-0.3.0/visualkeras/layered.py +1558 -0
  40. visualkeras-0.3.0/visualkeras/lenet.py +1681 -0
  41. visualkeras-0.3.0/visualkeras/options.py +421 -0
  42. visualkeras-0.3.0/visualkeras/show.py +116 -0
  43. visualkeras-0.3.0/visualkeras/utils.py +1025 -0
  44. visualkeras-0.3.0/visualkeras.egg-info/PKG-INFO +253 -0
  45. visualkeras-0.3.0/visualkeras.egg-info/SOURCES.txt +47 -0
  46. visualkeras-0.3.0/visualkeras.egg-info/requires.txt +12 -0
  47. visualkeras-0.2.0/.github/ISSUE_TEMPLATE/bug_report.md +0 -28
  48. visualkeras-0.2.0/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  49. visualkeras-0.2.0/.github/workflows/python-publish.yml +0 -36
  50. visualkeras-0.2.0/.github/workflows/stale.yml +0 -27
  51. visualkeras-0.2.0/.travis.yml +0 -14
  52. visualkeras-0.2.0/CITATION.cff +0 -22
  53. visualkeras-0.2.0/CONTRIBUTING.MD +0 -164
  54. visualkeras-0.2.0/PKG-INFO +0 -362
  55. visualkeras-0.2.0/README.md +0 -335
  56. visualkeras-0.2.0/changelog/CHANGELOG.md +0 -102
  57. visualkeras-0.2.0/examples/autoencoder.py +0 -25
  58. visualkeras-0.2.0/examples/dense.py +0 -11
  59. visualkeras-0.2.0/examples/generate_examples.py +0 -3
  60. visualkeras-0.2.0/examples/show_dimension.py +0 -84
  61. visualkeras-0.2.0/examples/usage_examples.md +0 -191
  62. visualkeras-0.2.0/examples/vgg16.py +0 -84
  63. visualkeras-0.2.0/figures/autoencoder.png +0 -0
  64. visualkeras-0.2.0/figures/basic_graph.png +0 -0
  65. visualkeras-0.2.0/figures/draw_shapes_1.png +0 -0
  66. visualkeras-0.2.0/figures/draw_shapes_2.png +0 -0
  67. visualkeras-0.2.0/figures/draw_shapes_3.png +0 -0
  68. visualkeras-0.2.0/figures/draw_text_callable.png +0 -0
  69. visualkeras-0.2.0/figures/encoder.png +0 -0
  70. visualkeras-0.2.0/figures/figure1_layered_basic.png +0 -0
  71. visualkeras-0.2.0/figures/figure2_layered_advanced.png +0 -0
  72. visualkeras-0.2.0/figures/figure3_graph_basic.png +0 -0
  73. visualkeras-0.2.0/figures/figure4_graph_advanced.png +0 -0
  74. visualkeras-0.2.0/figures/normal_view.png +0 -0
  75. visualkeras-0.2.0/figures/professional_diagram_sample.png +0 -0
  76. visualkeras-0.2.0/figures/reversed_view.png +0 -0
  77. visualkeras-0.2.0/figures/sizing_accurate.png +0 -0
  78. visualkeras-0.2.0/figures/sizing_balanced.png +0 -0
  79. visualkeras-0.2.0/figures/sizing_logarithmic.png +0 -0
  80. visualkeras-0.2.0/figures/sizing_relative_base_1.png +0 -0
  81. visualkeras-0.2.0/figures/vgg16.png +0 -0
  82. visualkeras-0.2.0/figures/vgg16_color_map.png +0 -0
  83. visualkeras-0.2.0/figures/vgg16_flat.png +0 -0
  84. visualkeras-0.2.0/figures/vgg16_legend.png +0 -0
  85. visualkeras-0.2.0/figures/vgg16_legend_show_dimension.png +0 -0
  86. visualkeras-0.2.0/figures/vgg16_scaling.png +0 -0
  87. visualkeras-0.2.0/figures/vgg16_spacing_layers.png +0 -0
  88. visualkeras-0.2.0/figures/vgg16_type_ignore.png +0 -0
  89. visualkeras-0.2.0/setup.py +0 -27
  90. visualkeras-0.2.0/tests/README.md +0 -72
  91. visualkeras-0.2.0/tests/conftest.py +0 -168
  92. visualkeras-0.2.0/tests/test_graph.py +0 -5
  93. visualkeras-0.2.0/tests/test_graph_inout_flag.py +0 -29
  94. visualkeras-0.2.0/tests/test_layer_utils.py +0 -47
  95. visualkeras-0.2.0/tests/test_layered.py +0 -5
  96. visualkeras-0.2.0/tests/test_utils.py +0 -84
  97. visualkeras-0.2.0/visualkeras/graph.py +0 -295
  98. visualkeras-0.2.0/visualkeras/layer_utils.py +0 -613
  99. visualkeras-0.2.0/visualkeras/layered.py +0 -583
  100. visualkeras-0.2.0/visualkeras/options.py +0 -228
  101. visualkeras-0.2.0/visualkeras/utils.py +0 -226
  102. visualkeras-0.2.0/visualkeras.egg-info/PKG-INFO +0 -362
  103. visualkeras-0.2.0/visualkeras.egg-info/SOURCES.txt +0 -19
  104. visualkeras-0.2.0/visualkeras.egg-info/requires.txt +0 -3
  105. {visualkeras-0.2.0 → visualkeras-0.3.0}/LICENSE +0 -0
  106. {visualkeras-0.2.0 → visualkeras-0.3.0}/visualkeras.egg-info/dependency_links.txt +0 -0
  107. {visualkeras-0.2.0 → visualkeras-0.3.0}/visualkeras.egg-info/top_level.txt +0 -0
@@ -0,0 +1 @@
1
+ include requirements-dev.txt
@@ -0,0 +1,253 @@
1
+ Metadata-Version: 2.4
2
+ Name: visualkeras
3
+ Version: 0.3.0
4
+ Summary: Architecture visualization of Keras models
5
+ Home-page: https://github.com/paulgavrikov/visualkeras
6
+ Author: Paul Gavrikov, Santosh Patapati
7
+ Author-email: Paul Gavrikov <paul.gavrikov@hs-offenburg.de>, Santosh Patapati <santosh.patapati@stonybrook.edu>
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: pillow>=6.2.0
21
+ Requires-Dist: numpy>=1.18.1
22
+ Requires-Dist: aggdraw>=1.3.11
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
26
+ Requires-Dist: setuptools; extra == "dev"
27
+ Requires-Dist: black>=24.0; extra == "dev"
28
+ Requires-Dist: ruff>=0.5; extra == "dev"
29
+ Requires-Dist: isort>=5.12; extra == "dev"
30
+ Requires-Dist: pre-commit>=3.5; extra == "dev"
31
+ Dynamic: author
32
+ Dynamic: author-email
33
+ Dynamic: classifier
34
+ Dynamic: description
35
+ Dynamic: description-content-type
36
+ Dynamic: home-page
37
+ Dynamic: license-file
38
+ Dynamic: provides-extra
39
+ Dynamic: requires-dist
40
+ Dynamic: requires-python
41
+ Dynamic: summary
42
+
43
+ # visualkeras for Keras / TensorFlow
44
+
45
+ [![Latest Version](https://img.shields.io/pypi/v/visualkeras.svg)](https://pypi.python.org/pypi/visualkeras)
46
+ [![Download Count](https://img.shields.io/pypi/dm/visualkeras.svg)](https://pypi.python.org/pypi/visualkeras)
47
+ [![CI](https://github.com/paulgavrikov/visualkeras/actions/workflows/ci.yaml/badge.svg)](https://github.com/paulgavrikov/visualkeras/actions/workflows/ci.yaml)
48
+ [![Documentation Status](https://readthedocs.org/projects/visualkeras/badge/?version=latest)](https://visualkeras.readthedocs.io/en/latest/?badge=latest)
49
+
50
+ 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).
51
+
52
+ [Release notes](https://github.com/paulgavrikov/visualkeras/blob/master/changelog/CHANGELOG.md)
53
+
54
+ ## Installation
55
+
56
+ Install the latest published release:
57
+
58
+ ```bash
59
+ pip install visualkeras
60
+ ```
61
+
62
+ Install the latest `master` branch (potentially unstable):
63
+
64
+ ```bash
65
+ pip install git+https://github.com/paulgavrikov/visualkeras
66
+ ```
67
+
68
+ ## Quick Start
69
+
70
+ ```python
71
+ import visualkeras
72
+
73
+ model = ...
74
+
75
+ visualkeras.layered_view(model).show()
76
+ visualkeras.layered_view(model, to_file="model.png")
77
+ ```
78
+
79
+ The recommended high-level API is `show(...)`, which selects a renderer by mode:
80
+
81
+ ```python
82
+ import visualkeras
83
+ from tensorflow.keras import layers
84
+ from visualkeras.options import FunctionalOptions
85
+
86
+ img = visualkeras.show(
87
+ model,
88
+ mode="functional",
89
+ options=FunctionalOptions(
90
+ collapse_enabled=True,
91
+ collapse_rules=[
92
+ {"kind": "layer", "selector": layers.Dense, "repeat_count": 4},
93
+ {
94
+ "kind": "block",
95
+ "selector": [layers.Dense, layers.Dropout],
96
+ "repeat_count": 2,
97
+ "annotation_position": "below",
98
+ },
99
+ ],
100
+ ),
101
+ )
102
+ ```
103
+
104
+ `show(...)` supports these modes:
105
+
106
+ - `layered`
107
+ - `graph`
108
+ - `functional`
109
+ - `lenet`
110
+
111
+ ## Renderers
112
+
113
+ | Renderer | Best for | Entry point |
114
+ |---|---|---|
115
+ | Layered view | Sequential CNN-style diagrams | `visualkeras.layered_view(model)` |
116
+ | Graph view | General node-based visualizations | `visualkeras.graph_view(model)` |
117
+ | Functional view | Functional Keras models with multiple modalities, inputs, outputs, streams, etc.; this is the most flexible option | `visualkeras.functional_view(model)` |
118
+ | LeNet view | Classic feature map stack diagrams; inspired by [LeNet](https://en.wikipedia.org/wiki/LeNet) | `visualkeras.lenet_view(model)` |
119
+
120
+ ## Examples
121
+
122
+ We provide basic examples here. Explamples with various options and customizations are covered in **the documentation**: <https://visualkeras.readthedocs.io/>.
123
+
124
+ ### Layered view
125
+
126
+ ```python
127
+ import tensorflow as tf
128
+ from tensorflow import keras
129
+ import visualkeras
130
+
131
+ model = keras.Sequential([
132
+ keras.layers.Input(shape=(28, 28, 1)),
133
+ keras.layers.Conv2D(32, (3, 3), activation="relu"),
134
+ keras.layers.MaxPooling2D((2, 2)),
135
+ keras.layers.Conv2D(64, (3, 3), activation="relu"),
136
+ keras.layers.Flatten(),
137
+ keras.layers.Dense(10, activation="softmax"),
138
+ ])
139
+
140
+ visualkeras.layered_view(model).show()
141
+ ```
142
+
143
+ ![Default layered view](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/vgg16.png)
144
+
145
+ ### Graph view
146
+
147
+ ```python
148
+ import tensorflow as tf
149
+ from tensorflow import keras
150
+ import visualkeras
151
+
152
+ model = Sequential([
153
+ Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
154
+ MaxPooling2D((2, 2)),
155
+ Dense(10, activation='softmax')
156
+ ])
157
+
158
+ visualkeras.graph_view(model)
159
+ ```
160
+
161
+ ![Default graph-based view of a simple CNN](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/basic_graph.png)
162
+
163
+ ### Functional view
164
+
165
+ ```python
166
+ import tensorflow as tf
167
+ from tensorflow import keras
168
+ import visualkeras
169
+
170
+ inputs = keras.Input(shape=(16,))
171
+ x = keras.layers.Dense(32, activation='relu')(inputs)
172
+ x = keras.layers.Dense(32, activation='relu')(x)
173
+ outputs = keras.layers.Dense(10, activation='softmax')(x)
174
+
175
+ model = keras.Model(inputs=inputs, outputs=outputs)
176
+
177
+ visualkeras.functional_view(model)
178
+ ```
179
+
180
+ ![Default functional view of a model with multiple blocks](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/func_block.png)
181
+
182
+ ### LeNet view
183
+
184
+ ```python
185
+ import tensorflow as tf
186
+ from tensorflow import keras
187
+ import visualkeras
188
+
189
+ model = keras.Sequential([
190
+ keras.layers.Input(shape=(28, 28, 1)),
191
+ keras.layers.Conv2D(6, (5, 5), activation='tanh'),
192
+ keras.layers.MaxPooling2D((2, 2)),
193
+ keras.layers.Conv2D(16, (5, 5), activation='tanh'),
194
+ keras.layers.MaxPooling2D((2, 2)),
195
+ keras.layers.Flatten(),
196
+ keras.layers.Dense(120, activation='tanh'),
197
+ keras.layers.Dense(84, activation='tanh'),
198
+ keras.layers.Dense(10, activation='softmax')
199
+ ])
200
+
201
+ visualkeras.lenet_view(model)
202
+ ```
203
+
204
+ ![Default LeNet-style view](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/lenet.png)
205
+
206
+ ## Documentation
207
+
208
+ Detailed documentation can be found in the documentation website: <https://visualkeras.readthedocs.io/>.
209
+
210
+ Particularly useful sections include:
211
+
212
+ - Quickstart: <https://visualkeras.readthedocs.io/en/latest/quickstart.html>
213
+ - Tutorials: <https://visualkeras.readthedocs.io/en/latest/tutorials/index.html>
214
+ - Examples: <https://visualkeras.readthedocs.io/en/latest/examples/index.html>
215
+ - API reference: <https://visualkeras.readthedocs.io/en/latest/api/index.html>
216
+ - Architecture guide: [ARCHITECTURE.md](ARCHITECTURE.md)
217
+
218
+ ## Compatibility
219
+
220
+ | Scope | Status | Notes |
221
+ |---|---|---|
222
+ | Core package | Supported | Python 3.9+ |
223
+ | `tf.keras` workflows | Supported | Suggested usage |
224
+ | Standalone `keras` | Mostly supported | May vary by backend setup; fully supported with TensorFlow backend |
225
+
226
+ ## Citation
227
+
228
+ If you find this project helpful for your research, please cite it:
229
+
230
+ ```bibtex
231
+ @misc{Gavrikov2020VisualKeras,
232
+ author = {Gavrikov, Paul and Patapati, Santosh},
233
+ title = {visualkeras},
234
+ year = {2020},
235
+ publisher = {GitHub},
236
+ journal = {GitHub repository},
237
+ howpublished = {\url{https://github.com/paulgavrikov/visualkeras}},
238
+ }
239
+ ```
240
+
241
+ ## Contributing
242
+
243
+ - Issues: <https://github.com/paulgavrikov/visualkeras/issues>
244
+ - Contributing guide: `CONTRIBUTING.MD`
245
+ - Architecture guide: `ARCHITECTURE.md`
246
+
247
+ ## Stay Updated
248
+
249
+ Sign up for the visualkeras mailing list here: <https://forms.gle/7eBZ1jCJ7Xsm6RvA7>
250
+
251
+ ## License
252
+
253
+ Visualkeras is licensed under the MIT License. See `LICENSE`.
@@ -0,0 +1,211 @@
1
+ # visualkeras for Keras / TensorFlow
2
+
3
+ [![Latest Version](https://img.shields.io/pypi/v/visualkeras.svg)](https://pypi.python.org/pypi/visualkeras)
4
+ [![Download Count](https://img.shields.io/pypi/dm/visualkeras.svg)](https://pypi.python.org/pypi/visualkeras)
5
+ [![CI](https://github.com/paulgavrikov/visualkeras/actions/workflows/ci.yaml/badge.svg)](https://github.com/paulgavrikov/visualkeras/actions/workflows/ci.yaml)
6
+ [![Documentation Status](https://readthedocs.org/projects/visualkeras/badge/?version=latest)](https://visualkeras.readthedocs.io/en/latest/?badge=latest)
7
+
8
+ 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).
9
+
10
+ [Release notes](https://github.com/paulgavrikov/visualkeras/blob/master/changelog/CHANGELOG.md)
11
+
12
+ ## Installation
13
+
14
+ Install the latest published release:
15
+
16
+ ```bash
17
+ pip install visualkeras
18
+ ```
19
+
20
+ Install the latest `master` branch (potentially unstable):
21
+
22
+ ```bash
23
+ pip install git+https://github.com/paulgavrikov/visualkeras
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```python
29
+ import visualkeras
30
+
31
+ model = ...
32
+
33
+ visualkeras.layered_view(model).show()
34
+ visualkeras.layered_view(model, to_file="model.png")
35
+ ```
36
+
37
+ The recommended high-level API is `show(...)`, which selects a renderer by mode:
38
+
39
+ ```python
40
+ import visualkeras
41
+ from tensorflow.keras import layers
42
+ from visualkeras.options import FunctionalOptions
43
+
44
+ img = visualkeras.show(
45
+ model,
46
+ mode="functional",
47
+ options=FunctionalOptions(
48
+ collapse_enabled=True,
49
+ collapse_rules=[
50
+ {"kind": "layer", "selector": layers.Dense, "repeat_count": 4},
51
+ {
52
+ "kind": "block",
53
+ "selector": [layers.Dense, layers.Dropout],
54
+ "repeat_count": 2,
55
+ "annotation_position": "below",
56
+ },
57
+ ],
58
+ ),
59
+ )
60
+ ```
61
+
62
+ `show(...)` supports these modes:
63
+
64
+ - `layered`
65
+ - `graph`
66
+ - `functional`
67
+ - `lenet`
68
+
69
+ ## Renderers
70
+
71
+ | Renderer | Best for | Entry point |
72
+ |---|---|---|
73
+ | Layered view | Sequential CNN-style diagrams | `visualkeras.layered_view(model)` |
74
+ | Graph view | General node-based visualizations | `visualkeras.graph_view(model)` |
75
+ | Functional view | Functional Keras models with multiple modalities, inputs, outputs, streams, etc.; this is the most flexible option | `visualkeras.functional_view(model)` |
76
+ | LeNet view | Classic feature map stack diagrams; inspired by [LeNet](https://en.wikipedia.org/wiki/LeNet) | `visualkeras.lenet_view(model)` |
77
+
78
+ ## Examples
79
+
80
+ We provide basic examples here. Explamples with various options and customizations are covered in **the documentation**: <https://visualkeras.readthedocs.io/>.
81
+
82
+ ### Layered view
83
+
84
+ ```python
85
+ import tensorflow as tf
86
+ from tensorflow import keras
87
+ import visualkeras
88
+
89
+ model = keras.Sequential([
90
+ keras.layers.Input(shape=(28, 28, 1)),
91
+ keras.layers.Conv2D(32, (3, 3), activation="relu"),
92
+ keras.layers.MaxPooling2D((2, 2)),
93
+ keras.layers.Conv2D(64, (3, 3), activation="relu"),
94
+ keras.layers.Flatten(),
95
+ keras.layers.Dense(10, activation="softmax"),
96
+ ])
97
+
98
+ visualkeras.layered_view(model).show()
99
+ ```
100
+
101
+ ![Default layered view](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/vgg16.png)
102
+
103
+ ### Graph view
104
+
105
+ ```python
106
+ import tensorflow as tf
107
+ from tensorflow import keras
108
+ import visualkeras
109
+
110
+ model = Sequential([
111
+ Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
112
+ MaxPooling2D((2, 2)),
113
+ Dense(10, activation='softmax')
114
+ ])
115
+
116
+ visualkeras.graph_view(model)
117
+ ```
118
+
119
+ ![Default graph-based view of a simple CNN](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/basic_graph.png)
120
+
121
+ ### Functional view
122
+
123
+ ```python
124
+ import tensorflow as tf
125
+ from tensorflow import keras
126
+ import visualkeras
127
+
128
+ inputs = keras.Input(shape=(16,))
129
+ x = keras.layers.Dense(32, activation='relu')(inputs)
130
+ x = keras.layers.Dense(32, activation='relu')(x)
131
+ outputs = keras.layers.Dense(10, activation='softmax')(x)
132
+
133
+ model = keras.Model(inputs=inputs, outputs=outputs)
134
+
135
+ visualkeras.functional_view(model)
136
+ ```
137
+
138
+ ![Default functional view of a model with multiple blocks](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/func_block.png)
139
+
140
+ ### LeNet view
141
+
142
+ ```python
143
+ import tensorflow as tf
144
+ from tensorflow import keras
145
+ import visualkeras
146
+
147
+ model = keras.Sequential([
148
+ keras.layers.Input(shape=(28, 28, 1)),
149
+ keras.layers.Conv2D(6, (5, 5), activation='tanh'),
150
+ keras.layers.MaxPooling2D((2, 2)),
151
+ keras.layers.Conv2D(16, (5, 5), activation='tanh'),
152
+ keras.layers.MaxPooling2D((2, 2)),
153
+ keras.layers.Flatten(),
154
+ keras.layers.Dense(120, activation='tanh'),
155
+ keras.layers.Dense(84, activation='tanh'),
156
+ keras.layers.Dense(10, activation='softmax')
157
+ ])
158
+
159
+ visualkeras.lenet_view(model)
160
+ ```
161
+
162
+ ![Default LeNet-style view](https://raw.githubusercontent.com/paulgavrikov/visualkeras/master/figures/lenet.png)
163
+
164
+ ## Documentation
165
+
166
+ Detailed documentation can be found in the documentation website: <https://visualkeras.readthedocs.io/>.
167
+
168
+ Particularly useful sections include:
169
+
170
+ - Quickstart: <https://visualkeras.readthedocs.io/en/latest/quickstart.html>
171
+ - Tutorials: <https://visualkeras.readthedocs.io/en/latest/tutorials/index.html>
172
+ - Examples: <https://visualkeras.readthedocs.io/en/latest/examples/index.html>
173
+ - API reference: <https://visualkeras.readthedocs.io/en/latest/api/index.html>
174
+ - Architecture guide: [ARCHITECTURE.md](ARCHITECTURE.md)
175
+
176
+ ## Compatibility
177
+
178
+ | Scope | Status | Notes |
179
+ |---|---|---|
180
+ | Core package | Supported | Python 3.9+ |
181
+ | `tf.keras` workflows | Supported | Suggested usage |
182
+ | Standalone `keras` | Mostly supported | May vary by backend setup; fully supported with TensorFlow backend |
183
+
184
+ ## Citation
185
+
186
+ If you find this project helpful for your research, please cite it:
187
+
188
+ ```bibtex
189
+ @misc{Gavrikov2020VisualKeras,
190
+ author = {Gavrikov, Paul and Patapati, Santosh},
191
+ title = {visualkeras},
192
+ year = {2020},
193
+ publisher = {GitHub},
194
+ journal = {GitHub repository},
195
+ howpublished = {\url{https://github.com/paulgavrikov/visualkeras}},
196
+ }
197
+ ```
198
+
199
+ ## Contributing
200
+
201
+ - Issues: <https://github.com/paulgavrikov/visualkeras/issues>
202
+ - Contributing guide: `CONTRIBUTING.MD`
203
+ - Architecture guide: `ARCHITECTURE.md`
204
+
205
+ ## Stay Updated
206
+
207
+ Sign up for the visualkeras mailing list here: <https://forms.gle/7eBZ1jCJ7Xsm6RvA7>
208
+
209
+ ## License
210
+
211
+ Visualkeras is licensed under the MIT License. See `LICENSE`.
@@ -1,4 +1,6 @@
1
1
  pytest>=7.0
2
+ pytest-cov>=5.0
3
+ setuptools
2
4
  black>=24.0
3
5
  ruff>=0.5
4
6
  isort>=5.12
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,44 @@
1
+ import setuptools
2
+ from pathlib import Path
3
+ from runpy import run_path
4
+
5
+ ROOT = Path(__file__).resolve().parent
6
+ long_description = (ROOT / "README.md").read_text(encoding="utf-8")
7
+ development_requires = [
8
+ line.strip()
9
+ for line in (ROOT / "requirements-dev.txt").read_text(encoding="utf-8").splitlines()
10
+ if line.strip() and not line.lstrip().startswith("#")
11
+ ]
12
+
13
+ setuptools.setup(
14
+ name="visualkeras",
15
+ version=run_path(str(ROOT / "visualkeras" / "_version.py"))["__version__"],
16
+ author="Paul Gavrikov, Santosh Patapati",
17
+ author_email=(
18
+ "Paul Gavrikov <paul.gavrikov@hs-offenburg.de>, "
19
+ "Santosh Patapati <santosh.patapati@stonybrook.edu>"
20
+ ),
21
+ description="Architecture visualization of Keras models",
22
+ long_description=long_description,
23
+ long_description_content_type="text/markdown",
24
+ url="https://github.com/paulgavrikov/visualkeras",
25
+ packages=setuptools.find_packages(),
26
+ classifiers=[
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Python :: 3.9",
29
+ "Programming Language :: Python :: 3.10",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "License :: OSI Approved :: MIT License",
33
+ "Operating System :: POSIX :: Linux",
34
+ "Operating System :: MacOS",
35
+ "Operating System :: Microsoft :: Windows",
36
+ ],
37
+ install_requires=[
38
+ 'pillow>=6.2.0',
39
+ 'numpy>=1.18.1',
40
+ 'aggdraw>=1.3.11'
41
+ ],
42
+ extras_require={"dev": development_requires},
43
+ python_requires='>=3.9',
44
+ )
@@ -0,0 +1,95 @@
1
+ from collections import Counter
2
+
3
+ import aggdraw
4
+ import pytest
5
+ from PIL import Image
6
+
7
+ from visualkeras import utils
8
+
9
+
10
+ @pytest.mark.parametrize("mode", ["lenet", "layered", "graph", "functional"])
11
+ @pytest.mark.parametrize("background", [(0, 0, 0, 0), (37, 53, 97, 0)])
12
+ def test_public_translucent_fills_keep_straight_alpha_colors(mode, background):
13
+ tf = pytest.importorskip("tensorflow")
14
+ import visualkeras
15
+
16
+ inputs = tf.keras.Input((8, 8, 1), name="in")
17
+ model = tf.keras.Model(inputs, tf.keras.layers.Conv2D(1, 1, name="out")(inputs))
18
+ settings = {"draw_connections": False, "draw_patches": False, "top_label": False, "bottom_label": False}
19
+ if mode == "layered":
20
+ settings = {"draw_volume": False, "draw_funnel": False}
21
+ elif mode == "functional":
22
+ settings = {"draw_volume": False, "connector_fill": (0, 0, 0, 0)}
23
+ elif mode == "graph":
24
+ settings = {"show_neurons": False, "connector_fill": (0, 0, 0, 0)}
25
+ image = visualkeras.show(
26
+ model, mode=mode, padding=20, background_fill=background,
27
+ styles={object: {"fill": (0, 0, 255, 128), "outline": (0, 0, 255, 128)}}, **settings,
28
+ )
29
+ pixels = Counter(pixel for pixel in image.getdata() if pixel[3] > 0 and pixel[2] > pixel[0] + pixel[1])
30
+ assert pixels
31
+ interior = pixels.most_common(1)[0][0]
32
+ assert interior[:3] == (0, 0, 255)
33
+ assert 0 < interior[3] < 255
34
+ assert image.getpixel((0, 0)) == background
35
+
36
+
37
+ def test_alpha_context_preserves_untouched_pixels_and_repeated_flushes():
38
+ image = Image.new("RGBA", (40, 32), (37, 53, 97, 0))
39
+ draw = utils._aggdraw_context(image)
40
+ draw.rectangle((8, 8, 24, 24), None, aggdraw.Brush((0, 0, 255, 128)))
41
+ draw.flush()
42
+ assert image.getpixel((16, 16))[:3] == (0, 0, 255)
43
+ assert image.getpixel((0, 0)) == (37, 53, 97, 0)
44
+ first = image.tobytes()
45
+ draw.flush()
46
+ assert image.tobytes() == first
47
+ draw.rectangle((16, 8, 32, 24), None, aggdraw.Brush((255, 0, 0, 128)))
48
+ draw.flush()
49
+ overlap = image.getpixel((20, 16))
50
+ assert overlap[0] > 0 and overlap[2] > 0 and sum(overlap[:3]) >= 250
51
+ assert image.getpixel((0, 0)) == (37, 53, 97, 0)
52
+
53
+
54
+ @pytest.mark.parametrize("mode", ["RGB", "RGBA"])
55
+ def test_opaque_alpha_context_matches_native_aggdraw_exactly(mode):
56
+ image = Image.new(mode, (40, 32), "white")
57
+ reference = image.copy()
58
+ for draw in [utils._aggdraw_context(image), aggdraw.Draw(reference)]:
59
+ draw.ellipse((4, 3, 29, 26), aggdraw.Pen((10, 20, 30, 120), 2), aggdraw.Brush((210, 80, 35, 128)))
60
+ draw.line((2, 25, 35, 4), aggdraw.Pen((100, 210, 40, 90), 3))
61
+ draw.flush()
62
+ assert image.tobytes() == reference.tobytes()
63
+
64
+
65
+ def test_layered_translucent_legend_keeps_straight_alpha_colors():
66
+ tf = pytest.importorskip("tensorflow")
67
+ import visualkeras
68
+
69
+ inputs = tf.keras.Input((4,), name="in")
70
+ model = tf.keras.Model(inputs, tf.keras.layers.Dense(4, name="out")(inputs))
71
+ settings = {"background_fill": (0, 0, 0, 0), "draw_volume": False, "draw_funnel": False,
72
+ "styles": {object: {"fill": (0, 0, 255, 128), "outline": (0, 0, 255, 128)}}}
73
+ base = visualkeras.layered_view(model, **settings)
74
+ image = visualkeras.layered_view(model, legend=True, **settings)
75
+ legend = image.crop((0, base.height, image.width, image.height))
76
+ blue = [pixel for pixel in legend.getdata() if pixel[0] == pixel[1] == 0 and pixel[2] > 0 and pixel[3] > 0]
77
+ assert blue
78
+ assert Counter(blue).most_common(1)[0][0][:3] == (0, 0, 255)
79
+
80
+
81
+ def test_alpha_context_blends_over_partially_transparent_destination():
82
+ image = Image.new("RGBA", (40, 32), (0, 128, 0, 128))
83
+ mask = Image.new("RGBA", image.size, (0, 0, 0, 0))
84
+ native = aggdraw.Draw(mask)
85
+ native.rectangle((8, 8, 24, 24), None, aggdraw.Brush((255, 255, 255, 128)))
86
+ native.flush()
87
+ foreground = Image.new("RGBA", image.size, "blue")
88
+ foreground.putalpha(mask.getchannel("A"))
89
+ expected = Image.alpha_composite(image, foreground)
90
+ draw = utils._aggdraw_context(image)
91
+ draw.rectangle((8, 8, 24, 24), None, aggdraw.Brush((0, 0, 255, 128)))
92
+ draw.flush()
93
+ # An 8-bit premultiplied buffer can round a color channel by one unit.
94
+ assert all(abs(a - b) <= 1 for a, b in zip(image.getpixel((16, 16)), expected.getpixel((16, 16))))
95
+ assert image.getpixel((0, 0)) == (0, 128, 0, 128)