简体   繁体   English

使用 Keras 使用 Python 进行深度学习的介绍部分

[英]Introduction part in Deep Learning with Keras using Python

Instruction of questions:问题指导:

  1. Instantiate a Sequential model.实例化一个顺序 model。
  2. Add a Dense layer of 50 neurons with an input shape of 1 neuron.添加一个由 50 个神经元组成的密集层,输入形状为 1 个神经元。
  3. Add two Dense layers of 50 neurons each and 'relu' activation.添加两个密集层,每个层有 50 个神经元和“relu”激活。
  4. End your model with a Dense layer with a single neuron and no activation.以具有单个神经元且无激活的 Dense 层结束 model。

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.model.add(Dense(___,___=___))中,您有三个空白。 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 .第一个用于提及神经元的数量,第二个用于表示您想要设置一些activation值,第三个用于将该值设置为relu

So you will get model.add(Dense(50,activation='relu'))所以你会得到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.文档中,Dense 层唯一需要的参数是units ,即神经元的数量。 The default activation function is None , so if you want it to be "relu" , do activation="relu" .默认激活 function 是None ,所以如果你希望它是"relu" ,请执行activation="relu"

In conclusion, this is that piece of code that creates a Dense layer with 50 neurons and activation as relu :总之,这是一段代码,它创建了一个具有 50 个神经元并激活为relu的 Dense 层:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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