对完全连接层使用单个共享偏置

时间:2018-06-03 07:56:55

标签: tensorflow machine-learning keras deep-learning

我尝试从论文[1]中尝试一些东西,其中要求对FC层中的所有神经元都有一个共同的偏差项,而不是每个神经元的个体偏差。< / p>

如何在Tensorflow中执行此操作?

是否可以创建没有偏差的FC层,最后添加tf.nn.bias_add()?这是正确的方法吗? 如果是,则没有标记将tf.nn.bias_add()设置为trainable。它会起作用吗?

还是其他任何建议?

<小时/> 参考文献:
[1]:Deep Reinforcement Learning with Double Q-Learning (Pg.6 right side)

1 个答案:

答案 0 :(得分:1)

tf.nn.bias_add(value, bias)需要A 1-D Tensor with size matching the last dimension of value。所以只需tf.add即可:

X = tf.placeholder(tf.float32, [None, 32])
W = tf.Variable(tf.truncated_normal([32, 16]))

#Single bias for all the 16 output
bias = tf.Variable(tf.truncated_normal([1]))

#Works as expected
y =  tf.add(tf.matmul(X,W), bias)

#ValueError: Dimensions must be equal, but are 16 and 1 for 'BiasAdd'
z =  tf.nn.bias_add(tf.matmul(X,W), bias)
相关问题