Neal
Neal

Reputation: 942

tf.layers.conv2d: Are use_bias=False and bias_initializer=None the same?

From what I can tell, tf.layers.conv2d has two different ways of disabling biases: setting use_bias=False and setting bias_initializer=None.

Are these the same, or do they do different things? Do I need to use both?

Upvotes: 1

Views: 2475

Answers (2)

xxi
xxi

Reputation: 1510

I'm not sure bias_initializer=None can disable bias

a little test

data = np.random.rand(2, 5, 8, 3).astype(np.float32)
tensor = tf.constant(data)
n = tf.layers.conv2d(tensor, 10, 3, 1, bias_initializer=None)
tfvar = tf.trainable_variables()
# tfvar 
# [<tf.Variable 'conv2d/kernel:0' shape=(3, 3, 3, 10) dtype=float32_ref>, 
# <tf.Variable 'conv2d/bias:0' shape=(10,) dtype=float32_ref>]

even set bias_initializer=None, get bias as trainable variables

Upvotes: 1

Autonomous
Autonomous

Reputation: 9075

You can either set use_bias = False or set bias_initializer=None to disable bias. I think the first one is more intuitive. However, not setting bias_initializer will make it zeros and not setting kernel_initializer will make it glorot_uniform according to this answer.

Upvotes: 0

Related Questions