Ajey
Ajey

Reputation: 35

tensorflow conv2d number of parameters

Want to know why number of parameters in conv2d is more by 1 than what I expect...

import tensorflow as tf
import tensorflow.keras as keras
input_shape = (40, 512, 512, 1)
conv2d = keras.layers.Conv2D(input_shape=input_shape[1:],
                         filters=1,
                         kernel_size=3,
                         strides=(1, 1),
                         padding='same')

model = keras.Sequential(conv2d)
model.compile()
model.summary()

Output:

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d (Conv2D)              (None, 512, 512, 1)       10        
=================================================================
Total params: 10
Trainable params: 10
Non-trainable params: 0
_________________________________________________________________

As kernel size is 3, I was expecting it to be Param # as 9 but its 10.

Upvotes: 1

Views: 939

Answers (1)

Sycorax
Sycorax

Reputation: 1386

By default, use_bias=True. There's a bias for each filter, so in this case you add 1 more parameter for the bias. This gives a total of 10 parameters.

Upvotes: 1

Related Questions