

.. _sphx_glr_usage_examples_graph:

============
Graph
============

These examples cover visualization via graph view


.. raw:: html

  <div id='sg-tag-list' class='sphx-glr-tag-list'></div>


.. raw:: html

    <div class="sphx-glr-thumbnails">

.. thumbnail-parent-div-open

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Visualization of basic dense model. No color_map is passed here, so each layer type is assigned a color automatically from a colorblind-safe default palette (see the Custom Color example to override this).">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_basic_dense_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_basic_dense`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Basic Dense</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Visualization of custom color. The synthetic input node can be recolored too, keyed by visualtorch.Input in color_map just like any real layer type.">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_custom_node_color_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_custom_node_color`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Custom Color</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Visualization of custom node size">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_custom_node_size_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_custom_node_size`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Custom Node Size</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Visualization of custom spacing between layers">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_custom_spacing_layers_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_custom_spacing_layers`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Custom Spacing for Layers</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="By default, graph_view draws a fully-connected mesh between every pair of adjacent layers&#x27; neuron circles. That&#x27;s accurate for a genuinely dense layer (e.g. Linear), but misleading for a convolutional one - a Conv2d&#x27;s real connectivity is local and shared across spatial positions, not &quot;every input channel wired to every output channel.&quot; Setting show_neurons=False draws each layer as a single box instead, which is the more honest representation for a conv-heavy model.">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_residual_block_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_residual_block`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Hiding Individual Neurons</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Visualization of an Inception-style block: four parallel branches (a plain Conv2d+BatchNorm2d, a 1x1-then-3x3 conv, a 1x1-then-5x5 conv, and a max-pool-then-1x1-conv) that all read the same input and merge into a shared projection layer.">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_inception_block_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_inception_block`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Multi-Branch Merge (Inception-style)</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Visualization of a model whose forward() takes two separate input tensors instead of one - an image branch (Conv2d + global pooling) and a tabular-vector branch (a small MLP) - merged by concatenation before a shared head. This is the pattern used by siamese networks and multi-modal architectures.">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_multi_input_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_multi_input`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Multi-Input Model (Siamese-style)</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A real, torchvision-provided architecture (not a toy model) - resnet18 has 8 residual blocks across 4 stages, with a projection shortcut (an extra Conv2d+BatchNorm2d in the skip path) at the first block of each of the last 3 stages, where the spatial size is downsampled and the channel count changes. Each residual skip connection is correctly routed above the diagram.">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_resnet18_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_resnet18`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">ResNet-18</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A small U-Net: two downsampling encoder stages, a bottleneck, and two upsampling decoder stages, with a skip connection concatenating each encoder stage&#x27;s output into its corresponding decoder stage. Both skip connections are genuine bypasses (around the pooling/bottleneck path) and are correctly routed above the diagram, nested since the two spans overlap.">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_unet_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_unet`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">U-Net</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A small Vision Transformer: a Conv2d patch-embedding (splitting the image into non-overlapping patches and projecting each to a vector), a learned positional embedding added on, and a Transformer encoder over the resulting patch sequence.">

.. only:: html

  .. image:: /usage_examples/graph/images/thumb/sphx_glr_plot_vit_thumb.png
    :alt:

  :doc:`/usage_examples/graph/plot_vit`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Vision Transformer (ViT)</div>
    </div>


.. thumbnail-parent-div-close

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /usage_examples/graph/plot_basic_dense
   /usage_examples/graph/plot_custom_node_color
   /usage_examples/graph/plot_custom_node_size
   /usage_examples/graph/plot_custom_spacing_layers
   /usage_examples/graph/plot_residual_block
   /usage_examples/graph/plot_inception_block
   /usage_examples/graph/plot_multi_input
   /usage_examples/graph/plot_resnet18
   /usage_examples/graph/plot_unet
   /usage_examples/graph/plot_vit

