Channel ordering of DepthwiseConv2D depth_multiplier

I’m wondering how the depth_multiplier in DepthwiseConv2D is reflected in the ordering of the output channels. Let’s say the input channels are ordered with the name 1, 2 ... , how will the output channels be ordered, are they 1a, 1b, 2a, 2b,... or 1a, 2a, ..., 1b, 2b, ... where a and b would represent the two variations when using a depth_multiplier of 2?

I need this info to do the following; Imagine a 2D signal represented as a 4D input tensor with the following shape:

batch x xdim x ydim x channels

When using a kernel of size 1 x ydim the respective output shape of a DepthwiseConv2D with a certain depth_multiplier and no padding would be

batch x xdim x 1 x channels*depth_multiplier

I want to transform this shape to

batch x xdim x depth_multiplier x channels

And hence need to know the ordering of the output channels. Thanks.

Hi @LeNerd, DepthwiseConv2D determines the number of output channels for each input channel. For example, if the input has 3 channels and the depth_multiplier is set to 2, then the output will have 6 channels. The output channels are ordered by their corresponding input channels, with each group of output channels corresponding to one input channel. So, the first group of output channels will correspond to the first input channel. Coming to the output,

4D tensor with shape:[batch_size, channels * depth_multiplier, new_rows,new_cols] if data_format='channels_first'
4D tensor with shape: [batch_size,new_rows, new_cols, channels * depth_multiplier] if data_format='channels_last'.

Thank You.

1 Like

Thanks! So in layman’s terms if your input channels would be named a, b and c your output channels would correspond to a1, a2, b1, b2, c1, c2 as the output channels are grouped per input channel and a depth_multiplier of 2 was chosen :slight_smile: