Thanks for your reply @ptrblck.
However, I am still wondering how this is automatically?
x = torch.randn(1, 3, 224, 224)

# Now change the in_features to 301056 
class MyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv2d(3, 6, 3, 1, 1)
        self.linear = nn.Linear(301056, 10)
        
    def forward(self, x):
        x = self.conv(x)
        x = x.view(x.size(0), -1)
        x = self.linear(x)
        return x

model = MyModel()
out = model(x) # works

Then if I change the input it fails:
x = torch.randn(1, 3, 128, 128)

And to make it work I have to manually change self.linear to:
self.linear = nn.Linear(98304, 10)

Is this the expected behaviour?
Is the following the right approach if I want to make it automatically? Or is there a better approach?
class MyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv2d(3, 6, 3, 1, 1)
        
    def forward(self, x):
        x = self.conv(x)
        linear1 = nn.Linear(x.size(1), 10)
        x = linear1(x)
        return x