I would advise against it because optimizers have states that you want to keep from one iteration to the next.
You can provide a dummy input to the network when you create it if you really need to know the input size to create all the Parameters.