Is tf.layers.dense a single layer?

三世轮回 提交于 2020-03-17 08:30:14

问题


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?

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.

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 is my input features tensor.


回答1:


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)

My network seemed to work properly with just 1 layer, so I was curious about the setup.

That is possible, for some tasks you will get decent results without hidden layers.




回答2:


tf.layers.dense is only one layer with a amount of nodes. You can check on TensorFlow web site about tf.layers.dense

layer1 = tf.layers.dense(inputs=pool2_flat, units=1024, activation=tf.nn.relu)
layer2 = tf.layers.dense(inputs=layer1, units=1024, activation=tf.nn.relu)


来源:https://stackoverflow.com/questions/45693020/is-tf-layers-dense-a-single-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!