Reputation: 999
My question concerns the dimensions of the tensors involved in a Conv1D layer in Keras. The input shape is supposed to be (batch, steps, channels). I have for example Accelerometer data, where I get a time signal for each Axis. I would like to do inference on time windows of length 50, so one sample for inference has the shape (50, 3).
Now, if I use a Conv1D layer as first layer on this data with kernel_size=10 and filters=64 the outcome of the first layer on one window of data has the shape (41, 64). I completely understand that 41 pops up, as it is the number of samples that arises from the convolution of a length 50 signal with a length 10 kernel. However, I am not entirely sure where the three axis of my accelerometer are in these data. I would have more expected the following behavior:
input_shape = (batch, steps, channels), output_shape = (batch, steps_after_conv, channels, filters)
Can somebody explain that behavior of Keras? I did not quite understand it from the documentation.
Upvotes: 1
Views: 397
Reputation: 3436
As shown in the image given above (Image courtesy: http://followtheart.info/kareff-Mon_15_14.html), in a convolution
operation in a CNN
, each filter convolves over all channels (three channels in case of an RGB image) for calculating output value. So in your case of 64 filters, each filter will take values from all input channels in its receptive field. Hence your output will have outputs from 64 filters irrespective of the number of channels you have in your input.
For a batch of images (batch_size, num_channels, height, width)
, output will be of shape (batch_size, num_filters, height_after_conv, width_after_conv)
.
Upvotes: 1