.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/visualkeras/plot_dl_ann_dense.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite or Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_visualkeras_plot_dl_ann_dense.py: visualkeras: Spam Dense example ========================================== .. currentmodule:: scikitplot.visualkeras An example showing the :py:func:`~scikitplot.visualkeras` function used by a :py:class:`~tensorflow.keras.Model` model. .. GENERATED FROM PYTHON SOURCE LINES 10-14 .. code-block:: Python # Authors: The scikit-plots developers # SPDX-License-Identifier: BSD-3-Clause .. GENERATED FROM PYTHON SOURCE LINES 15-36 .. code-block:: Python # visualkeras Need aggdraw tensorflow # !pip install scikitplot[core, cpu] # or # !pip install aggdraw # !pip install tensorflow # python -c "import tensorflow as tf, google.protobuf as pb; print('tf', tf.__version__); print('protobuf', pb.__version__)" # python -m pip check # If Needed # pip install -U "protobuf<6" # pip install protobuf==5.29.4 import tensorflow as tf # Clear any session to reset the state of TensorFlow/Keras tf.keras.backend.clear_session() import tensorflow.python as tf_python # Clear any session to reset the state of TensorFlow/Keras tf_python.keras.backend.clear_session() .. GENERATED FROM PYTHON SOURCE LINES 37-49 .. code-block:: Python model = tf_python.keras.models.Sequential() model.add(tf_python.keras.layers.InputLayer(input_shape=(100,))) # Add Dense layers model.add(tf_python.keras.layers.Dense(64, activation="relu")) # input_shape=(100,) model.add(tf_python.keras.layers.Dense(32, activation="relu")) model.add(tf_python.keras.layers.Dense(1, activation="sigmoid")) # Compile the model model.compile(optimizer="rmsprop", loss="binary_crossentropy", metrics=["accuracy"]) model.summary() .. rst-class:: sphx-glr-script-out .. code-block:: none Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense (Dense) (None, 64) 6464 _________________________________________________________________ dense_1 (Dense) (None, 32) 2080 _________________________________________________________________ dense_2 (Dense) (None, 1) 33 ================================================================= Total params: 8,577 Trainable params: 8,577 Non-trainable params: 0 _________________________________________________________________ .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python from scikitplot import visualkeras .. GENERATED FROM PYTHON SOURCE LINES 53-61 .. code-block:: Python img_spam = visualkeras.graph_view( model, # to_file="result_images/spam_dense_x.png", save_fig=True, save_fig_filename="spam_dense_graph.png", ) img_spam .. image-sg:: /auto_examples/visualkeras/images/sphx_glr_plot_dl_ann_dense_001.png :alt: plot dl ann dense :srcset: /auto_examples/visualkeras/images/sphx_glr_plot_dl_ann_dense_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 62-79 .. code-block:: Python img_spam = visualkeras.layered_view( model, min_z=1, min_xy=1, max_z=4096, max_xy=4096, scale_z=1, scale_xy=1, font={"font_size": 7}, text_callable="default", one_dim_orientation="x", # to_file="result_images/spam_dense_x.png", save_fig=True, save_fig_filename="spam_dense_x.png", ) img_spam .. image-sg:: /auto_examples/visualkeras/images/sphx_glr_plot_dl_ann_dense_002.png :alt: plot dl ann dense :srcset: /auto_examples/visualkeras/images/sphx_glr_plot_dl_ann_dense_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 80-97 .. code-block:: Python img_spam = visualkeras.layered_view( model, min_z=1, min_xy=1, max_z=4096, max_xy=4096, scale_z=1, scale_xy=1, font={"font_size": 7}, text_callable="default", one_dim_orientation="y", # to_file="result_images/spam_dense_y.png", save_fig=True, save_fig_filename="spam_dense_y.png", ) img_spam .. image-sg:: /auto_examples/visualkeras/images/sphx_glr_plot_dl_ann_dense_003.png :alt: plot dl ann dense :srcset: /auto_examples/visualkeras/images/sphx_glr_plot_dl_ann_dense_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 98-115 .. code-block:: Python img_spam = visualkeras.layered_view( model, min_z=1, min_xy=1, max_z=4096, max_xy=4096, scale_z=1, scale_xy=1, font={"font_size": 7}, text_callable="default", one_dim_orientation="z", # to_file="result_images/spam_dense_z.png", save_fig=True, save_fig_filename="spam_dense_z.png", ) img_spam .. image-sg:: /auto_examples/visualkeras/images/sphx_glr_plot_dl_ann_dense_004.png :alt: plot dl ann dense :srcset: /auto_examples/visualkeras/images/sphx_glr_plot_dl_ann_dense_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 116-124 .. tags:: model-type: classification model-workflow: model building plot-type: visualkeras domain: neural network level: beginner purpose: showcase .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.217 seconds) .. _sphx_glr_download_auto_examples_visualkeras_plot_dl_ann_dense.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-plots/scikit-plots/main?urlpath=lab/tree/notebooks/auto_examples/visualkeras/plot_dl_ann_dense.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/visualkeras/plot_dl_ann_dense.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dl_ann_dense.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dl_ann_dense.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_dl_ann_dense.zip ` .. include:: plot_dl_ann_dense.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_