0

我有一些神经网络(张量流)

    n_steps = 10
    n_inputs = 3
    n_outputs = 1
    n_neurons = 100
    n_layers = 3
    X = tf.placeholder(tf.float32, [None, n_steps, n_inputs])
    y = tf.placeholder(tf.float32, [None, n_steps, n_outputs])

    layers = []
    for i in range(n_layers):
        layers.append(tf.contrib.rnn.BasicRNNCell(num_units=n_neurons, activation=tf.nn.relu))


    multi_layer_cell = tf.contrib.rnn.MultiRNNCell(layers)

    rnn_outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)

像这样(下)是正确的?它正在工作,但我不确定;)

training = tf.placeholder_with_default(True,shape=())
X_dropout = tf.layers.dropout(X,dropout_rate,training=training)
rnn_outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X_dropout, dtype=tf.float32)

如何添加到这个神经网络 tensorflow dropout?

感谢您的任何建议!

4

1 回答 1

1

您的代码只是对 input 进行了 dropout X,您应该使用tf.contrib.rnn.DropoutWrapper( link )。

layers = []
for i in range(n_layers):
    layers.append(tf.contrib.rnn.DropoutWrapper(tf.contrib.rnn.BasicRNNCell(num_units=n_neurons
                                                                            , activation=tf.nn.relu)
                                                ,output_keep_prob=1-dropout_rate))
于 2019-01-04T05:51:52.750 回答