我知道偏差与 1
将被添加到每个层的输入向量或者就像它是具有 1
的恒定输出的神经元一样 . 从偏置神经元出来的权重是在训练期间训练的正常权重 .
现在我正在研究Tensorflow中的一些神经网络代码 . 例如 . 这个(它只是CNN(VGGnet)的一部分,特别是CNN的一部分,其中卷积结束并且完全连接的层开始):
with tf.name_scope('conv5_3') as scope:
kernel = tf.Variable(tf.truncated_normal([3, 3, 512, 512], dtype=tf.float32,
stddev=1e-1), name='weights')
conv = tf.nn.conv2d(self.conv5_2, kernel, [1, 1, 1, 1], padding='SAME')
biases = tf.Variable(tf.constant(0.0, shape=[512], dtype=tf.float32),
trainable=True, name='biases')
out = tf.nn.bias_add(conv, biases)
self.conv5_3 = tf.nn.relu(out, name=scope)
self.parameters += [kernel, biases]
# pool5
self.pool5 = tf.nn.max_pool(self.conv5_3,
ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1],
padding='SAME',
name='pool4')
with tf.name_scope('fc1') as scope:
shape = int(np.prod(self.pool5.get_shape()[1:]))
fc1w = tf.Variable(tf.truncated_normal([shape, 4096],
dtype=tf.float32,
stddev=1e-1), name='weights')
fc1b = tf.Variable(tf.constant(1.0, shape=[4096], dtype=tf.float32),
trainable=True, name='biases')
pool5_flat = tf.reshape(self.pool5, [-1, shape])
fc1l = tf.nn.bias_add(tf.matmul(pool5_flat, fc1w), fc1b)
self.fc1 = tf.nn.relu(fc1l)
self.parameters += [fc1w, fc1b]
现在我的问题是,为什么卷积层中的偏差 0
和完全连接的层中的 1
(此模型的每个转换层都有 0
用于偏置,FC层有 1
)?或者我的解释是否仅涵盖完全连接的层,而卷积层则不同?
1 回答
偏差(在任何层中)通常用零初始化,但随机或特定的小值也是可能的 . 引自Stanford CS231n:
其他示例:tf.layers.dense function是创建FC图层的快捷方式,默认情况下使用
zero_initializer
;并且sample CNN对所有权重和偏差使用随机init,它不会影响性能 .因此,总而言之,偏差初始化并不重要(与权重初始化相比),我非常确定您将获得与零或小随机初始化相似的训练速度 .