murat_ersen_unal:

why that 32 is not included in output shape of last layer?


As far as I understand, while following the tutorial, running base_model.summary() on its own prints the string summary of the pre-trained MobileNetV2 network with no inputs fed into the model yet (e.g. no image batch tensor of shape (32, 160, 160, 3) has been used as an input), hence the last layer’s output shape of (None, 5, 5, 1280) and the first layer’s shape of (None, 160, 160, 3).



 murat_ersen_unal:

This is the output shape of base_model. So I expected to see (1,5,5,1280) shaped output for one image. However, when ı run:
" feature_batch = base_model(image)
print(feature_batch.shape)"
output is (32,5,5,1280) why there are 32 different layers in first dimension


You set the batch size initially here:
BATCH_SIZE = 32
IMG_SIZE = (160, 160)

train_dataset = tf.keras.utils.image_dataset_from_directory(train_dir,
                                                            shuffle=True,
                                                            batch_size=BATCH_SIZE,
                                                            image_size=IMG_SIZE)
...
# Instantiate the base model
base_model = tf.keras.applications.MobileNetV2(...)
...
image_batch, label_batch = next(iter(train_dataset))
# Pass the image batch (of 32) to the pre-trained MobileNetV2 `base_model()`
feature_batch = base_model(image_batch) 
# Print the shape
print(feature_batch.shape)

which then outputs:
(32, 5, 5, 1280)

If you simply run the same code but without feature extraction:
...
image_batch, label_batch = next(iter(train_dataset))
image_batch.shape # Check the shape

then the shape of the tensor will be:
TensorShape([32, 160, 160, 3])

(where 32 is the batch size.)