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 occurred when building cascaded model with loaded sub-model #19374

Closed
keisen opened this issue Mar 25, 2024 · 7 comments
Closed

ValueError occurred when building cascaded model with loaded sub-model #19374

keisen opened this issue Mar 25, 2024 · 7 comments
Assignees
Labels

Comments

@keisen
Copy link

keisen commented Mar 25, 2024

Hi, keras team!

I'm facing a error when build cascaded model with sub-model loaded from a file.
It's okay if the sub-model is NOT loaded from file, just created on memory.
This behavior appeared form keras 3+. Until keras 2.x, it didn't exist definitely.

I wrote the code to reproduce error, please refer to notebook below:
https://gist.github.com/keisen/4703d6508a950ff6a35d84da73e335b8

Please improve this issue or let me know how to work around with keras 3.x....

Thanks!

@SuryanarayanaY
Copy link
Collaborator

Hi @keisen ,

I have replicated the issue with Keras3(TF2.16v) and attached gist here. With Keras2 it works fine and attached gist here.

This seems a regressions issue for me.Will check and update. Thanks!

@SuryanarayanaY
Copy link
Collaborator

Hi @keisen ,

I did some debugging and find out the reason for this error.Basically the output of child model is Keras Tensor whereas loaded_child_model it is Tensor but wrapped in the list. I have verified both model configs and they are same.

It's quite interesting why the loaded_child_model is wrapping the Tensor in a list.

Sharing the gist with the debug info so far.

@keisen
Copy link
Author

keisen commented Mar 28, 2024

@SuryanarayanaY

It's quite interesting why the loaded_child_model is wrapping the Tensor in a list.

Yep, That's why I asked you to resolve this issue.
Before posting, I've also tried the test you did then got the same as you got, and in addition, you may also already try, I ran the code below:

X = tf.random.normal((1, 8, 8, 3))

print('child_model       :', child_model(X))
print('loaded_child_model:', loaded_child_model(X))

Then I got the output below:

child_model       : tf.Tensor([[0.3972141 0.6027859]], shape=(1, 2), dtype=float32)
loaded_child_model: tf.Tensor([[0.3972141 0.6027859]], shape=(1, 2), dtype=float32)

As you can see above, The result of loaded_child_model is not a list object.

Before posting, I was going to debug and hack to work around this issue,
but, after seeing this, I gave up completely then decided to ask you and your team.
This problem is definitely over my head lol.

I'm looking forward to hearing good news from you!
Best regards,
keisen

@SuryanarayanaY
Copy link
Collaborator

Hi @keisen ,

I also have tested with numpy array and predictions are same for both . It seems this is happening with Keras Tensor(placeholder) only. You can notice the same on gist. I am also looking into it for the root cause.Its taking time apparently.

@keisen
Copy link
Author

keisen commented Mar 28, 2024

Hi @SuryanarayanaY

You can notice the same on gist.

Yep, I know.

I am also looking into it for the root cause.Its taking time apparently.

It's okay, no worries. Rather, I really appreciate you to take on this tough work.
Thank you so much!

Sincerely,

@SuryanarayanaY SuryanarayanaY added the keras-team-review-pending Pending review by a Keras team member. label Apr 10, 2024
@sachinprasadhs sachinprasadhs removed the keras-team-review-pending Pending review by a Keras team member. label Apr 11, 2024
@fchollet
Copy link
Member

It appears I have fixed this issue as the same issue was previously reported in a different ticket. Please check that Keras at HEAD works for you.

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

No branches or pull requests

5 participants