[英]Freezing specific values in a weight matrix in tensorflow
假設我有一個看起來像[[a , b ], [c, d]]
權重矩陣,是否可以在Tensorflow中將b
和c
的值固定為零,以便在優化期間它們不會改變?
一些示例代碼:
A = tf.Variable([[1., 0.], [3., 0.]])
A1 = A[:,0:1] # just some slicing of your variable
A2 = A[:,1:2]
A2_stop = tf.stop_gradient(tf.identity(A2))
A = tf.concat((A1, A2_stop), axis=1)
實際上,需要tf.identity
來停止A2之前的梯度。
有三種方法可以做到
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.