问题描述
如果我只使用这样的单层:
If I just use a single layer like this:
layer = tf.layers.dense(tf_x, 1, tf.nn.relu)
这仅仅是一个具有单个节点的单层吗?
Is this just a single layer with a single node?
或者它实际上是一组具有1个节点的图层(输入,隐藏,输出)吗?我的网络似乎只能在1层上正常工作,所以我对设置感到好奇.
Or is it actually a set of layers (input, hidden, output) with 1 node? My network seemed to work properly with just 1 layer, so I was curious about the setup.
因此,下面的此设置是否具有2个隐藏层(layer1
和layer2
均为隐藏层)?还是实际上只有1个(仅layer 1
)?
Consequently, does this setup below have 2 hidden layers (are layer1
and layer2
here both hidden layers)? Or actually just 1 (just layer 1
)?
layer1 = tf.layers.dense(tf_x, 10, tf.nn.relu)
layer2 = tf.layers.dense(layer1, 1, tf.nn.relu)
tf_x
是我的输入特征张量.
tf_x
is my input features tensor.
推荐答案
tf.layers.dense
将单个图层添加到您的网络.第二个参数是该层的神经元/节点数.例如:
tf.layers.dense
adds a single layer to your network. The second argument is the number of neurons/nodes of the layer. For example:
# no hidden layers, dimension output layer = 1
output = tf.layers.dense(tf_x, 1, tf.nn.relu)
# one hidden layer, dimension hidden layer = 10, dimension output layer = 1
hidden = tf.layers.dense(tf_x, 10, tf.nn.relu)
output = tf.layers.dense(hidden, 1, tf.nn.relu)
这是可能的,对于某些任务,您将获得体面的结果而没有隐藏的图层.
That is possible, for some tasks you will get decent results without hidden layers.
这篇关于tf.layers.dense是单层吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!