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

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

.. _sphx_glr_usage_examples_lenet_style_plot_max_channels_lenet_style.py:

Maximum Channels
=======================================

Compare a compact channel stack with a taller one using ``max_channels``.
Capping the number of rendered channel planes keeps wide convolutional layers
legible without changing the model itself.

.. GENERATED FROM PYTHON SOURCE LINES 8-23

.. code-block:: Python


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

    model = nn.Sequential(
        nn.Conv2d(3, 128, kernel_size=3, padding=1),
        nn.ReLU(),
        nn.Conv2d(128, 256, kernel_size=3, padding=1),
        nn.AdaptiveAvgPool2d((1, 1)),
    )
    input_shape = (1, 3, 64, 64)

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








.. GENERATED FROM PYTHON SOURCE LINES 24-27

Compact Channel Stack
---------------------
Limiting the stack to 20 planes keeps wide layers compact.

.. GENERATED FROM PYTHON SOURCE LINES 27-37

.. code-block:: Python


    img_compact = visualtorch.render(model, input_shape=input_shape, style="lenet", max_channels=20)

    plt.figure(figsize=(img_compact.width / dpi, img_compact.height / dpi), dpi=dpi)
    plt.imshow(img_compact)
    plt.title("max_channels=20")
    plt.axis("off")
    plt.tight_layout()
    plt.show()




.. image-sg:: /usage_examples/lenet_style/images/sphx_glr_plot_max_channels_lenet_style_001.png
   :alt: max_channels=20
   :srcset: /usage_examples/lenet_style/images/sphx_glr_plot_max_channels_lenet_style_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 38-41

Default Channel Stack
---------------------
The default cap of 100 preserves a taller channel stack.

.. GENERATED FROM PYTHON SOURCE LINES 41-50

.. code-block:: Python


    img_default = visualtorch.render(model, input_shape=input_shape, style="lenet")

    plt.figure(figsize=(img_default.width / dpi, img_default.height / dpi), dpi=dpi)
    plt.imshow(img_default)
    plt.title("max_channels=100 (default)")
    plt.axis("off")
    plt.tight_layout()
    plt.show()



.. image-sg:: /usage_examples/lenet_style/images/sphx_glr_plot_max_channels_lenet_style_002.png
   :alt: max_channels=100 (default)
   :srcset: /usage_examples/lenet_style/images/sphx_glr_plot_max_channels_lenet_style_002.png
   :class: sphx-glr-single-img






.. _sphx_glr_download_usage_examples_lenet_style_plot_max_channels_lenet_style.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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