Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Only instances of keras.Layer can be added to a Sequential model. Received: <tensorflow_hub.keras_layer.KerasLayer object at 0x7a9a39daf130> (of type <class 'tensorflow_hub.keras_layer.KerasLayer'>) #668

Open
moatednorth opened this issue Aug 14, 2024 Discussed in #662 · 1 comment

Comments

@moatednorth
Copy link

Discussed in #662

Originally posted by moatednorth July 31, 2024
Sequential api can't handle hub.KerasLayer

`

Create a Keras Layer using the USE pretrained layer from Kaggle

sentence_encoder_layer = hub.KerasLayer("https://www.kaggle.com/models/google/universal-sentence-encoder/TensorFlow2/universal-sentence-encoder/2",
input_shape=[],
dtype=tf.string,
trainable=False,
name="USE")

Create model using the Sequential API

model_6 = tf.keras.Sequential([
sentence_encoder_layer,
layers.Dense(64, activation="relu"),
layers.Dense(1, activation="sigmoid", name="ouput_layer")
], name="model_6_USE")
`

@AnilKamath27
Copy link

Hi, moatednorth. This is an issue that is occurring in the latest version of tensorflow 2.17. This won't be an issue if you try with tf 2.15.0. Below is a screenshot of my notebook where I was able to use hub.KerasLayers as part of Sequential API.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants