untimeError: input image (T: 1 H: 7 W: 7) smaller than kernel size (kT: 64 kH: 7 kW: 7)

input
torch.Size([64, 3, 224, 224])
target
torch.Size([64])
inputforward167
after expand
torch.Size([1, 64, 3, 224, 224])
input185after permute
torch.Size([64, 3, 1, 224, 224])

this is the code
def forward(self, input):

    print("inputforward167")

    print (input.shape)

    #print(input)

    #sample_len = (3 if self.modality == "RGB" else 2) * self.new_length

    if self.modality == 'RGBDiff':

        sample_len = 3 * self.new_length

        input = self._get_diff(input)

        print("input157")

        print(input.shape)

    if not self.slow_testing:#self.test_mode:

        input=input.view((-1,self.new_length,3)+ input.size()[-2:])

        print("input181")

        print(input.shape)

        input=input.permute(1,2,0,3,4).contiguous()

        print("input185")

        print(input.shape)



    else:

         input=input.view((-1,3,self.new_length)+ input.size()[-2:])

         print("inputbase")

         print(input.shape)

  #  input = input.view(input.size(0), -1)

   # print (input.shape)

    base_out = self.base_model(input)

    print("base193")

    print(base_out.shape)

    #base_out=F.dropout(base_out,p=0.5)

    if self.gtsn:

        base_out=base_out.view(base_out.shape[0]/self.num_segments,-1)

        print("base198")

        print(base_out.shape)

    if self.dropout > 0:

        base_out = self.new_fc(base_out)

        print("base205")

        print(base_out.shape)

            

    if not self.gtsn:

        if self.reshape:

            base_out = base_out.view((-1, self.num_segments) + base_out.size()[1:])

            print("base213")

            print(base_out.shape)

        base_out = self.consensus(base_out).squeeze(1)

        print("base220")

        print(base_out.shape)

        if  self.slow_testing:#apply_softmax:

            base_out = self.softmax(base_out)

        print("base_out")

        print(base_out.shape)

        return base_out#.squeeze(1)

    else:

        return base_out

and i’m using resnet50 as base model

self.base_model= I3ResNet(resnet50, self.new_length,num_class,test_mode=test_mode,num_segments=self.num_segments,fast_implementation=fast_implementation)
self.new_fc1 = nn.Linear(3224224, 2048)
self.new_fc=nn.Linear(2048,num_class)

The error is raised, if an intermediate activation’s spatial size is too small for a particular conv layer, so you would either have to increase the spatial size of the input, or reduce the pooling in the model.

PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier :wink:

1 Like