tensorflow / models

Models and examples built with TensorFlow
Other
77.23k stars 45.75k forks source link

Is there a way to extract gradients at each iteration step from a `tf.estimator.DNNLinearCombinedClassifier` model? #3579

Closed ozkansafak closed 6 years ago

ozkansafak commented 6 years ago

I'm trying to to implement the SWATS optimization algorithm.

I'm able to extract the weights values by model.get_variable_value(name). Is there a similar way to extract the gradients while using an tf.train.AdamOptimizer or a tf.train.GradientDescentOptimizer?

Z-Zheng commented 6 years ago

The graph for training contains grad tensors corresponding to TRAINABLE_VARIABLES, so you can call tf.get_default_graph().get_tensor_by_name("tensor_name:0") to get it if you use default_graph.