简体   繁体   English

Keras澄清隐藏层的定义

[英]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_diminput_shapebatch_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.

相关问题 语法 Keras 层定义 - Syntax Keras layer definition Keras中LSTM中的多层隐藏层 - Multiple Layer hidden layer in LSTM in Keras 如何使用Keras API提取“从输入层到隐藏层”和“从隐藏层到输出层”的权重? - How to extract weights “from input layer to hidden layer” and “from hidden layer to output layer” with Keras API? 给定keras中隐藏层的输入,权重和偏差,如何获得隐藏层的输出? - How to get output of hidden layer given an input, weights and biases of the hidden layer in keras? Keras自定义损失函数,使用隐藏层输出作为目标的一部分 - Keras custom loss function that uses hidden layer outputs as part of the objective 我可以手动将输入神经元插入 Keras 中的隐藏层吗? - Can I manually slot an input neuron into a hidden layer in Keras? KL在隐藏层和任意分布之间的分歧(Keras / TensorFlow) - KL divergence between hidden layer and arbitrary distribution (Keras/TensorFlow) keras自定义损失函数调用隐藏层密集操作 - keras custom loss function call hidden layer dense operations 每个时期的隐藏层 Output 并将其存储在 keras 的列表中? - Output of hidden layer for every epoch and storing that in a list in keras? 在 Tensorflow/Keras 中查看隐藏层的 output 的最简单方法是什么? - Easiest way to see the output of a hidden layer in Tensorflow/Keras?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM