简体   繁体   中英

How can I choose the value of output neurons for the hidden layer of tf.keras model?

I am new to Keras and starting with this code from tf tutorial :

# choosing the layers of my models 
model = keras.Sequential([ # the sequential model of Keras library 
    keras.layers.Flatten(input_shape=(28, 28)), # the first input layer
    keras.layers.Dense(128, activation='relu'),# the hidden layer 
    keras.layers.Dense(10)# output layers and 10 corresponds to the number of used classes 
])

I wonder what the value 128 is? and how it was calculated?

128 is a hyper parameter which is the number of nodes in your second to last layer.

It isn't calculated, you can change it to whatever you want, try [18,32,64...etc] . The larger you make it the slower your training will be; however your model might be more accurate since there are more nodes to capture the signal of your dataset.

It's not calculated, it's a hyperparameter (a parameter that isn't estimated by the data, but selected by you prior to running the model). It essentially determines the complexity of the model. The more neurons, the more complex relationships it can model in the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM