visualkeras: ResNetV2 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
23 model = tf.keras.applications.ResNet50V2(
24     include_top=True,
25     weights=None,  # "imagenet" or 'path/'
26     input_tensor=None,
27     input_shape=None,
28     pooling=None,
29     classes=1000,
30     classifier_activation="softmax",
31     name="resnet50v2",
32 )
33 # model.summary()
36 img_resnet50v2 = visualkeras.layered_view(
37     model,
38     legend=True,
39     min_z=1,
40     min_xy=1,
41     max_z=4096,
42     max_xy=4096,
43     scale_z=0.01,
44     scale_xy=10,
45     font={"font_size": 99},
46     # to_file="result_images/resnet50v2.png",
47     save_fig=True,
48     save_fig_filename="resnet50v2.png",
49 )
50 img_resnet50v2
plot resnetv2
<matplotlib.image.AxesImage object at 0x7fa0dc35d7d0>

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

65 # model = tf.keras.applications.ResNet101V2(
66 #     include_top=True,
67 #     weights=None,  # "imagenet" or 'path/'
68 #     input_tensor=None,
69 #     input_shape=None,
70 #     pooling=None,
71 #     classes=1000,
72 #     classifier_activation="softmax",
73 #     name="resnet101v2",
74 # )
75 # visualkeras.layered_view(
76 #   model,
77 #   legend=True,
78 #   show_dimension=True,
79 #   to_file='result_images/resnet101v2.png',
80 # )
81
82 # model = tf.keras.applications.ResNet152V2(
83 #     include_top=True,
84 #     weights=None,  # "imagenet" or 'path/'
85 #     input_tensor=None,
86 #     input_shape=None,
87 #     pooling=None,
88 #     classes=1000,
89 #     classifier_activation="softmax",
90 #     name="resnet152v2",
91 # )
92 # visualkeras.layered_view(
93 #   model,
94 #   legend=True,
95 #   show_dimension=True,
96 #   to_file='result_images/resnet152v2.png',
97 # )

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

Related examples

visualkeras: custom VGG example

visualkeras: custom VGG example

visualkeras: EfficientNetV2 example

visualkeras: EfficientNetV2 example

visualkeras: custom vgg16 show dimension example

visualkeras: custom vgg16 show dimension example

Visualkeras: Spam Classification Conv1D Dense Example

Visualkeras: Spam Classification Conv1D Dense Example

Gallery generated by Sphinx-Gallery