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

Issue with Loading Sequential Models #20074

Closed
xchen99sdr opened this issue Jul 31, 2024 · 3 comments · Fixed by #20076
Closed

Issue with Loading Sequential Models #20074

xchen99sdr opened this issue Jul 31, 2024 · 3 comments · Fixed by #20076
Assignees
Labels

Comments

@xchen99sdr
Copy link

tensorflow/tensorflow#70757

Reposting per tensorflow developer's recommendation.

I am encountering the same issue with pip version 2.17

Thank you

@RaulCastillo547
Copy link

I'm the original poster of the tensorflow issue. Thank you xchen99sdr for reposting it.

@james77777778
Copy link
Contributor

A minimal reproducible script:

from keras import layers
from keras import models
from keras import ops
from keras import saving

CONV_WIDTH = 3
model = models.Sequential([layers.Lambda(lambda x: x[:, -CONV_WIDTH:, :])])
x = ops.ones((1, 10, 4))
y = model(x)
model.save("model.keras")
revived_model = saving.load_model("model.keras", safe_mode=False)  # <- failed

A workaround is to directly assign the value instead of using variables in layers.Lambda. I don't know why it caused the issue.

from keras import layers
from keras import models
from keras import ops
from keras import saving

model = models.Sequential([layers.Lambda(lambda x: x[:, -3:, :])])  # Not using `CONV_WIDTH`
x = ops.ones((1, 10, 4))
y = model(x)
model.save("model.keras")
revived_model = saving.load_model("model.keras", safe_mode=False)

I have submitted a PR #20076 to ultimately fix it. You can also wait for it.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

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

Successfully merging a pull request may close this issue.

4 participants