Conv2d() received an invalid combination of arguments

python_Dev: <p>I am trying to make the AlexNet from scratch. I am new in pytorch, can someone explain me what went wrong please</p>
<pre><code class="lang-auto">#create convolution 1 and 2
class conv_block(nn.Module):
  def __init__(self, in_channels, out_channels, kernel_size, stride, padding):
    super(conv_block, self).__init__()
    self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding)
    self.relu = nn.ReLU()
    self.pool_max = nn.MaxPool2d(kernel_size=(3,3), stride=(2,2))
    #self.maths = None

  def forward(self, x):
    self.pool_max(self.relu(self.conv(x)))
</code></pre>
<pre><code class="lang-auto">#create AlexNet
#fiiiiiiiiiix convolution 5

class AlexNet(nn.Module):
  def __init__(self):
    super(AlexNet, self).__init__()
    self.arch = nn.Sequential(
        conv_block(3, 96, kernel_size=(11,11), stride=(4,4), padding=(0,0)),
        conv_block(96, 256, kernel_size=(5,5), stride=(1,1), padding=(0,0)),
        nn.Conv2d(256, 384, kernel_size=(3,3), stride=(1,1), padding=(1,1)), #conv3
        nn.ReLU(),
        nn.Conv2d(384, 384, kernel_size=(3,3), stride=(1,1), padding=(1,1)), #conv4
        nn.ReLU(),
        nn.Conv2d(384, 256, kernel_size=(3,3), stride=(1,1), padding=(1,1)), #conv5
        nn.ReLU(),
        nn.Flatten(0, -1), #flatten for fully connected layer
        nn.Linear(4096, 4096), #fc1
        nn.ReLU(),
        nn.Linear(4096, 4096), #fc2
        nn.ReLU(),
        nn.Linear(4096, 10), #fc3
    )
  
  def forward(self, x):
    return softmax(self.arch(x))
</code></pre>
<pre><code class="lang-auto">#load CIFAR10
import torchvision
import torchvision.transforms as transforms
import torchvision.datasets as datasets
from torch.utils.data import DataLoader

transform = transforms.Compose(
    [transforms.ToTensor(),
     transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

batch_size = 4
</code></pre>
<p>Here I get the error:</p>
<pre><code class="lang-auto">model(images)
</code></pre>
<p>/usr/local/lib/python3.7/dist-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight, bias)<br>
442                             _pair(0), self.dilation, self.groups)<br>
443         return F.conv2d(input, weight, bias, self.stride,<br>
 → 444                         self.padding, self.dilation, self.groups)<br>
445<br>
446     def forward(self, input: Tensor) → Tensor:</p>
<p>TypeError: conv2d() received an invalid combination of arguments - got (NoneType, 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: (!NoneType!, !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: (!NoneType!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)</li>
</ul>

ptrblck: <p>Your <code>conv_block</code> is missing a <code>return</code> statement and will thus return <code>None</code>.</p>
<p>Also, check if the <code>softmax</code> layer in <code>AlexNet</code> is really needed as neither <code>nn.CrossEntropyLoss</code> nor <code>nn.NLLLoss</code> expect probabilities as the model outputs (the former expects raw logits while the latter expects log probabilities).</p>

python_Dev: <p>Thank you , this works now!</p>