Expected 4-dimensional input for 4-dimensional weight [192, 768, 1, 1], but got 2-dimensional input of size [50, 1000] instead
I'm try to modify Inception v3 pre trained in pytorch to have a multi-input. ( 4 output precisely).
I get this error:
Expected 4-dimensional input for 4-dimensional weight [192, 768, 1, 1], but got 2-dimensional input of size [50, 1000] instead
My input shape is : torch.Size([50, 3, 299, 299])
This is the code for my model,
class CNN1(nn.Module):
    def __init__(self, pretrained):
        super(CNN1, self).__init__()
        if pretrained is True:
            self.model = models.inception_v3(pretrained=True)    
        modules = list(self.model.children())[:-1]      # delete the last fc layer.
        self.features = nn.Sequential(*modules)
        self.fc0 = nn.Linear(2048, 10)   #digit 0
        self.fc1 = nn.Linear(2048, 10)  #digit 1
        self.fc2 = nn.Linear(2048, 10)    #digit 2
        self.fc3 = nn.Linear(2048, 10)   #digit 3  
    def forward(self, x):
        bs, _, _, _ = x.shape
        x = self.features(x)
        x = F.adaptive_avg_pool2d(x, 1).reshape(bs, -1)

        label0 = self.fc0(x)
        label1 = self.fc1(x)
        label2= self.fc2(x) 
        label3= self.fc3(x)
          
        return {'label0': label0, 'label1': label1,'label2':label2, 'label3': label3}

and this is a piece of iteration:
        for batch_idx, sample_batched in enumerate(train_dataloader):
            # importing data and moving to GPU
            image,label0, label1, label2, label3 = sample_batched['image'].to(device),\
                                             sample_batched['label0'].to(device),\
                                              sample_batched['label1'].to(device),\
                                               sample_batched['label2'].to(device) ,\
                                                       sample_batched['label3'].to(device)  

            
            # zero the parameter gradients
            optimizer.zero_grad()
            output=model(image.float())

anyone have a suggestion?

One way to remove layers of a PyTorch model is to use nn.Identity() layer. I think you want to remove the last fully connected layer. If so check this:
import torch 
import torch.nn as nn 
import torch.nn.functional as F 
from torchvision import models


class CNN1(nn.Module):
    def __init__(self, pretrained):
        super(CNN1, self).__init__()
        if pretrained is True:
            self.model = models.inception_v3(pretrained=True)
        else:    
            self.model = models.inception_v3(pretrained=False)    
        # modules = list(self.model.children())[:-1]      
        # delete the last fc layer.
        self.model.fc = nn.Identity()

        # # to freeze training of inception weights
        # for param in self.model.parameters():
        #     param.requires_grad = False

        self.fc0 = nn.Linear(2048, 10)  
        self.fc1 = nn.Linear(2048, 10)  
        self.fc2 = nn.Linear(2048, 10)   
        self.fc3 = nn.Linear(2048, 10)    
    
    def forward(self, x):
        bs, _, _, _ = x.shape
        x, aux_x = self.model(x)
        # x = F.adaptive_avg_pool2d(x, 1).reshape(bs, -1)
        label0 = self.fc0(x)
        label1 = self.fc1(x)
        label2= self.fc2(x) 
        label3= self.fc3(x)
          
        return {'label0': label0, 'label1': label1,'label2':label2, 'label3': label3}


if __name__ == '__main__':
    net = CNN1(True)
    print(net)

    inp = torch.randn(50, 3, 299, 299)
    out = net(inp)

    print('label0 shape:', out['label0'].shape)

Note: if you want to freeze training of inception layers set requires_grad = False for each parameter
In you code you are assuming all the layer connections are sequential by using nn.Sequential(*modules) line, may be that is causing the error.
