Size missmatch error

if the output of my dropout layer is[8,32,19,11] how can i convert it into [8, 32*19*11] using nn.linear?
these layers follow three conv2d layers

....
self.DropoutLayer = nn.Dropout(0.6)
self.FullyConnected = nn.Linear(8, 32*19*11)

my forward function is

def forward(self, inp):
        #print(inp.shape) #prints torch.Size([1, 8, 6, 128, 64])[batchsize, sequenceLength, channels, H, W]
        out = self.CNNLayer1(inp[0])
        out = self.CNNLayer2(out)
        out = self.CNNLayer3(out)
        out = self.DropoutLayer(out)
        print(out.shape)#torch.Size([8, 32, 19, 11])
        out = self.FullyConnected(out)
        return out

This size mismatch error arises

RuntimeError: size mismatch, m1: [4864 x 11], m2: [8 x 6688] at /pytorch/aten/src/THC/generic/THCTensorMathBlas.cu:266

Hi

You can change the shape using torch.Tensor.view:

out = self.DropoutLayer(out)
out = out.view(out.size(0), -1)
out = self.FullyConnected(out)
1 Like