qq_28254507
ProgJ
2018-01-21 02:40
采纳率: 88.1%
浏览 4.9k

CNN算法中怎么使用自调节学习速率

 ........
#---------------------------网络结束---------------------------
loss=tf.losses.sparse_softmax_cross_entropy(labels=y_,logits=logits)
train_op=tf.train.AdamOptimizer(learning_rate=0.05).minimize(loss)
correct_prediction = tf.equal(tf.cast(tf.argmax(logits,1),tf.int32), y_)    
acc= tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
......
for epoch in range(n_epoch):
......
   #training
    train_loss, train_acc, n_batch = 0, 0, 0
    for x_train_a, y_train_a in minibatches(x_train, y_train, batch_size, shuffle=True):
        _,err,ac=sess.run([train_op,loss,acc], feed_dict={x: x_train_a, y_: y_train_a})
        train_loss += err; train_acc += ac; n_batch += 1
    print("   train loss: %f" % (train_loss/ n_batch))
    print("   train acc: %f" % (train_acc/ n_batch))
        ......

怎么能在每次循环里用 初始学习速率/循环次数 (0.05/epoch) 作为当前学习速率,以让下降速率递减

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • caozhy
    已采纳
    点赞 评论
  • u013802188
    花折泪 2018-08-17 01:57

    Configure a model for mean-squared error regression.

    model.compile(optimizer=tf.train.AdamOptimizer(0.01),
    loss='mse', # mean squared error
    metrics=['mae']) # mean absolute error

    Configure a model for categorical classification.

    model.compile(optimizer=tf.train.RMSPropOptimizer(0.01),
    loss=keras.losses.categorical_crossentropy,
    metrics=[keras.metrics.categorical_accuracy])

    点赞 评论

相关推荐