-
Notifications
You must be signed in to change notification settings - Fork 31
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
The model does not save and load correctly when containing tf.keras.layers.experimental.preprocessing.StringLookup
layer
#29
Comments
Hi @oawxkw, please try the new |
Hello @nkovela1, thanks for your reply. I think this issue may relate to the format of the models, which is causing the
According to the documentation, the I'm using the following code to test the different import pickle
import tensorflow as tf
print(tf.version.GIT_VERSION, tf.version.VERSION, flush=True)
model_input = tf.keras.Input(shape=(1,), dtype=tf.int64)
lookup = tf.keras.layers.experimental.preprocessing.StringLookup(vocabulary=['aaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbb'])(model_input)
output = tf.keras.layers.Dense(10)(lookup)
full_model = tf.keras.Model(model_input, output)
def test_save(filepath, save_format=None):
try:
full_model.save(filepath, save_format=save_format)
full_model_loaded = tf.keras.models.load_model(filepath)
print(filepath, save_format, full_model_loaded.layers[1].get_config())
model_bytes = pickle.dumps(full_model_loaded)
model_recovered = pickle.loads(model_bytes)
except Exception as e:
print("Failed! Error:", e, flush=True)
else:
print("Success!", flush=True)
test_save("/tmp/temp_model", save_format=None)
test_save("/tmp/temp_model.keras", save_format=None)
test_save("/tmp/temp_model.tf", save_format=None)
test_save("/tmp/temp_model", save_format='keras')
test_save("/tmp/temp_model.keras", save_format='keras')
test_save("/tmp/temp_model.tf", save_format='keras')
test_save("/tmp/temp_model", save_format='tf')
test_save("/tmp/temp_model.keras", save_format='tf')
test_save("/tmp/temp_model.tf", save_format='tf') |
System information.
Describe the problem.
The model does not save and load correctly when containing
tf.keras.layers.experimental.preprocessing.StringLookup
layer.It seems that the
vocabulary
is not saved or loaded correctly, which is empty when loading the model.I manually checked the saved model files and found that:
The
vocabulary
is saved as a constant value insaved_model.pb
and all layers arguments are dumped inkeras_metadata.pb
, but it's not saved invariables/variables.data-00000-of-00001
andvariables/variables.index
(cannot find the stingaaaa
orbbbb
in these two files).If the saved model files are correct, there should be something wrong when loading the model.
I've reported this issue in tensorflow/tensorflow#61779, but the contributor suggested reporting it here.
This behavior may also relate to tensorflow/tensorflow#61369, but in a different API endpoint.
Describe the current behavior.
Loading the saved model throws an error, which is caused by the empty
vocabulary
argument of theStringLookup
layer.Describe the expected behavior.
Saving and loading the model should work correctly for the
StringLookup
layer.Standalone code to reproduce the issue.
Source code / logs.
The text was updated successfully, but these errors were encountered: