2017-07-19 47 views
1

我在CNN中使用TensorFlow庫,python。如何在TensorFlow中爲CNNs算法開發隨機梯度下降優化器?

我想開發細胞神經網絡優化具有下列參數的隨機梯度下降優化:

learning rate = 0.05, 
decay = 1e-6, 
Nesterov momentum 0.9 

我想知道我應該如何改變我的代碼來實現這一目標。這裏是我到目前爲止的代碼:

optimizer = tf.train.AdamOptimizer(learning_rate=0.05).minimize(cost) 

謝謝。

回答

1

這可以很容易地通過使用MomentumOptimizer(https://www.tensorflow.org/api_docs/python/tf/train/MomentumOptimizer)和指數衰減(https://www.tensorflow.org/versions/r0.12/api_docs/python/train/decaying_the_learning_rate)來完成:

global_step = tf.Variable(0, trainable=False) 
starter_learning_rate = 0.05 
learning_rate = tf.train.exponential_decay(starter_learning_rate, global_step, 
             1000, 0.96, staircase=True) 

optimizer = tf.train.MomentumOptimizer(learning_rate=learning_rate, momentum=0.9, use_nesterov=True).minimize(cost, global_step=global_step) 
+0

我用你的算法,但成本函數的返回值楠。這是我的成本函數:cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits = pred,labels = y)) – MSN

+0

立即或在幾個時代之後?它適用於亞當? –

+0

是的,它與亞當一起工作,但是當我使用動量時,這是我的結果: – MSN

相關問題