I want to get names of slots from Momentum optimizer in tensorflow with using get_slot_names as it is explained here in tensorflow webpage. I am using following line in my code to get them:
slots=tf.train.MomentumOptimizer(learning_rate=1e-3, momentum=0.9,).get_slot_names()
I ran my graph and then when I print slots it return me only an empty list. Any help will be appreciated.
By the way, my network is working fine in minimizing the loss or for other things. Also, I tried it with other optimizers, but it have same problem.
I am using tf 1.3 in ubuntu 14. Thanks,
The only problem in the code is that slot_variables are created during minimize call (actually in apply_gradients). And since you call get_slot_variables() before - they are empty.
So instead of
you should do
The reason for that is really simple - many slots are variables specific, for example methods like Adam will create one slot per each optimised variable, and before calling .minimize - optimiser does not know which variables it will be optimising.
In particular, for MomentumOptimizer you keep accumulated gradients per each variable. Consequently they cannot be computed prior to calling minimize. These accumulated gradients are stored in "momentum" slot (quite bad choice for the name, but this where they are in TF).