简体   繁体   中英

Introduction part in Deep Learning with Keras using Python

Instruction of questions:

  1. Instantiate a Sequential model.
  2. Add a Dense layer of 50 neurons with an input shape of 1 neuron.
  3. Add two Dense layers of 50 neurons each and 'relu' activation.
  4. End your model with a Dense layer with a single neuron and no activation.

Below is my code:

# Instantiate a Sequential model
model = Sequential()

# Add a Dense layer with 50 neurons and an input of 1 neuron
model.add(Dense(50, input_shape=(2,), activation='relu'))

# Add two Dense layers with 50 neurons and relu activation
model.add(Dense(____,____=____))
model.____

# End your model with a Dense layer and no activation
model.____

I am confused about the part

model.add(Dense(____,____=____))

In model.add(Dense(___,___=___)) , you have three blanks. The first one is for mentioning number of neurons, the second one for saying that you want to set some value for activation and the third one is for setting that value as relu .

So you will get model.add(Dense(50,activation='relu'))

More information can be found in the Dense layer documentation .

In the documentation , the only required parameter for the Dense layer is units , which is the number of neurons. The default activation function is None , so if you want it to be "relu" , do activation="relu" .

In conclusion, this is that piece of code that creates a Dense layer with 50 neurons and activation as relu :

model.add(Dense(50, activation="relu"))

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