tf.train.get_or_create_global_step()用法解析

这个方法是创建一个全局的步数,当然也可以在python里面创建一个全局变量,专门计步的.不过tf里面既然有,用这个更好些吧


import tensorflow as tf
d=tf.train.get_or_create_global_step()
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(d))

初始化为0

tf.train.get_or_create_global_step()用法解析_第1张图片

要加的话,可以d=d+1  或者是tf.assign(d,d+1)


tf.train.get_or_create_global_step()用法解析_第2张图片 

你可能感兴趣的:(人工智能专栏)