Given groups=1, weight of size [6, 3, 3, 3], expected input[128, 1, 32, 32] to have 3 channels, but got 1 channels instead and i got 'Tensor' object has no attribute 'state_dict'

Sir, but in previous layer out_channels=128 .so in self.c1 for in_channels =128 was mentioned

class GaborNN(nn.Module):
def init(self):
super(GaborNN, self).init()
#Gabor Convolution 1
self.g0 = GaborConv2d(in_channels=1, out_channels=128, kernel_size=11,stride=1,padding=2)
self.relu1=nn.ReLU()
print(self.g0.weight.shape)

    #Max Pool 1
    self.maxpool1=nn.MaxPool2d(2)
  
    #Convolution 2
    self.c1 = nn.Conv2d(in_channels=128, out_channels=384, kernel_size=11,stride=1,padding=2)
    self.relu2=nn.ReLU()
    print(self.c1.weight.shape)
    #Max Pool 2
    self.maxpool1=nn.MaxPool2d(2)
    #print(self.maxpool1.shape)
    self.fc1 = nn.Linear(384*8*8, 100)
    print(self.fc1.weight.shape)
    self.fc2 = nn.Linear(100, 1)
    #print(self.fc1.weight.shape)
    #self.fc2 = nn.Linear(64, 2)
    #print(self.fc2.weight.shape)

def forward(self, x):
    ##Convolution 1
    out=self.g0(x)
    out=self.relu1(out)
    #Max Pool 1
    out=self.maxpool1(out)
    #Convolution 2
    out=self.c1(x)
    out=self.relu2(out)
    #Max Pool 2
    out=self.maxpool2(out)
    #print(out.size)
    out=out.view(out.size(0),-1)
    out=self.fc1(out)
    out=self.fc2(out)
    print(out)
    return out

Sir , is this code correct

As previously described you are not passing the output of self.g0 to self.c1 but the original input:

def forward(self, x):
    out=self.g0(x)
    out=self.relu1(out)
    out=self.maxpool1(out)
    out=self.c1(x) # !!!!

so it seems you want to use:

def forward(self, x):
    out=self.g0(x)
    out=self.relu1(out)
    out=self.maxpool1(out)
    out=self.c1(out) # !!!!

instead.

after changing it to the code u had mentioned , got this one

RuntimeError: mat1 and mat2 shapes cannot be multiplied (128x3456 and 24576x100)

This new error is a shape mismatch in self.fc1, so change its in_features to 3456.

x = x.view(-1, x.size(-3), x.size(-2), x.size(-1)) sir , what is dis statement doing? and for any CNN model using Pytorch we write
def forward (self,x)
x = x.view(-1, x.size(-3), x.size(-2), x.size(-1)) , in some CNNmodels it is defined like this and in some models they are mentioning directly like this
out=self.g0(x)
out=self.relu1(out)
What is thhis X?

class GaborNN(nn.Module):
def init(self):
super(GaborNN, self).init()
#Gabor Convolution 1
self.g0 = GaborConv2d(in_channels=1, out_channels=128, kernel_size=11,stride=1,padding=2)
self.relu1=nn.ReLU()
print(self.g0.weight.shape)

    #Max Pool 1
    self.maxpool1=nn.MaxPool2d(2)
  
    #Convolution 2
    self.c1 = nn.Conv2d(in_channels=128, out_channels=384, kernel_size=11,stride=1,padding=2)
    self.relu2=nn.ReLU()
    print(self.c1.weight.shape)
    #Max Pool 2
    self.maxpool2=nn.MaxPool2d(2)
    #print(self.maxpool1.shape)
    self.fc1 = nn.Linear(3456, 100)
    print(self.fc1.weight.shape)
    self.fc2 = nn.Linear(100, 1)
   
def forward(self, x):
    ##Convolution 1
    #x  = x.view(-1, x.size(-3), x.size(-2), x.size(-1))
    out=self.g0(x)
    out=self.relu1(out)
    #Max Pool 1
    out=self.maxpool1(out)
    #Convolution 2
    out=self.c1(out)
    out=self.relu2(out)
    #Max Pool 2
    out=self.maxpool2(out)
    #print(len(list(out.size)))
    #out=out.view(out.size(0),-1)
    out=self.fc1(out)
    out=self.fc2(out)
    #print(out)
    return out

For this model now i have changed self.fc1=3456 but arrived with the following run time error sir
RuntimeError: mat1 and mat2 shapes cannot be multiplied (147456x3 and 3456x100) and what are these 147456x3 and 3456x100. i understood3456x100 is from self.fc1 but 147456x3 i didnt understand sir.

Sir , Please reply .

The view operation is creating a new view to the tensor with the specified shapes. In the posted line of code dim0 is flattened.

x is the input tensor to the forwardmethod as defined in:

def forward(self, x):

This shape mismatch is caused in self.fc1 and you would have to check the input activation shape and make sure it’s matching the expected in_features. I would generally recommend to take a look at the tutorials to see some working examples and dig into the framework.

What is the shape of the input x to the forward() function?
and how to check its shape? i had writtten print (x.shape ) but no output is written .and how to know the shape of every layer in forward function? i had written print statement but it is not writting any output

You are passing x to the forward method via:

output = model(input)

This line of code will call the forward method with input as the x argument.

Using print(x.shape) is the right approach. If you are not seeing any output, you should make sure that the code is indeed executed and that your current setup is able to print anything.

Thank you for your reply.