如何冻结张量流中变量的某些部分 [英] How to freeze some part of the variable in tensorflow
本文介绍了如何冻结张量流中变量的某些部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到可以通过设置 trainable=False
来冻结变量.我想知道如何只冻结其中的一部分而不是将其拆分为两个变量.
I've noticed that a variable can be frozen by setting trainable=False
. I'm wondering how to freeze only part of it instead of splitting it into two variables.
例如我只想冻结v = tf.Variable(tf.zeros([2])
中的第一个元素.看起来grad_new = tf.multiply(grad, np.array([0,1]))
不起作用.
For example, I only want to freeze the first element in v = tf.Variable(tf.zeros([2])
. It seems that grad_new = tf.multiply(grad, np.array([0,1]))
doesn't work.
推荐答案
问题已解决.
grad_new = tf.multiply(grad, np.array([0,1]))
实际上效果很好.是把代码弄乱的保护程序.
grad_new = tf.multiply(grad, np.array([0,1]))
actually works quite well. It's the saver who mess up the code.
这篇关于如何冻结张量流中变量的某些部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文