我正在考虑创建一个定制的神经网络。基本结构和往常一样,但我想截断层与层之间的连接。例如,如果我构建一个具有两个隐藏层的网络,我想删除一些权重并保留其他权重,如下所示:
这不是传统的dropout
(以避免过度拟合),因为应该指定并固定剩余的权重(连接)。
python有什么方法可以做到吗? Tensorflow、pytorch、theano 或任何其他模块?
最佳答案
是的,您可以在 tensorflow 中执行此操作。
你的 tensorflow 代码中会有这样的层:
m = tf.Variable( [width,height] , dtype=tf.float32 ))
b = tf.Variable( [height] , dtype=tf.float32 ))
h = tf.sigmoid( tf.matmul( x,m ) + b )
你想要的是一些新的矩阵,我们称它为 k 表示 kill。它会杀死特定的神经连接。神经连接在 m 中定义。这将是您的新配置
k = tf.Constant( kill_matrix , dtype=tf.float32 )
m = tf.Variable( [width,height] , dtype=tf.float32 )
b = tf.Variable( [height] , dtype=tf.float32 )
h = tf.sigmoid( tf.matmul( x, tf.multiply(m,k) ) + b )
您的 kill_matrix 是一个由 1 和 0 组成的矩阵。为您想要保留的每个神经连接插入一个 1,为您想要杀死的每个神经连接插入一个 0。
关于python - 在训练期间固定神经网络中的一部分权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43851657/