How does Conv2d works when input's feature map is different from the kernel weight's input size?

Viewed 68

In this code "x" is an input to the convolutional 2D layer with 1 batch size, 256 both height & width size and 40 feature maps.

And, w is the weight for the convolutional layer, where the kernel size is (3x3), with depth of 10 and with 80 filters.

x = tf.random.uniform((1, 256, 256, 40))
w = tf.random.uniform((3, 3, 10, 80))
out = tf.nn.conv2d(x, w, strides = (1, 1), padding = 'SAME', data_format='NHWC')

output.shape

##############
OUTPUT: 

TensorShape([1, 256, 256, 80])

Here, this particular code works fine, where the output shape is (1x256x256x80). But Why? Here, the input's feature map is not same as the depth, which I think it should be.

According to me, the weight should be of shape (3x3x40x80) instead of (3x3x10x80) where the 3rd position value (i.e; in 2nd index which is 40) should be equal to the 4th position value (i.e; in 3rd index which is 40) of the shape of input.

Otherwise, how would the convolution operation will happen?


*** It also works fine for the weights with the shape ***

  • (3x3x1x80)
  • (3x3x2x80)
  • (3x3x4x80)
  • (3x3x5x80)
  • (3x3x8x80)
  • (3x3x20x80)

It seems like, it works with all the depth which divides 40.

0 Answers
Related