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

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

.. _sphx_glr_usage_examples_flow_plot_resnet18_flow.py:

ResNet-18
=======================================

The same real, torchvision-provided `resnet18` architecture as the ``graph`` style's example -
8 residual blocks across 4 stages, with a projection shortcut where channels/spatial size
change - rendered in ``flow`` style instead.

Conv2d is orange, BatchNorm2d is green, and ReLU is sky blue.

.. GENERATED FROM PYTHON SOURCE LINES 10-35



.. image-sg:: /usage_examples/flow/images/sphx_glr_plot_resnet18_flow_001.png
   :alt: plot resnet18 flow
   :srcset: /usage_examples/flow/images/sphx_glr_plot_resnet18_flow_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    from collections import defaultdict

    import matplotlib.pyplot as plt
    import visualtorch
    from torch import nn
    from torchvision.models import resnet18

    model = resnet18(weights=None, num_classes=10)

    input_shape = (1, 3, 64, 64)

    color_map: dict = defaultdict(dict)
    color_map[nn.Conv2d]["fill"] = "#E69F00"
    color_map[nn.BatchNorm2d]["fill"] = "#009E73"
    color_map[nn.ReLU]["fill"] = "#56B4E9"

    img = visualtorch.render(model, input_shape, style="flow", color_map=color_map, scale_xy=3, spacing=15)

    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_resnet18_flow.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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