I am trying to build a simple resnet model but getting an error "conv2d() received an invalid combination of arguments"

UmarMubeen: <p>here is my code and error<br>
<strong>Residual block</strong><br>
def Residual_block(in_channel,out_channel):</p>
<p>res_layer = [nn.Conv2d(in_channel, out_channel, kernel_size=3, padding=1, stride=1 ),</p>
<pre><code>          nn.BatchNorm2d(out_channel),

          nn.ReLU(inplace= True),

          

          nn.Conv2d(out_channel, out_channel, kernel_size=3, padding=1, stride=1),

          nn.BatchNorm2d(out_channel)]
</code></pre>
<p>return nn.Sequential(*res_layer)<br>
<strong>convolutional</strong><br>
def convo_block(in_channel, out_channel):</p>
<p>convo_layer = [nn.Conv2d(in_channel, out_channel, kernel_size=3, padding=1,stride=1),</p>
<pre><code>             nn.BatchNorm2d(out_channel),

             nn.ReLU() ]
</code></pre>
<p>return nn.Sequential(*convo_layer)</p>
<p><strong>Model</strong><br>
class Resnet_9(nn.Module):</p>
<p>def <strong>init</strong>(self,in_channel,out_classes):</p>
<pre><code>super().__init__()

self.conv_1 = convo_block(in_channel, 64)

                                      

self.conv_2 = convo_block(64, 128)

self.pool_1= nn.MaxPool2d(2,2)        #16*16*128

                                    

self.residual_block1 = Residual_block(128,128)

self.conv_3 = convo_block(128, 256)

self.pool_2= nn.MaxPool2d(2,2)        #8*8*128

                       

self.conv_4 = convo_block(256, 512)

self.pool_3= nn.MaxPool2d(2,2)        #4*4*128

                                    

self.residual_block2 = Residual_block(512,512) 

self.classfier = nn.Sequential(nn.MaxPool2d(2,2),        #2*2*512

                                nn.Flatten(),

                                nn.Dropout(0.2),

                                nn.Linear(512,out_classes)

                                )
</code></pre>
<p>def forward(self,x):</p>
<pre><code>out = self.conv_1(x)

out = self.conv_2(out)

out = self.pool_1(out)

out = self.residual_block1(out) + out

out = nn.ReLU(out)

out = self.conv_3(out)

out = self.pool_2(out)

out = self.conv_4(out)

out = self.pool_3(out)

out = self.residual_block2(out) + out

out = nn.ReLU(out)

out = self.classfier(out)

return out
</code></pre>
<p><strong>Error</strong><br>
TypeError: conv2d() received an invalid combination of arguments - got (ReLU, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:</p>
<ul>
<li>(Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)<br>
didn’t match because some of the arguments have invalid types: (!ReLU!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)</li>
<li>(Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)<br>
didn’t match because some of the arguments have invalid types: (!ReLU!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)</li>
</ul>

KFrank: <p>Hi Umar!</p>
<aside class="quote no-group quote-modified" data-username="UmarMubeen" data-post="1" data-topic="134141" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/u/f08c70/48.png" class="avatar"> UmarMubeen:</div>
<blockquote>
<pre><code>out = nn.ReLU(out)

out = self.conv_3(out)
</code></pre>
<p>…</p>
<p>TypeError: conv2d() received an invalid combination of arguments - got (ReLU, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:</p>
</blockquote>
</aside>
<p>The problem is that <code>nn.ReLU(out)</code> <em>constructs</em> a <code>ReLU</code> object so<br>
that you then pass that <code>ReLU</code> object to <code>conv_3</code>.</p>
<p>You want either:</p>
<pre data-code-wrap="python"><code class="lang-python">out = nn.ReLU() (out)
# or
out = nn.functional.relu (out)
</code></pre>
<p>(I’m a little surprised that <code>nn.ReLU(out)</code> itself doesn’t throw an<br>
error because in most cases your <code>out</code> won’t be able to be cast<br>
to a <code>bool</code>.)</p>
<p>Best.</p>
<p>K. Frank</p>

UmarMubeen: <p><a class="mention" href="/u/kfrank">@KFrank</a><br>
it worked .<br>
Thankyou so much.</p>