W3 Lab 3 Only instances of `keras.Layer` can be added to a Sequential model

Advanced Computer Vision with TensorFlow Course Week 4 Lab 3 code shell 3 –

the error was nly instances of keras.Layer can be added to a Sequential model. Received: <tensorflow_hub.keras_layer.KerasLayer object at 0x7c77d7c78b50> (of type <class ‘tensorflow_hub.keras_layer.KerasLayer’>)

@Mohamad_Samruk

The hub.KerasLayer from TensorFlow Hub is not always recognized as a native keras.Layer in a Sequential model. Try using the Functional API instead of Sequential, as it fully supports KerasLayer and pay attention to the implementation guides in the notebook.

Hope it helps! Feel free to ask if you need further assistance.

Exception encountered when calling layer ‘keras_layer_3’ (type KerasLayer).

A KerasTensor is symbolic: it’s a placeholder for a shape an a dtype. It doesn’t have any actual numerical value. You cannot convert it to a NumPy array.

Call arguments received by layer ‘keras_layer_3’ (type KerasLayer):
• inputs=<KerasTensor shape=(None, None, None, 3), dtype=float32, sparse=False, name=keras_tensor_6>
• training=None

I used functional API then the error was -

Exception encountered when calling layer ‘keras_layer_3’ (type KerasLayer).

A KerasTensor is symbolic: it’s a placeholder for a shape an a dtype. It doesn’t have any actual numerical value. You cannot convert it to a NumPy array.

Call arguments received by layer ‘keras_layer_3’ (type KerasLayer):
• inputs=<KerasTensor shape=(None, None, None, 3), dtype=float32, sparse=False, name=keras_tensor_6>
• training=None

The error occurs because the hub.KerasLayer expects inputs with a fully defined shape (like (224, 224, 3)), but it’s receiving a symbolic tensor with undefined spatial dimensions (None, None, None, 3). You should define the input shape explicitly using tf.keras.Input(shape=(224, 224, 3)) and ensure the input images are properly resized and preprocessed to match the expected format of the Hub model.

If you struggle too much, you can share your notebook in private messages so I can take a look at it — but first, try to solve it by yourself!

is your issue resolved?? This is module version issue. Let me know if you still have the issue.

Not yet, please help me

Follow the steps in this LinkedIn comment