Question about the unit of hidden layer

Hello Prof. and tutors, I am learning Course 2 week 2, suddenly I have a question. While building Neural network, like this picture, how can I get how many units that I should use for the layer 1 and layer 2? Some confused about choosing the units. Thanks!

The sizes of the hidden layers are determined by experimentation.

You want enough units to get “good enough” performance, but not so many that training takes excessive resources (time and computation cycles).

So, do you mean that I need to test the number of units in order to find the best solution? But if I have many hidden layers, do I need to test many times? It should become a time-consuming task.

Hello @kaian0414

Sadly, there is no magic pill in this case - It does involve a trial and error process. As @TMosh pointed out, it is a balancing act with accuracy/performance on one side and the hardware cost/speed/computation time on the other.

Oh… Need time to try, thanks!