Thanks for your answer @ptrblck! I think I found a solution that can work from here 2:
def _infer_flat_size(self, model):
    model = nn.Sequential(*model)
    model_output = model(torch.ones(1, *self.input_size))
    return int(np.prod(model_output.size()[1:]))  

So using this function to calculate the size and use it to set the in_features.