C4,W2,A2 Transfer_learning_with_MobileNet_v1

Exercise 2 - alpaca_model
how to use tf.expand_dims()

Im doing thing data_augmentation(tf.expand_dims(inputs,0))
and having following error

ValueError: Input 0 of layer sequential_1 is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [1, None, 160, 160, 3]

Here’s what 4 dimensions (None, H, W, C) represent:

  1. None: Batch size
  2. H: Height of a single image
  3. W: Widght of a single image
  4. C: number of channels. This is 3 for color images and 1 for greyscale images.

Why do you need tf.expand_dims ?

1 Like

because notebook saying something like this:-
Screenshot 2022-12-07 160730

The instruction asks you apply the augmentation pipeline to the inputs. Please pay attention to the input shape of data_augmentation before augmenting the images. In the example shown after the definition of the function data_augmentation, tf.expand_dims was applied to a single image to create a batch size of 1.