Doubt in happy_model.summary() Shapes

1
In this section of the week, 1 assignment 2 I am confused as to why are there None values in the Output Shape? And like we mentioned the shape (64,64,3) why didn’t we mention the number of training example because we know that it is 600. We should have done it like tfl.ZeroPadding2D( padding = 3, input_shape=(600,64,64,3), data_format = “channels_last” ) instead of tfl.ZeroPadding2D( padding = 3, input_shape=(64,64,3), data_format = “channels_last” )

Hey @Chinmay_Sahoo,
Here, None represents the Number of data-points in a single batch. When we train any model, we generally use a batch size < dataset size, i.e., mini-batch gradient descent, as you might have learnt in Course 2 of DLS. Now, let’s say for this case, we take the batch-size as 70. In that case, the first 8 batches would have 70 examples each, but the 9th batch would have 40 examples only.

And hence, a dynamic batch size allows us to train the model without any further modifications required. Also, if you will notice, the tensorflow API is made in such an amazing way, that we don’t need to define the batch size in any of the layers. It automatically finds it and use it once we have defined the batch size while loading the dataset in the tensor format.

However, as far as the possibility of doing this goes, it is possible to define the model in this way. In that case, you would have to make sure that all your batches have the same number of examples, otherwise your model will raise error during the course of training, most likely, in the last batch. Here’s an example from the Tensorflow docs, in which they have defined the batch-size in the layer. I hope this helps.

Regards,
Elemento

In the code if I use input_size = (10,64,64,3) wich means I want to use mini batch size of 10 then it throws me an error “Input 0 of layer “zero_padding2d_9” is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: (None, 10, 64, 64, 3)”.

And we do have to define the batch size while using the .fit() command. My question is that in the documentation of tf.keras.layers.ZeroPadding2D they said that we have to mention the input size as ( batch_size, rows, cols, channels ), but in the programming exercise we didn’t do that and if I do mention the batch size it shows me the error so is the documentation incorrect?

Hey @Chinmay_Sahoo,
You can check this Kernel, Version 1 out for a better understanding. Also, do check this amazing StackOverflow Thread. I hope these help. Feel free to make a copy of the kernel and play with it, unless you get a crystal clear understanding of the concept.

Regards,
Elemento