Closed nectario closed 4 years ago
same issue here
Hi Nektarios,
as the error message indicates, the expected inputs are strings, and not floats.
First, you'd need to change your input to something like this: input = Input(shape=(), name="Input", dtype=tf.string)
To start, you can follow the example in the colab of this hub module: https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1 https://colab.research.google.com/github/tensorflow/hub/blob/master/examples/colab/tf2_text_classification.ipynb
and adapt it to Functional API as needed.
Example: hub_handle = "https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1" hub_layer = hub.KerasLayer(hub_handle, output_shape=[20], input_shape=[], dtype=tf.string, trainable=True) input = Input(shape=(), name="Input", dtype=tf.string) net = hub_layer(input) net = tf.keras.layers.Dense(16, activation='relu')(net) output = tf.keras.layers.Dense(1, activation='sigmoid')(net) m = Model(input, output) m.summary()
Once you get a very basic example working, you can experiment further with your model. In case other issues come up, I'd recommend to ask at StackOverflow for general tensorflow related questions.
Hi,
I tried out what you say, but I got:
WARNING:tensorflow:AutoGraph could not transform <tensorflow.python.saved_model.function_deserialization.RestoredFunction object at 0x1313d4f60> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux,
export AUTOGRAPH_VERBOSITY=10) and attach the full output. Cause: Python inputs incompatible with input_signature: inputs: ( Tensor("Input_1:0", shape=(None, None), dtype=string)) input_signature: ( TensorSpec(shape=(None,), dtype=tf.string, name=None))
Any Idea whats going on? The code is here:
https://github.com/StoyanVenDimitrov/deeplearning_NLU/blob/save_mode/application.py#L154
Try looking at the input shapes. The error states that it expected shape=(None,)
but you passed shape=(None, None)
.
Moreover, you could look into the types as well. Not sure if string
instead of tf.string
will make a difference.
as pointed out by @maximneumann , the input shape has to be shape=().
This resolved the issue for me.
TensorFlow Version: 2.1 Python Version: 3.76 OS: Windows 10 Issue: Keras Hub Layer Does Not Work with Functional API. Throws Exception. Unable to load IMDB dataset. See below code and exception:
Exception: