C4 W2 A2 Transfer Learning

Hi

When running the Alpaca model, I get the following error.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-35-11ffc7a7acb3> in <module>
----> 1 model2 = alpaca_model(IMG_SIZE, data_augmentation)

<ipython-input-34-b7e1c5914eb8> in alpaca_model(image_shape, data_augmentation)
     30 
     31     # data preprocessing using the same weights the model was trained on
---> 32     x = preprocess_input(x)
     33 
     34     # set training to False to avoid keeping track of statistics in the batch norm layer

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/applications/mobilenet_v2.py in preprocess_input(x, data_format)
    500 @keras_export('keras.applications.mobilenet_v2.preprocess_input')
    501 def preprocess_input(x, data_format=None):
--> 502   return imagenet_utils.preprocess_input(x, data_format=data_format, mode='tf')
    503 
    504 

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/applications/imagenet_utils.py in preprocess_input(x, data_format, mode)
    117   else:
    118     return _preprocess_symbolic_input(
--> 119         x, data_format=data_format, mode=mode)
    120 
    121 

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/applications/imagenet_utils.py in _preprocess_symbolic_input(x, data_format, mode)
    261   """
    262   if mode == 'tf':
--> 263     x /= 127.5
    264     x -= 1.
    265     return x

TypeError: unsupported operand type(s) for /=: 'Sequential' and 'float'

I don’t know what I am doing wrong. Can someone help me, please?
Thank you!

The way you’re initializing x is incorrect. Be sure to invoke the __call__ method of the data_augmentation` sequential model.

What code did you use to set the initial value of x?

What that error message is telling you is that x is not a tensor: it’s a Sequential model object. As Balaji says, it’s important to keep track of which things are functions and which are tensors. We’re in pretty deep waters here. One way to get a better view of all this is to have a look at this thread about the Keras Sequential and Functional models.