# Conv1D layer input and output

Consider the following code for Conv1D layer

# The inputs are 128-length vectors with 10 timesteps, and the batch size
# is 4.
input_shape = (4, 10, 128)
x = tf.random.normal(input_shape)
y = tf.keras.layers.Conv1D(32, 3, activation='relu',input_shape=input_shape[1:])(x)
print(y.shape)
(4, 8, 32)


It has been given that there are 10 vectors, with each of length 128. Then how does the output will be of shape (8, 32)?

If we apply a filter of size 3, we will then get a vector of length 126, if stride is 1. But, I cannot see 126 anywhere in the output.

How to understand the shapes of input and output?

• Please consider upvoting the answer if you found it useful, and also mark it as correct if deemed so. Alternatively, please comment on what you think the answer lacks or what is not clear. – noe Feb 24 at 18:46
• @noe thanks for providing an answer. I require some more knowledge to appreciate the answer. In search of the knowledge. – hanugm Feb 25 at 4:57
• I added more information to make it clearer. – noe Feb 25 at 8:10

## 1 Answer

As described on the linked page, 128 is the dimensionality of each vector (i.e. the number of input channels), and 10 is the number of timesteps.

8 is the resulting number of timesteps after applying the filter of size 3 to the initial 10 timesteps.

In order to make it clearer, let's visualize the 1D convolution (source): The missing parts in the picture are the batch size (4) and the output time length (8).