Kernel size can't greater than actual input size


(Vinay Kumar) #1

Hi,
I’m getting the following error.

RuntimeError: Calculated padded input size per channel: (1017 x 1). 
Kernel size: (3 x 3). 
Kernel size can't greater than actual input size at /opt/conda/conda-bld/pytorch_1524584710464/work/aten/src/THNN/generic/SpatialConvolutionMM.c:48

My input tensor has size [1,1,1025,15]
Following is my Network:

MeeAutoEncoder(
  (encoder): MeeEncoder(
    (en_layer1): Conv2d(1, 12, kernel_size=(3, 3), stride=(1, 1))
    (en_layer2): MaxPool2d(kernel_size=(3, 5), stride=1, padding=0, dilation=1, ceil_mode=False)
    (en_layer3): Conv2d(12, 20, kernel_size=(3, 3), stride=(1, 1))
    (en_layer4): MaxPool2d(kernel_size=(1, 5), stride=1, padding=0, dilation=1, ceil_mode=False)
    (en_layer5): Conv2d(20, 30, kernel_size=(3, 3), stride=(1, 1))
    (en_layer6): Conv2d(30, 40, kernel_size=(3, 3), stride=(1, 1))
    (en_layerReLU): ReLU()
    (encoder): Sequential(
      (0): Conv2d(1, 12, kernel_size=(3, 3), stride=(1, 1))
      (1): ReLU()
      (2): MaxPool2d(kernel_size=(3, 5), stride=1, padding=0, dilation=1, ceil_mode=False)
      (3): Conv2d(12, 20, kernel_size=(3, 3), stride=(1, 1))
      (4): ReLU()
      (5): MaxPool2d(kernel_size=(1, 5), stride=1, padding=0, dilation=1, ceil_mode=False)
      (6): Conv2d(20, 30, kernel_size=(3, 3), stride=(1, 1))
      (7): ReLU()
      (8): Conv2d(30, 40, kernel_size=(3, 3), stride=(1, 1))
    )
  )
  (decoder): MeeDecoder(
    (de_layer1): Conv2d(40, 30, kernel_size=(3, 3), stride=(1, 1))
    (de_layer2): Conv2d(30, 20, kernel_size=(3, 3), stride=(1, 1))
    (de_layer3): Upsample(size=(5, 205), mode=bilinear)
    (de_layer4): Conv2d(20, 12, kernel_size=(3, 3), stride=(1, 1))
    (de_layer5): Upsample(size=(15, 1025), mode=bilinear)
    (de_layer6): Conv2d(12, 1, kernel_size=(3, 3), stride=(1, 1))
    (de_layerReLU): ReLU()
    (decoder): Sequential(
      (0): Conv2d(40, 30, kernel_size=(3, 3), stride=(1, 1))
      (1): ReLU()
      (2): Conv2d(30, 20, kernel_size=(3, 3), stride=(1, 1))
      (3): ReLU()
      (4): Upsample(size=(5, 205), mode=bilinear)
      (5): Conv2d(20, 12, kernel_size=(3, 3), stride=(1, 1))
      (6): ReLU()
      (7): Upsample(size=(15, 1025), mode=bilinear)
      (8): Conv2d(12, 1, kernel_size=(3, 3), stride=(1, 1))
      (9): ReLU()
    )
  )
)

#2

Your last conv layer in your encoder throws this error, since it receives an input of [1, 30, 1017, 1] and tries to use kernel_size=3.
You have to lower the kernel size to 1 or modify your model somewhere before this layer.


(Vinay Kumar) #3

Thanks @ptrblck. It solved the issue.


#4

I got a similar error as below

“Calculated padded input size per channel: (3 x 3). Kernel size: (5 x 5). Kernel size can’t greater than actual input size at /pytorch/aten/src/THNN/generic/SpatialConvolutionMM.c:48”

I was try to load pretrained inception model and test a image
‘’
net = models.inception_v3(pretrained=False)
net.fc = nn.Linear(2048, 2)
net_dict = torch.load(‘model_inception.pt’)

print net

net.load_state_dict(net_dict[‘state_dict’])
#checkpoint = torch.load(Path(‘model_resnet.pt’))
#model.load_state_dict(checkpoint)
trans = transforms.Compose([
transforms.RandomHorizontalFlip(),
transforms.Resize((229,229)),

transforms.ToTensor(),
#transforms.Normalize((0.5, 0.5, 0.5),(0.5, 0.5, 0.5))
])

#for file in glob(’.png’):
for file in glob.glob("/home/CN/
.png"):
#print (file)
img_pil= Image.open(file)
input = trans(img_pil)

input = input.view(1, 3, 229,229)

output = net(input)

prediction = int(torch.max(output.data, 1)[1].numpy())
#print(prediction)

if (prediction == 0):
    print ('AD')
if (prediction == 1):
    print ('CN')
    
print((file,prediction))

    
    
    
prob = F.softmax(output, dim=1)
print prob

‘’