本文介绍了Keras关于层数的困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Keras模型中使用的层数有些困惑.该文件在这件事上相当模糊.

I'm a bit confused about the number of layers that are used in Keras models. The documentation is rather opaque on the matter.

根据杰森·布朗利(Jason Brownlee)的说法,第一层在技术上包括两层,即由input_dim指定的输入层和一个隐藏层.请参阅他的博客上的第一个问题.

According to Jason Brownlee the first layer technically consists of two layers, the input layer, specified by input_dim and a hidden layer. See the first questions on his blog.

在所有Keras文档中,通常将第一层指定为model.add(Dense(number_of_neurons, input_dim=number_of_cols_in_input, activtion=some_activation_function)).

In all of the Keras documentation the first layer is generally specified asmodel.add(Dense(number_of_neurons, input_dim=number_of_cols_in_input, activtion=some_activation_function)).

因此,我们可以制作的最基本的模型是:

The most basic model we could make would therefore be:

 model = Sequential()
 model.add(Dense(1, input_dim = 100, activation = None))

此模型是由一个单层组成,其中100维输入通过单个输入神经元传递,还是由两层组成,第一层为100维输入层,第二层为一维隐藏层?

Does this model consist of a single layer, where 100 dimensional input is passed through a single input neuron, or does it consist of two layers, first a 100 dimensional input layer and second a 1 dimensional hidden layer?

此外,如果我要指定一个这样的模型,它有多少层?

Further, if I were to specify a model like this, how many layers does it have?

model = Sequential()
model.add(Dense(32, input_dim = 100, activation = 'sigmoid'))
model.add(Dense(1)))

这是一个具有1个输入层,1个隐藏层和1个输出层的模型吗?还是一个具有1个输入层和1个输出层的模型?

Is this a model with 1 input layer, 1 hidden layer, and 1 output layer or is this a model with 1 input layer and 1 output layer?

推荐答案

第一个问题,模型是:

1个输入层和1个输出层.

1 input layer and 1 output layer.

第二个问题:

1个输入层

1个隐藏层

1个激活层(乙状结肠)

1 activation layer (The sigmoid one)

1个输出层

对于输入层,这是Keras使用input_dim arg或input_shape进行抽象的,但是您可以在以下位置找到该层:

For the input layer, this is abstracted by Keras with the input_dim arg or input_shape, but you can find this layer in :

from keras.layers import Input

与激活层相同.

from keras.layers import Activation

这篇关于Keras关于层数的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 04:34