AttributeError: NoneType object has no attribute size

username: dirkcremers
cooked: <p>Hi,</p>
<p>I am trying to get a summary of the pre-trained model by using the following code:</p>
<p>import torchvision<br>
from torchsummary import summary<br>
model = torchvision.models.vit_b_16(weights=‘IMAGENET1K_SWAG_E2E_V1’)<br>
summary(model,input_size= (3, 384, 384))</p>
<p>However, I do not understand the error output which is provided. Can somebody maybe explain what is going wrong, since the input sizes seem to match with the vision transformer. Doing something like this for ResNet works and provides a detailed description of the model.</p>
<p>Error stack trace:</p>
<p>/usr/local/lib/python3.9/dist-packages/torchsummary/torchsummary.py in (.0)<br>
21             if isinstance(output, (list, tuple)):<br>
22                 summary[m_key][“output_shape”] = [<br>
—&gt; 23                     [-1] + list(o.size())[1:] for o in output<br>
24                 ]<br>
25             else:</p>
<p>Thanks for helping out!</p>
<p>Dirk</p>

username: ptrblck
cooked: <p><code>torchsummary</code> is deprecated as it wasn’t updated in a couple of years as seen in <a href="https://github.com/sksq96/pytorch-summary">their repository</a>. Use <code>torchinfo</code> instead which works for me after adding the missing batch dimension:</p>
<pre><code class="lang-python">import torchvision
from torchinfo import summary

model = torchvision.models.vit_b_16(weights='IMAGENET1K_SWAG_E2E_V1')
summary(model,input_size= (1, 3, 384, 384))

# ===============================================================================================
# Layer (type:depth-idx)                        Output Shape              Param #
# ===============================================================================================
# VisionTransformer                             [1, 1000]                 768
# ├─Conv2d: 1-1                                 [1, 768, 24, 24]          590,592
# ├─Encoder: 1-2                                [1, 577, 768]             443,136
# │    └─Dropout: 2-1                           [1, 577, 768]             --
# │    └─Sequential: 2-2                        [1, 577, 768]             --
# │    │    └─EncoderBlock: 3-1                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-2                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-3                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-4                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-5                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-6                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-7                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-8                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-9                 [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-10                [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-11                [1, 577, 768]             7,087,872
# │    │    └─EncoderBlock: 3-12                [1, 577, 768]             7,087,872
# │    └─LayerNorm: 2-3                         [1, 577, 768]             1,536
# ├─Sequential: 1-3                             [1, 1000]                 --
# │    └─Linear: 2-4                            [1, 1000]                 769,000
# ===============================================================================================
# Total params: 86,859,496
# Trainable params: 86,859,496
# Non-trainable params: 0
# Total mult-adds (M): 397.66
# ===============================================================================================
# Input size (MB): 1.77
# Forward/backward pass size (MB): 304.88
# Params size (MB): 232.27
# Estimated Total Size (MB): 538.92
# ===============================================================================================
</code></pre>