Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does TensorFlow Conv2D have two weights matrices?

I have a tf.keras.layers.Conv2D constructed like so:

>>> conv2d_layer = tf.keras.layers.Conv2D(filters=128, kernel_size=(3, 3), strides=2)

For reference that layer is part of a network where the prior layer is prior_layer = Conv2D(filters=64, kernel_size=(3, 3), strides=2).

When I call conv2d_layer.get_weights(), it returns a list with two entries:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>>> [w.shape for w in conv2d_layer.get_weights()]
[(3, 3, 64, 128), (128,)]

Why are there two np.ndarrays in conv2d_layer.get_weights()? What are their respective meanings?

>Solution :

The first shape is for the weights of your conv2D, and the second one is the bias for the same layer, which is represented by a vector.

Looking at the documentation, you can see

For example, a Dense layer returns a list of two values: the kernel matrix and the bias vector. These can be used to set the weights of another Dense layer:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading