其他分享
首页 > 其他分享> > tf.train.GradientDescentOptimizer 优化器

tf.train.GradientDescentOptimizer 优化器

作者:互联网

tf.train.GradientDescentOptimizer(learning_rate, use_locking=False,name=’GradientDescent’)
 参数:
learning_rate: A Tensor or a floating point value. 要使用的学习率
use_locking: 要是True的话,就对于更新操作(update operations.)使用锁
name: 名字,可选,默认是”GradientDescent”

sample

import tensorflow as tf

x = tf.Variable(2, name='x', dtype=tf.float32)
log_x = tf.log(x)
log_x_squared = tf.square(log_x)

optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(log_x_squared)

init = tf.initialize_all_variables()

def optimize():
  with tf.Session() as session:
    session.run(init)
    print("starting at", "x:", session.run(x), "log(x)^2:", session.run(log_x_squared))
    for step in range(10):  
      session.run(train)
      print("step", step, "x:", session.run(x), "log(x)^2:", session.run(log_x_squared))
        

optimize()

标签:session,run,log,squared,train,tf,GradientDescentOptimizer
来源: https://www.cnblogs.com/smallredness/p/11203250.html