You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Keras 3, calling a model specified via the functional API with one StringLookupLayer and one IntegerLookupLayer each connected to their own Input layers raises a "Cast int64 to string" error, but in Keras 2, the tensors flow.
Here is a minimal example to reproduce the error. Try running it first in the latest version of Keras and TensorFlow, see the error, then downgrade and observe that it works:
import keras
import numpy as np
import tensorflow as tf
# Create a string lookup layer
data = [["a", "c", "d"], ["d", "z", "b"]]
letters_lookup = keras.layers.StringLookup(name='letters_lookup', output_mode='one_hot')
letters_lookup.adapt(data)
# Create an integer lookup layer
data = np.array([[12, 1138, 42], [42, 1000, 36]])
integers_lookup = keras.layers.IntegerLookup(name='integers_lookup', output_mode='one_hot')
integers_lookup.adapt(data)
# Create input layers
integers_input = keras.Input(shape=(), name='integers_in', dtype="int64")
letters_input = keras.Input(shape=(), name='letters_in', dtype="string")
# Make a model using the functional API
letters_out = letters_lookup(letters_input)
integers_out = integers_lookup(integers_input)
model = keras.Model([letters_input,integers_input],[letters_out,integers_out])
# Test the model
test_tensor_dict = {
'letters_in': tf.constant(['d']),
'integers_in': tf.constant([42], dtype=tf.int64)
}
model(test_tensor_dict)
2024-08-26 17:50:26.960422: W tensorflow/core/framework/op_kernel.cc:1817] OP_REQUIRES failed at cast_op.cc:122 : UNIMPLEMENTED: Cast int64 to string is not supported
2024-08-26 17:50:26.960536: I tensorflow/core/framework/local_rendezvous.cc:404] Local rendezvous is aborting with status: UNIMPLEMENTED: Cast int64 to string is not supported
---------------------------------------------------------------------------
UnimplementedError Traceback (most recent call last)
Cell In[14], line 1
----> 1 model(test_tensor_dict)
File /opt/conda/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.__traceback__)
120 # To get the full stack trace, call:
121 # `keras.config.disable_traceback_filtering()`
--> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb
File /opt/conda/lib/python3.10/site-packages/tensorflow/python/framework/ops.py:5983, in raise_from_not_ok_status(e, name)
5981 def raise_from_not_ok_status(e, name) -> NoReturn:
5982 e.message += (" name: " + str(name if name is not None else ""))
-> 5983 raise core._status_to_exception(e) from None
UnimplementedError: Exception encountered when calling Functional.call().
{{function_node __wrapped__Cast_device_/job:localhost/replica:0/task:0/device:CPU:0}} Cast int64 to string is not supported [Op:Cast] name:
Arguments received by Functional.call():
• inputs={'letters_in': 'tf.Tensor(shape=(1,), dtype=string)', 'integers_in': 'tf.Tensor(shape=(1,), dtype=int64)'}
• training=None
• mask={'letters_in': 'None', 'integers_in': 'None'}
Tested in Colab and also on a Mac laptop running JupyterLab in a Google Cloud Deep Learning container.
The text was updated successfully, but these errors were encountered:
In Keras 3, calling a model specified via the functional API with one StringLookupLayer and one IntegerLookupLayer each connected to their own Input layers raises a "Cast int64 to string" error, but in Keras 2, the tensors flow.
Here is a minimal example to reproduce the error. Try running it first in the latest version of Keras and TensorFlow, see the error, then downgrade and observe that it works:
Tested in Colab and also on a Mac laptop running JupyterLab in a Google Cloud Deep Learning container.
The text was updated successfully, but these errors were encountered: