Solved by mailcorahul in post #2 
              
              
                The tensor shape after x = F.max_pool2d(F.relu(self.conv2(x)), (2, 2)) will be batch_size x 16 x 5 x 5. 
Hence while reshaping x = x.view(-1, 16*6*6), the error is thrown. 
Change self.fc = nn.Linear(16*6*6, 128) to self.fc = nn.Linear(16*5*5, 128) 
and x = x.view(-1, 16*6*6) to x = x.view(-1, 16*5*…