Pass correct image shape to model that uses a conv1d and con2d in the same network
so I am trying to implement the VGG network, everything in the paper, but i have when i am using the architecture that has a conv1-255 as part of it network. below is my code
def _make_convo_layers(architecture) -&gt; torch.nn.Sequential:
        &quot;&quot;&quot;
        Create convolutional layers from the vgg architecture type passed in.
        : param architecture:
        &quot;&quot;&quot;
        layers = []
        in_channels = 3
        for layer in architecture:
            if type(layer) == int:
                out_channels = layer
                layers += [nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1, stride=1), nn.ReLU()]
                # layers.append([nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1, stride=1) + nn.ReLU()])
                in_channels = layer
            elif (layer == 'Conv1-256'):
                out_channels = 256
                layers += [nn.Conv1d(256, out_channels, kernel_size=3, padding=1, stride=1), nn.ReLU()]
            elif (layer == 'LRN'):
                layers += [nn.LocalResponseNorm(5, alpha=0.0001, beta=0.75, k=1)]
            elif (layer == 'M'):
                layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
        return nn.Sequential(*layers)

below is me passing some random data to the model
device = torch.device(&quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;)
print(device)
vgg = VGGNet(config['vgg16-C1']).to(device)
x = torch.randn(1, 3, 224, 224).to(device)
model = vgg(x).to(device)
print(model.shape)

below is the error i received when i passed the x variable to the model
RuntimeError: Expected 3-dimensional input for 3-dimensional weight [256, 256, 3], but got 4-dimensional input of size [1, 256, 56, 56] instead

any help will do, please

just as jhso commented use are doing this wrong, looking that this VGG explanation on this VGG page, what you need to do isn't to use a 1D convolution but to perform a convolution operation of kernel size 1 instead of using the original kernel size of 3.
def _make_convo_layers(architecture) -&gt; torch.nn.Sequential:
        &quot;&quot;&quot;
        Create convolutional layers from the vgg architecture type passed in.
        : param architecture:
        &quot;&quot;&quot;
        layers = []
        in_channels = 3
        for layer in architecture:
            if type(layer) == int:
                out_channels = layer
                layers += [nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1, stride=1), nn.ReLU()]
                in_channels = layer
            elif (layer == 'Conv1-256'):
                out_channels = 256
                layers += [nn.Conv1d(256, out_channels, kernel_size=1, padding=1, stride=1), nn.ReLU()]
            elif (layer == 'LRN'):
                layers += [nn.LocalResponseNorm(5, alpha=0.0001, beta=0.75, k=1)]
            elif (layer == 'M'):
                layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
        return nn.Sequential(*layers)

