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

There were problems saving and loading the model #12

Closed
ChineseDictionary opened this issue Sep 7, 2024 · 6 comments
Closed

There were problems saving and loading the model #12

ChineseDictionary opened this issue Sep 7, 2024 · 6 comments

Comments

@ChineseDictionary
Copy link

I first saved the model using model.save, with no errors. But when I used
from keras.models import load_model model = load_model('my_model.keras')
to load the model, I get an error of
ValueError: A total of 4 objects could not be loaded. Example error message for object <KANLinear name=kan_linear, built=True>: The shape of the target variable and the shape of the target value in variable.assign(value) must match. variable.shape=(1, 10), Received: value.shape=(1, 10). Target variable: <KerasVariable shape=(1, 3, 10), dtype=float32, path=tkan/tkan_cell/kan_linear/grid> List of objects that could not be loaded: [<KANLinear name=kan_linear, built=True>, <LayerNormalization name=layer_normalization, built=False>, <KANLinear name=kan_linear_1, built=True>, <LayerNormalization name=layer_normalization_1, built=False>]
There was no such error when I saved and loaded the LSTM model. How can I solve this?

@remigenet
Copy link
Owner

Hi, thanks a lot for pointing out, there were indeed a serialization issue in keras_efficient_kan package that occurs when using layer normalization, which were the case in the TKAN, but not with other models that used it !
I published a fixed new version of it and did as well for the TKAN package (to include the modification), so all you have to do is update your package version of TKAN to 0.4.2 (pip install tkan --upgrade OR pip install tkan==0.4.2) and it should be fixed !

@ChineseDictionary
Copy link
Author

Thank you!

@ChineseDictionary
Copy link
Author

The problem has not been completely solved. When I try to load the model in another file in the same environment, the problem still occurs. How do we fix this? Thank you.

@ChineseDictionary
Copy link
Author

The save and load steps are the same as above. I have updated TKAN and keras_efficient_kan to the latest version. The error message is
ValueError: A total of 2 objects could not be loaded. Example error message for object :
The shape of the target variable and the shape of the target value in variable.assign(value) must match. variable.shape=(1, 10), Received: value.shape=(1, 10). Target variable: <KerasVariable shape=(1, 65, 10), dtype=float32, path=tkan/tkan_cell/kan_linear/grid>
List of objects that could not be loaded:
[, ]

@ChineseDictionary
Copy link
Author

ChineseDictionary commented Sep 20, 2024

ValueError: A total of 2 objects could not be loaded. Example error message for object :The shape of the target variable and the shape of the target value in variable.assign(value) must match. variable.shape=(1, 10), Received: value.shape=(1, 10). Target variable: <KerasVariable shape=(1, 65, 10), dtype=float32, path=tkan/tkan_cell/kan_linear/grid>
List of objects that could not be loaded:[<KANLinear name=kan_linear, built=True>, <KANLinear name=kan_linear_1, built=True>]

@ducanbk13
Copy link

Hi, I have the same problem. It shows something like: The shape of the target variable and the shape of the target value in variable.assign(value)` must match. variable.shape=(1, 10), Received: value.shape=(1, 10). Target variable: <KerasVariable shape=(1, 2, 10), dtype=float32, path=tkan_6/tkan_cell_6/kan_linear_6/grid>

List of objects that could not be loaded:
[, , , ]`
I tested in many ways from loading .h5 file to using default keras. All of them don't work at all.
Has anyone fixed that?

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

No branches or pull requests

3 participants