RuntimeError: Given input size: (10x7x7). Calculated output size: (10x0x0). Output size is too small
Trying to train the mnist 28x28x1 images 

my model is 

   def __init__(self):
        super(CNN_mnist, self).__init__()
        self.conv = nn.Sequential(
            # 3 x 128 x 128
            nn.Conv2d(1, 32, 3, 1, 1),
            nn.BatchNorm2d(32),
            nn.LeakyReLU(0.2),

            # 32 x 128 x 128
            nn.Conv2d(32, 64, 3, 1, 1),
            nn.BatchNorm2d(64),
            nn.LeakyReLU(0.2),

            # 64 x 128 x 128
            nn.MaxPool2d(2, 2),

            # 64 x 64 x 64
            nn.Conv2d(64, 128, 3, 1, 1),
            nn.BatchNorm2d(128),
            nn.LeakyReLU(0.2),

            # 128 x 64 x 64
            nn.Conv2d(128, 256, 3, 1, 1),
            nn.BatchNorm2d(256),
            nn.LeakyReLU(0.2),

            # 256 x 64 x 64
            nn.MaxPool2d(2, 2),

            # 256 x 32 x 32
            nn.Conv2d(256, 10, 3, 1, 1),
            nn.BatchNorm2d(10),
            nn.LeakyReLU(0.2)
        )
        # 256 x 32 x 32
        self.avg_pool = nn.AvgPool2d(32)
        # 256 x 1 x 1
        self.classifier = nn.Linear(10, 10)

    def forward(self, x):
        features = self.conv(x)
        flatten = self.avg_pool(features).view(features.size(0), -1)
        output = self.classifier(flatten)
        return output, features


and I got following error 


  RuntimeError: Given input size: (10x7x7). Calculated output size:
  (10x0x0). Output size is too small


not sure what this error mean and where should I fix it? 

Your [avg_pool] layer expects its input size to be (at least) 32x32, as the kernel size defined for this layer is 32.
However, given the size of the input, the feature map this pooling layer gets is only 7x7 in size. This is too small for kernel size of 32.

You should either increase the input size, or define a smaller (e.g., 7) kernel size for the avg_pooling layer.
