Problems passing tensor to linear layer - Pytorch
I'm trying to build a neural net however I can't figure out where I'm going wrong with the max pooling layer.

    self.embed1 = nn.Embedding(256, 8)
    self.conv_1 = nn.Conv2d(1, 64, (7,8), padding = (0,0))
    self.fc1 = nn.Linear(64, 2)

def forward(self,x):

    import pdb; pdb.set_trace()
    x = self.embed1(x) #input a tensor of ([1,217]) output size: ([1, 217, 8]) 
    x = x.unsqueeze(0) #conv lay needs a tensor of size (B x C x W x H) so unsqueeze here to make ([1, 1, 217, 8])
    x = self.conv_1(x) #creates 64 filter of size (7, 8).Outputs ([1, 64, 211, 1]) as 6 values lost due to not padding. 

    x = torch.max(x,0) #returning max over the 64 columns. This returns a tuple of length 2 with 64 values in each att, the max val and indices.
    x = x[0] #I only need the max values. This returns a tensor of size ([64, 211, 1])
    x = x.squeeze(2) #linear layer only wants the number of inputs and number of outputs so I squeeze the tensor to ([64, 211])
    x = self.fc1(x) #Error Size mismatch (M1: [64 x 211] M2: [64 x 2])


I understand why the linear layer isn't accepting 211 however I don't understand why my tensor after maxing over the columns isn't 64 x 2.

You use of torch.max returns two outputs: the max value along dim=0 and the argmax along that dimension. Thus, you need to pick only the first output. (you might want to consider using adaptive max pooling for this task).

Your linear layer expects its input to have dim 64 (that is batch_size-by-64 shaped tensor). However, it seems like your x[0] is of shape 13504x1 - definitely not 64.

See this thread for example.
