tensorflow dropout

咱們都知道dropout對於防止過擬合效果不錯
dropout通常用在全鏈接的部分,卷積部分不會用到dropout,輸出曾也不會使用dropout,適用範圍[輸入,輸出)
1.tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None, name=None)
2.tf.nn.rnn_cell.DropoutWrapper(rnn_cell, input_keep_prob=1.0, output_keep_prob=1.0)java

普通dropout

def dropout(x, keep_prob, noise_shape=None, seed=None, name=None)
#x: 輸入
#keep_prob: 名字表明的意思
#return:包裝了dropout的x。訓練的時候用,test的時候就不須要dropout了
#例:
w = tf.get_variable("w1",shape=[size, out_size])
x = tf.placeholder(tf.float32, shape=[batch_size, size])
x = tf.nn.dropout(x, keep_prob=0.5)
y = tf.matmul(x,w)

 

rnn中的dropout

1 def rnn_cell.DropoutWrapper(rnn_cell, input_keep_prob=1.0, output_keep_prob=1.0):
2 #
3 lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(size, forget_bias=0.0, state_is_tuple=True)
4 lstm_cell = tf.nn.rnn_cell.DropoutWrapper(lstm_cell, output_keep_prob=0.5)
5 #通過dropout包裝的lstm_cell就出來了
View Code
相關文章
相關標籤/搜索