How to visualize the architecture of a model?

Nikat: <p>Hello I am very new to this field and<br>
dealing with Pytorch is difficult for me.</p>
<p>How can I visualize the architecture of a model?</p>
<p>I have tried the following:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/c/fc0ce203cd4efc2c454c945a297d8ab9799c77de.png" data-download-href="https://discuss.pytorch.org/uploads/default/fc0ce203cd4efc2c454c945a297d8ab9799c77de" title="Visualisieren"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/c/fc0ce203cd4efc2c454c945a297d8ab9799c77de_2_690x347.png" alt="Visualisieren" data-base62-sha1="zXJVhLkX73fGTVYW4YrAJjyYme2" width="690" height="347" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/c/fc0ce203cd4efc2c454c945a297d8ab9799c77de_2_690x347.png, https://discuss.pytorch.org/uploads/default/optimized/3X/f/c/fc0ce203cd4efc2c454c945a297d8ab9799c77de_2_1035x520.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/f/c/fc0ce203cd4efc2c454c945a297d8ab9799c77de_2_1380x694.png 2x" data-dominant-color="2F2F30"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Visualisieren</span><span class="informations">1834×923 97.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
and it throws an error that I cannot solve.</p>

AlphaBetaGamma96: <p>The error suggests your model is in training mode but should be in evaluation mode. So, can you put <code>model.eval()</code> before the <code>yhat = model(batch)</code> line, and see if that solves the error?</p>
<pre><code class="lang-auto">batch = next(iter(training_data))
model.eval()
yhat=model(batch)
</code></pre>

Nikat: <p>Thank you for your reply. After your addition I received another error message.	<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/1/51d29160b6abea36f6183f9674f03da5a6284d10.png" data-download-href="https://discuss.pytorch.org/uploads/default/51d29160b6abea36f6183f9674f03da5a6284d10" title="visualisieren fehlermeldung"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/1/51d29160b6abea36f6183f9674f03da5a6284d10_2_690x356.png" alt="visualisieren fehlermeldung" data-base62-sha1="bFPOvKTlkKxiw62Vnzbjtig3jCE" width="690" height="356" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/1/51d29160b6abea36f6183f9674f03da5a6284d10_2_690x356.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/1/51d29160b6abea36f6183f9674f03da5a6284d10_2_1035x534.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/5/1/51d29160b6abea36f6183f9674f03da5a6284d10_2_1380x712.png 2x" data-dominant-color="303132"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">visualisieren fehlermeldung</span><span class="informations">1845×952 121 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
What does “expecting the last two dimensions of the Tensor to be H and W instead got {img.shape[-2:]}” mean?<br>
And how can I fulfill the expectation?</p>

AlphaBetaGamma96: <p>Your variable <code>img</code> isn’t a Tensor it’s a list, so check what <code>img</code> exactly is. It could be a list of a single tensor, but you’ll need to check. You could try printing <code>len(img)</code> to see how many items are in the list</p>

ConvolutionalAtom: <p>You could also try torchview. It accepts any type of input and output for your model.<br>
Here is the link:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/mert-kurttutan/torchview">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/mert-kurttutan/torchview" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/345;"><img src="https://opengraph.githubassets.com/7d4336304b875723ebb5a3fef799a31e4a85dbcbc0ed2fa6e92f69e71145d561/mert-kurttutan/torchview" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/mert-kurttutan/torchview" target="_blank" rel="noopener nofollow ugc">GitHub - mert-kurttutan/torchview: torchview: visualize pytorch models</a></h3>

  <p>torchview: visualize pytorch models. Contribute to mert-kurttutan/torchview development by creating an account on GitHub.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>