Reputation: 94
I have a free varaible (tf.variable) x, and I wish to minimize an error term with respect to subset of the tensor x (for example minimizing the error only with respect to the first row of 2D tensor).
One way is to compute the gradients and change the gradient to zero for the irrelevant parts of the tensor and apply the gradients. Is their another way?
Upvotes: 1
Views: 152
Reputation: 17201
You can use mask
and tf.stop_gradient
to selectively make the variable non-trainable: tf.stop_gradient(mask*x)
. The value in matrix mask
1 should denote parts to apply gradient and 0 otherwise.
Upvotes: 1