Currently I am having trouble in making a few elements in a variable as non-trainable. It implies that given a variable such as x,
x= tf.Variable(tf.zeros([2,2]))
I wish to train only x[0,0] and x[1,1] while keeping x[0,1] ans x[1.0] as fixed while training.
Currently tensorflow does provide the option to make any variable non-trainable by using trainable=False
or tf.stop_gradient()
. However, these method will make the all element in x
as non-trainable. My question is how to obtain this selectivity?
You can use
tf.stop_gradient
trick to prevent maskedtf.Variable
elements from training. For example: