# what happens to the depth channels when convolved by multiple filters in a cnn (keras, tensorflow)

I have a $$15$$-channel time series that I want to convolve using a $$1$$d CNN ($$1\times n$$ time-steps kernel). Now, let's say I want to have, as my first layer, $$16$$ filters. This would imply to my mind that the output would have a depth of $$16 \times 15 = 240$$, because each filter would be applied to each channel independently. However when I implement this in keras, (using Sequential) the filter dimensions in the summary do not reflect this. Here is a code fragment:

TIME_RANGE = 31
NUMBER_OF_CHANNELS = 15

model = Sequential()
filters=16,
kernel_size=7,
data_format='channels_last'))

kernel_size=5,


and here is the corresponding summary output:

Layer (type)                 Output Shape              Param #


=================================================================

conv1d_1 (Conv1D)            (None, 25, 16)            1696


re_lu_1 (ReLU)               (None, 25, 16)            0


batch_normalization_1 (Batch (None, 25, 16)            64


conv1d_2 (Conv1D)            (None, 21, 32)            2592


as you can see output's shape along the time-wise axis decreases as expected due to the no-padding argument, from $$31$$ to $$25$$ to $$21$$, but the depth just reflects the number of filters-- so where have all my channels gone? At this point in the architecture I was expecting a depth of $$15\times 16\times 32 = 7680$$. It seems an implicit $$1\times 1$$ convolution is occurring somewhere, which I don't think I actually want-- I'd like to do my $$1\times 1$$ convolutions later on in the network. So what am I missing here?

When you have a image dimension of HxWxC and you apply a convolutional layer with filter size F and kernel size KxK, you will be sliding F different KxKxC kernels over your image, resulting in the output dimension of the total operation being H'xW'xF which is what you are seeing.

• thanks for responding to my question, but you haven't actually answered it! My question is what happens to all the channels (and the information they contain?) – Tel Jan 5 '19 at 1:26
• I think it does: the convolutional filters are functions of all C layers. You have F of them. You could sort of say the convolutional layer outputs F new "channels", though they're not interpretable as colors like the channels of the original image. – Sean Owen Jan 5 '19 at 18:57
• OK fair enough I didn't really pose the question well-- what I was after was a solution to my problem, not an explanation. I should have stated that explicitly. – Tel Jan 6 '19 at 0:38

Well I've figured it out. I need to use a depth-wise convolution. In tensorflow/keras this is implemented using DepthwiseConv2D. The depth_multiplier argument will create a new set of channels for every set of input channels, so 15 input channels with a depth multiple of 16 will create 240 output channels (instead of just 16).

Because I'm dealing with a 1D signal I just make the kernel height 1. There is an extra input dimension that also need to be 1.

Here is a fragment:

TIME_RANGE = 31
NUMBER_OF_CHANNELS = 15

from keras.layers import DepthwiseConv2D

model = Sequential()