visualkeras: custom VGG example#

An example showing the visualkeras function used by a tf.keras.Model model.

 9 # Authors: The scikit-plots developers
10 # SPDX-License-Identifier: BSD-3-Clause

pip install protobuf==5.29.4

15 import tensorflow as tf
16
17 # Clear any session to reset the state of TensorFlow/Keras
18 tf.keras.backend.clear_session()
19
20 from scikitplot import visualkeras
model = tf.keras.applications.VGG16(

include_top=True, weights=None, # “imagenet” or ‘path/’ input_tensor=None, input_shape=None, pooling=None, classes=1000, classifier_activation=”softmax”, name=”vgg16”,

) model.summary() visualkeras.layered_view(

model, legend=True, show_dimension=True, to_file=’result_images/vgg16.png’,

)

42 model = tf.keras.applications.VGG19(
43     include_top=True,
44     weights=None,  # "imagenet" or 'path/'
45     input_tensor=None,
46     input_shape=None,
47     pooling=None,
48     classes=1000,
49     classifier_activation="softmax",
50     name="vgg19",
51 )
52 # model.summary()
55 img_vgg19 = visualkeras.layered_view(
56     model,
57     legend=True,
58     show_dimension=True,
59     min_z=1,
60     min_xy=1,
61     max_z=4096,
62     max_xy=4096,
63     scale_z=0.5,
64     scale_xy=11,
65     font={"font_size": 199},
66     # to_file="result_images/vgg19.png",
67     save_fig=True,
68     save_fig_filename="vgg19.png",
69     overwrite=False,
70     add_timestamp=True,
71     verbose=True,
72 )
73 img_vgg19
plot vgg
[INFO] Saving path to: /home/circleci/repo/galleries/examples/visualkeras_CNN/result_images/vgg19_20250627_091001Z.png

<matplotlib.image.AxesImage object at 0x7fa0dc392c50>

Tags: model-type: classification model-workflow: model building plot-type: visualkeras domain: neural network level: beginner purpose: showcase

Total running time of the script: (0 minutes 13.730 seconds)

Related examples

visualkeras: ResNetV2 example

visualkeras: ResNetV2 example

visualkeras: EfficientNetV2 example

visualkeras: EfficientNetV2 example

Visualkeras: Spam Classification Conv1D Dense Example

Visualkeras: Spam Classification Conv1D Dense Example

visualkeras: Spam Dense example

visualkeras: Spam Dense example

Gallery generated by Sphinx-Gallery