Tensorflow: Trainable Variable Masking

半腔热情 提交于 2019-12-01 07:37:43

问题


I am working on a convolutional neural net that requires some parts of the a kernel weights to be untrainable. tf.nn.conv2d(x, W) takes in a trainable variable W as weights. How can I make some of the elements of W to be untrainable?


回答1:


Maybe you could have your trainable weights W1, a mask M indicating where the trainable variables are, and a constant / untrainable weight matrix W2, and use

W = tf.multiply(W1, tf.cast(M, dtype=W1.dtype)) + tf.multiply(W2, tf.cast(tf.logical_not(M), dtype=W2.dtype)) 


来源:https://stackoverflow.com/questions/44774672/tensorflow-trainable-variable-masking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!