Folks, can someone please help: Why is the batch size not specified here?
In all videos of week 3 and 4, instructor specifies input shape as (batch size, window_size, feature_size) or (None, 1) but here just says input_shape = [window_size]. Why? Neither does he use batch_size parameter in model.fit ( )
How does the sequential model magically know input shape is going to be a batch of 32 training examples i.e. 32 x 20 x 1 and not 20 x 1? If batch_size = 50, how would model know to expect data of 50 x 20 x 1 without mentioning that anywhere?
Hi Aditya,
In model.fit, the default value for batch size is 32. In case nothing has been passed, it’ll be assumed to be 32. Since the batch size in the above program is also 32, it wasn’t explicitly passed as that’s the default value anyway. Refer ‘fit’ section in the documentation.
batch_size : Integer or None
. Number of samples per gradient update. If unspecified, batch_size
will default to 32. Do not specify the batch_size
if your data is in the form of datasets, generators, or keras.utils.Sequence
instances (since they generate batches).
In the input layer, the batch size is optional again, if you refer the documentation, you can specify the ‘shape tuple’ or the ‘tensor shape’. The batch size is optional either way and independent. Similarly, if you don’t use the input layer explicitly but use the Keras Functional model via Input
(like in this example), the requirement remains the same.
input_shape
: Shape tuple (not including the batch axis), or TensorShape
instance (not including the batch axis).
batch_size
: Optional input batch size (integer or None
).
Hope this helps, thanks.
1 Like
Is your query solved sir?