-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Loading model Conv2DTranspose from h5 file results in error complaining about group:1 parameter #19441
Comments
Can you try to create a model in Keras 3 instead of keras_core and try to load it in the same version and let us know the outcome of it. Thanks |
I'm a bit confused about keras versions. I thought Keras 3 and keras-core were basically the same thing? The model I'm having issues with was created by tf-keras, and I'm trying to load into the latest version of keras-core (installed via pip as keras-core). Do you actually want me to try to install keras 3 (if so how), or do you wnat me to try to generate a model in keras-core (this is on the todo list for next week anyway). |
keras-core was a pre-release for Keras 3, now Keras 3 is available and all the latest updates will be made available in the Keras 3 release. |
I'm only getting keras 2.15.0 when I do that? I'm on windows with Python 3.8. Am I doing something wrong, or has Keras 3 not reached windows yet? |
Also, 2.15.0 doesn't actually allow you to import keras as it fails with a tensorflow related error. The maximum tensorflow version that seems to be available is 2.13.1, which works with keras 2.13.1. |
I managed to install keras3 by starting with a fresh installation of python 3.11 and just installing pytorch and keras (plus packaging and pandas which appear to be dependencies of keras but aren't configured as such). The same problem(s) exist with this version as with keras_core loading historic models from tf-keras, and the same hacky fix(es) work to get the model loaded. I'm going to port our model generation code over now, and see if a h5 generated by keras3 will have the same issue (not that that solves anything for legacy models). I'll report back. |
I can now confirm that if the model is created in Keras 3, and saved as .h5 the problem does not occur. It only occurs with historic models created in tf.keras. However, we (and customers) have a large collections of such models. |
Could you please provide some sample reproducible code to replicate the reported behavior. Thanks |
The minimal code below will throw that error with the model I linked above. However, first you need to fix #19151. I proposed a hack for that there, but I see there are some posts, so I'll go respond to that now.
|
Unfortunately this code snippet is not reproducible since it refers to |
@fchollet I attached the model above. For convenience it is here: https://drive.google.com/file/d/1Jn9C4vTRVWgHCqAXnMfO_i-B3pK4c14I/view?usp=sharing |
Adding this solves the problem (click me.)# hack to change model config from keras 2->3 compliant
import h5py
f = h5py.File("/content/old_keras_model.h5", mode="r+")
model_config_string = f.attrs.get("model_config")
if model_config_string.find('"groups": 1,') != -1:
model_config_string = model_config_string.replace('"groups": 1,', '')
f.attrs.modify('model_config', model_config_string)
f.flush()
model_config_string = f.attrs.get("model_config")
assert model_config_string.find('"groups": 1,') == -1
f.close() As it was indicated in #19151, in this comment. Is the it fixed for you @dmagee ? I include a GIST that downloads and instantiates the model and problem (removing the snippet I provided above from it). |
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you. |
This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further. |
try using tensorflow version 2.12.1, worked for me. |
Loading a .h5 model created in TensorFlow.keras containing Conv2DTranspose layer in keras-core results in an error:
Exception encountered: Unrecognized keyword arguments passed to Conv2DTranspose: {'groups': 1}
A hacky fix is to edit keras_core/src/ops/operation.py in the method from_config() so:
I've yet to confirm the resultant network behaves exactly the same as the original, but it seems to work. It's obviously not the ideal solution. I'm not quite sure what that parameter does, as it's not something I used when creating the network. I imagine most legacy networks using Conv2DTranspose will have the same issue.
Model is here if helpful:
https://drive.google.com/file/d/1Jn9C4vTRVWgHCqAXnMfO_i-B3pK4c14I/view?usp=sharing
Note:it also has the issue raised here about Lambda layers: #19151
(I proposed a hack there, and it looks like a better solution is being worked on)
Derek
The text was updated successfully, but these errors were encountered: