Keras - 1D Convolution How it works

In convolutional neural networks (CNNs), 1D and 2D filters are not really 1 and 2 dimensional. It is a convention for description.

In your example, each 1D filter is actually a Lx50 filter, where L is a parameter of filter length. The convolution is only performed in one dimension. That may be why it is called 1D. So, with proper padding, each 1D filter convolution gives a 400x1 vector. The Convolution1D layer will eventually output a matrix of 400*nb_filter.


Coming from a background of signal processing it also took me while to understand the concept of it and it seems to be the case of many people in the community.

Pyan gave a very good explanation. As it is often explained with words in many forums, I made a little animation the I hope will help.

See below the input tensor, the filter (or weight) and the outputed tensor. You can also see the size of the output tensor as a function of the number of filters used (represented with different colours).

Visual Representation of the 1D Convolultion (Simplified)

Note that to perform the scalar multiplication between the input and the filter, the filter should be transposed. There are also different implementations (Karas, Tensorflow, Pytorch...), but I think this animation can give a good representation of what is happening.

Hope it can help someone.