
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "usage_examples/flow/plot_ignore_layers.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_flow_plot_ignore_layers.py>`
        to download the full example code.

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

.. _sphx_glr_usage_examples_flow_plot_ignore_layers.py:

Ignore Layers
=======================================

Visualize some layers only. ``type_ignore`` hides layer types you don't care about (here, ReLU
and Flatten); ``show_input=False`` is the same idea applied to the synthetic input box itself -
both trim the diagram down to just the layers worth looking at.

.. GENERATED FROM PYTHON SOURCE LINES 8-47



.. image-sg:: /usage_examples/flow/images/sphx_glr_plot_ignore_layers_001.png
   :alt: plot ignore layers
   :srcset: /usage_examples/flow/images/sphx_glr_plot_ignore_layers_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


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

    # Example of a simple CNN model using nn.Sequential
    model = nn.Sequential(
        nn.Conv2d(3, 16, kernel_size=3, padding=1),
        nn.ReLU(),
        nn.MaxPool2d(2, 2),
        nn.Conv2d(16, 32, kernel_size=3, padding=1),
        nn.ReLU(),
        nn.MaxPool2d(2, 2),
        nn.Conv2d(32, 64, kernel_size=3, padding=1),
        nn.ReLU(),
        nn.MaxPool2d(2, 2),
        nn.Flatten(),
        nn.Linear(64 * 28 * 28, 256),  # Adjusted the input size for the Linear layer
        nn.ReLU(),
        nn.Linear(256, 10),  # Assuming 10 output classes
    )

    ignored_layers = [nn.ReLU, nn.Flatten]

    input_shape = (1, 3, 224, 224)
    img = visualtorch.render(
        model,
        input_shape=input_shape,
        style="flow",
        type_ignore=ignored_layers,
        show_input=False,
    )

    dpi = 150  # rendered at 2x this in the final doc build (savefig.dpi=300 in conf.py)
    plt.figure(figsize=(img.width / dpi, img.height / dpi), dpi=dpi)
    plt.imshow(img)
    plt.axis("off")
    plt.tight_layout()
    plt.show()


.. _sphx_glr_download_usage_examples_flow_plot_ignore_layers.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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