Help me understand the input_shape

Firstly, from what I have seen the input_shape of keras.layers should be a tuple e.g. (50, 50, 3), why in the second week it is a list [20]?

# Build the single layer neural network
l0 = tf.keras.layers.Dense(1, input_shape=[window_size])
model = tf.keras.models.Sequential([l0])

Secondly, I get the intuition that Dense layer receives window_size data and outputs the next value as the prediction for that from the code, but in the 4th week, the input_shape is a list of [None, 1], what does that mean, what is the shape of input?
Can someone please answer and explain those 2 questions, thank you.

Some Keras functions can accept either a vector or a tuple.

You only have a 3-element tuple if the data set has three dimensions (such as a color image) with red/green/blue planes)

When a dimension is set to “None”, it means the value will be provided later during training. Often this is used when you don’t yet know how many examples ‘m’ you will have.

1 Like

@Namhoang Thanks for the quesiton,

Answering your first question,

the input shape of a layer can be either a tuple or a vector. The most common would be a 2D input with shape:
(batch_size, input_dim)

In this lab though, the input is a list with a size as the windowed data size.
This can be written as in the 4th week:
l0 = tf.keras.layers.Dense(1, input_shape=(window_size,))

if you inspect the model summary for both writings, it would be the same.


Thank you for the answers, is there a link for reference or document(ebook for example) where I can get better intuition about the input_shape of neural network? I sometimes find it hard to input that parameter correctly.

@Namhoang Sure,
you can check the following post:

and I would check also the tensorflow documentation input_shape:

Please feel free to ask more question about this point or any other point.