1
$\begingroup$

Suppose I have a sequence data of size $B \times N \times d$ where $B$ is the batch size, $N$ is the sequence length, and $d$ is the dimension or the number of features. Suppose I want to do 1D convolution using Tensorflow. For simplicity let us assume that the number of filter is 1.

As far as I know, if the data is $d$-dimensional then the kernel is also $d$-dimensional and the convolution is done per channel. That is, $i$-th sequence is convoluted by $i$-th kernel so by this logic we will have $d$ convolution results. But, as the number of filter is 1 then we will aggregate all convolution results into one. My question is in Tensorflow (or generally) how do we the aggregation? Thanks.

$\endgroup$

1 Answer 1

2
$\begingroup$

I’ll answer the last question first :) Aggregation is typically done by “pooling” and this can output the either the mean of the inputs, the max, or the min. These are done with pooling layers, for example From the tensorflow documentation: https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPool1D

“Downsamples the input representation by taking the maximum value over a spatial window of size pool_size. The window is shifted by strides. The resulting output, when using the "valid" padding option, has a shape of: output_shape = (input_shape - pool_size + 1) / strides) enter image description here

To answer the first question, convolution is usually thought of as sliding a window of some kernel size along the input, multiplying the kernel by the input, and then pooling to create the output. The stride is the amount that the window slides, the kernel dimension is how big your kernel is (typically much smaller than input dimension), and the input dimension is how long a single instance of the training data is. In the 1d example diagram above, the kernel is dimension is 3, input dimension is 5, and the output of the max pooling is 1x3. So to clarify your second paragraph, the data and kernel size aren’t usually the same, all inputs are convoluted by the same kernel (if you only have one), and the size of the output will depend on your input size, kernel size, stride, and pooling. Typically you’ll want to have more than one filter btw.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.