简体   繁体   中英

How to check number of times a Weight Tensor has been updated in TensorFlow?

I have a simple question. I have created my own weights using tf.get_variable . For debugging purposes I need to check how many times the weights have been updated, ie how many times the optimizer have actually updated the weight?

How can this be done? If you require my code I can provide it.

That is usually called in TensorFlow the "global step", and it has some helper functions for it:

global_step = tf.train.create_global_step()
optimizer.minimize(loss, global_step=global_step)

tf.train.get_global_step really just creates a variable, but making sure it is not trainable and adding it to the right collections. You also have tf.train.get_global_step so you can do:

optimizer.minimize(loss, global_step=tf.train.create_global_step())

And at some other point in the code retrieve the tensor like:

global_step = tf.train.get_global_step()

Moreover, you can use tf.train.get_or_create_global_step if you are not sure which part of the graph definition will go first.

The is one more function, tf.train.global_step , but I don't think it serves any purpose currently, since it just runs the given tensor in the given session and returns its value as an integer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM