TypeError: ‘tuple’ object is not callable

pak_key: <p>import torch.nn.functional as F<br>
class TinVgg(nn.Module):<br>
“”"<em>summary</em><br>
该链接解释了vgg架构:<a href="https://poloclub.github.io/cnn-explainer/" class="inline-onebox" rel="noopener nofollow ugc">CNN Explainer</a></p>
<pre><code>Args:
    nn (_type_): _description_
"""
def __init__(self,input_shape:int,
             hidden_units:int,
             out_shape:int) -&gt; None:
    super(TinVgg,self).__init__()
    self.conv_block_1 = nn.Sequential(
        # 第一层
        nn.Conv2d(in_channels=input_shape,
                  out_channels=hidden_units,
                  kernel_size=3,
                  stride=1,
                  padding=1),
        nn.ReLU(),
        nn.Conv2d(
            in_channels=hidden_units,
            out_channels=hidden_units,
            kernel_size=3,
            stride=1,
            padding=1
        ),
        nn.ReLU(),
        # 最大池化
        nn.MaxPool2d(kernel_size=2,stride=2), # 步长与内核相同    
    ),
    self.conv_block_2 = nn.Sequential(
        # 第二层
        nn.Conv2d(in_channels=hidden_units,
                  out_channels=hidden_units,
                  kernel_size=3,
                  stride=1,
                  padding=1),
        nn.ReLU(),
        nn.Conv2d(
            in_channels=hidden_units,
            out_channels=hidden_units,
            kernel_size=3,
            stride=1,
            padding=1
        ),
        nn.ReLU(),
        # 最大池化
        nn.MaxPool2d(kernel_size=2,stride=2))# 步长与内核相同    
        # 创建分类器
        
    self.classifier = nn.Sequential(
        nn.Flatten(),
        nn.Linear(in_features=hidden_units,out_features=out_shape)
    )
    # 前向
def forward(self, x):
    x = self.conv_block_1(x)
    print(x.shape)
    x = self.conv_block_2(x)
    print(x.shape)
    x_class = self.classifier(x)
    return x_class
    """
    或者         return self.classifier(self.conv_block_2(self.conv_block_1(x))) 等价于上面的前向
    """
</code></pre>
<p>The error I get is: ----------------------------------------------- ----------------------------------<br>
TypeError Traceback (most recent call last)<br>
Cell In[110], line 1<br>
----&gt; 1 model_0(image_batch)</p>
<p>File d:\python_3.11\Lib\site-packages\torch\nn\modules\module.py:1501, in Module._call_impl(self, *args, **kwargs)<br>
1496 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1497 # this function, and just call forward.<br>
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1499 or _global_backward_pre_hooks or _global_backward_hooks<br>
1500 or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1501 return forward_call(*args, **kwargs)<br>
1502 # Do not call functions when jit is used<br>
1503 full_backward_hooks, non_full_backward_hooks = <span class="chcklst-box fa fa-square-o fa-fw"></span>, <span class="chcklst-box fa fa-square-o fa-fw"></span></p>
<p>Cell In[104], line 57<br>
56 def forward(self, x):<br>
—&gt; 57 x = self.conv_block_1(x)<br>
58 print(x.shape)<br>
59 x = self.conv_block_2(x)</p>
<p>TypeError: ‘tuple’ object is not callable</p>

InnovArul: <aside class="quote no-group" data-username="pak_key" data-post="1" data-topic="194613">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pak_key/48/66623_2.png" class="avatar"> pak_key:</div>
<blockquote>
<pre><code class="lang-auto">    self.conv_block_1 = nn.Sequential(
        # 第一层
        nn.Conv2d(in_channels=input_shape,
                  out_channels=hidden_units,
                  kernel_size=3,
                  stride=1,
                  padding=1),
        nn.ReLU(),
        nn.Conv2d(
            in_channels=hidden_units,
            out_channels=hidden_units,
            kernel_size=3,
            stride=1,
            padding=1
        ),
        nn.ReLU(),
        # 最大池化
        nn.MaxPool2d(kernel_size=2,stride=2), # 步长与内核相同    
    ),
</code></pre>
</blockquote>
</aside>
<p>From a quick first look,  it seems there is an additional comma after <code>nn.Sequential()</code>. Could you please remove the comma (<code>,</code>) after <code>nn.Sequential()</code> definition and try again?<br>
In python, adding a comma makes it a tuple.<br>
For example,</p>
<pre><code class="lang-auto">&gt;&gt;&gt; x = 5,
&gt;&gt;&gt; x
(5,)

&gt;&gt;&gt; type(x)
&lt;class 'tuple'&gt;
</code></pre>