
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "usage_examples/graph/plot_hide_neurons_graph.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_usage_examples_graph_plot_hide_neurons_graph.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_usage_examples_graph_plot_hide_neurons_graph.py:

Hide Neurons
=======================================

By default ``graph_view`` draws one node per neuron (constrained by ``ellipsize_after``), which is
great for seeing the width of each layer but gets busy for anything beyond a toy model. Setting
``show_neurons=False`` collapses each layer down to a single node, giving a much more compact,
block-diagram-like view that stays readable for deeper networks.

The two renders below use the *same* model so the difference is easy to spot.

.. GENERATED FROM PYTHON SOURCE LINES 11-38

.. code-block:: Python


    import matplotlib.pyplot as plt
    import visualtorch
    from torch import nn

    model = nn.Sequential(
        nn.Linear(4, 8),
        nn.ReLU(),
        nn.Linear(8, 6),
        nn.ReLU(),
        nn.Linear(6, 3),
    )

    input_shape = (1, 4)

    dpi = 150  # rendered at 2x this in the final doc build (savefig.dpi=300 in conf.py)


    def _show(*, show_neurons: bool) -> None:
        img = visualtorch.render(model, input_shape, style="graph", show_neurons=show_neurons)
        plt.figure(figsize=(img.width / dpi, img.height / dpi), dpi=dpi)
        plt.imshow(img)
        plt.axis("off")
        plt.tight_layout()
        plt.show()









.. GENERATED FROM PYTHON SOURCE LINES 39-42

``show_neurons=True`` (default)
-------------------------------
One node per neuron - the width of every layer is visible at a glance.

.. GENERATED FROM PYTHON SOURCE LINES 42-45

.. code-block:: Python


    _show(show_neurons=True)




.. image-sg:: /usage_examples/graph/images/sphx_glr_plot_hide_neurons_graph_001.png
   :alt: plot hide neurons graph
   :srcset: /usage_examples/graph/images/sphx_glr_plot_hide_neurons_graph_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 46-49

``show_neurons=False``
----------------------
One node per layer - a compact view that scales to deeper models without the clutter.

.. GENERATED FROM PYTHON SOURCE LINES 49-51

.. code-block:: Python


    _show(show_neurons=False)



.. image-sg:: /usage_examples/graph/images/sphx_glr_plot_hide_neurons_graph_002.png
   :alt: plot hide neurons graph
   :srcset: /usage_examples/graph/images/sphx_glr_plot_hide_neurons_graph_002.png
   :class: sphx-glr-single-img






.. _sphx_glr_download_usage_examples_graph_plot_hide_neurons_graph.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_hide_neurons_graph.ipynb <plot_hide_neurons_graph.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_hide_neurons_graph.py <plot_hide_neurons_graph.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_hide_neurons_graph.zip <plot_hide_neurons_graph.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
