RuntimeError: Given input size: (512x1x1). Calculated output size: (512x0x0). Output size is too small

can anyone help i develop cnn and this error pop up and i have no idea what went wrog or how to fix it can annyone help

class gface1(nn.Module):
    def __init__(self, bottleneck_setting=MobiFace_bottleneck_setting, final=False):
        super(gface1, self).__init__()
        self.final = final

        self.conv1 = ConvBlock(3, 64, 3, 2, 1)

        self.dw_conv1 = ConvBlock(64, 64, 3, 1, 1, dw=True)

      
        self.conv4= ConvBlock6(64,128,3, 1, 1)

        self.conv5= ConvBlock6(128,256,3, 1, 1)

        self.conv6= ConvBlock6(256,512,3, 1, 1)

        #self.conv7 = ConvBlock(512, 512, 1, 1, 0, linear=True)

        #self.linear1 = nn.Linear(512*7*7, 512)

        #self.linear7 = ConvBlock4(512, 512, (7, 6), 1, 0, dw=True, linear=True)

        #self.linear1 = ConvBlock4(512, 128, 1, 1, 0, linear=True)

        #self.prelu1 = nn.PReLU()



    def forward(self, x):
        x = self.conv1(x)
        x = self.dw_conv1(x)
        #x= self.conv3(x)
        x=self.conv4(x)
        x= self.conv5(x)
        x=self.conv6(x)
        #x=self.conv7(x)
        #x = x.view(x.size(0), -1)
        #x = self.linear1(x)
        #if self.final is False:
         # x = self.prelu1(x)
        #x = self.linear7(x)
        #x = self.linear1(x)
        #x = x.view(x.size(0), -1)
        return x
        
        


class ConvBlock6(nn.Module):
    def __init__(self, inp, oup, k, s, p, dw=False, linear=False):
        super(ConvBlock6, self).__init__()
        self.linear = linear
        self.conv = nn.Conv2d(inp, oup, k, s, p, groups=inp, bias=False)
        self.batch1 = nn.BatchNorm2d(oup)
        self.PRelu1=nn.PReLU(oup)
        self.max1= nn.MaxPool2d((2, 2), 2)


        self.dw_conv2=nn.Conv2d(oup, oup, k, s, p,groups=inp * 2, bias=False)
        self.batch2=nn.BatchNorm2d(oup)
        self.PRelu2=nn.PReLU(oup)
        self.max2=  nn.MaxPool2d((2, 2), 2)
        

        self.conv3= nn.Conv2d(oup, oup, 1, 1, 0, bias=False)
        self.batch3=nn.BatchNorm2d(oup)


        

        #self.maxP = x

    def forward(self, x):
        x = self.conv(x)
        x = self.batch1(x)
        x=self.PRelu1(x)
        x= self.max1(x)
        x=self.dw_conv2(x)
        x=self.batch2(x)
        x=self.PRelu2(x)
        x=self.max2(x)
        x=self.conv3(x)
        x=self.batch3(x)
        return self.conv3(x)

at some step in your forward pass your input gets downsampled too much, likely because of one extra pooling layer. during your forward pass report shape of tensor, and find where the problem is that way

so remove or reduce pool layer should help am i correct

Or change its settings, or the proble might be in convolutions, they also can change the size of channels

1 Like