[英]Keras clarification on definition of hidden layer
I am following a tutorial on building a simple deep neural network in Keras, and the code provided was: 我正在跟踪有关在Keras中构建简单的深度神经网络的教程,提供的代码是:
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
Is the first model.add
line to define the first hidden layer, with 8 inputs in the input layer? 是第一个
model.add
行定义第一个隐藏层,在输入层中有8个输入吗? Is there thus no need to specify the input layer except for the code input_dim=8
? 因此,除了代码
input_dim=8
之外,是否需要指定输入层?
You're right. 你是对的。
When you're creating a Sequential
model, the input "layer" *
is defined by input_dim
or by input_shape
, or by batch_input_shape
. 在创建
Sequential
模型时,输入“ layer” *
由input_dim
或input_shape
或batch_input_shape
。
*
- The input layer is not really a layer, but just a "container" for receiving data in a specific format. *
-输入层实际上不是一个层,而只是一个用于接收特定格式数据的“容器”。
Later you might find it very useful to use functional API models instead of sequential models. 稍后,您可能会发现使用功能性API模型而不是顺序模型非常有用。 In that case, then you will define the input tensor with:
在这种情况下,您将使用以下命令定义输入张量:
inputs = Input((8,))
And pass this tensor through the layers: 并将该张量通过各层:
outputs = Dense(12, input_dim=8, activation='relu')(inputs)
outputs = Dense(8, activation='relu')(outputs)
outputs = Dense(1, activation='sigmoid')(outputs)
To create the model: 创建模型:
model = Model(inputs,outputs)
It seems too much trouble at first, but soon you will feel the need to create branches, join models, split models, etc. 一开始似乎麻烦太多,但是很快您就会感到需要创建分支,联接模型,拆分模型等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.