0
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$ – noe Feb 24 at 18:46
  • $\begingroup$ @noe thanks for providing an answer. I require some more knowledge to appreciate the answer. In search of the knowledge. $\endgroup$ – hanugm Feb 25 at 4:57
  • $\begingroup$ I added more information to make it clearer. $\endgroup$ – noe Feb 25 at 8:10
1
$\begingroup$

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):

enter image description here

The missing parts in the picture are the batch size (4) and the output time length (8).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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