-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
Models with InputLayer are not serialized to HDF5 correctly #11683
Comments
@cyounkins Thanks for posting the workaround. Would you like to keep this issue open? |
@ymodak yes absolutely. It is a bug to not be able to deserialize previously serialized networks. |
@cyounkins -- Thanks, for pushing this issue. I have been struggling with this for too long. I simply rolled back to keras 2.1.6, but would much prefer a fix...and that means fix it, not close it because one of our smarter contributors found and posted a way around the bug. |
@gabrieldemarmiesse Can you please take a look? Thanks! |
What is the workaround if my model is saved as separate .json with architecture and .hdf5 with weights? |
My own workaround is to build the model directly, rather than using |
@hosford42 Thanks, I can construct the model in code, but the problem seems to be with loading the weight file into it...
|
Yes, that issue went away when I stopped using Sequential to construct the
code, and created the Input directly instead.
…On Fri, Dec 21, 2018, 11:49 AM mikephn ***@***.***> wrote:
@hosford42 <https://github.com/hosford42> Thanks, I can construct the
model in code, but the problem seems to be with loading the weight file
into it...
ValueError: You are trying to load a weight file containing 1 layers into
a model with 28 layers.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11683 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEWlsxjVr9IACng1kpcS07Z02j4guuJoks5u7R82gaJpZM4Yp6NZ>
.
|
I’m using the functional API, creating the layers and calling Model(input, output) at the end.
… On 21 Dec 2018, at 21:57, Aaron Hosford ***@***.***> wrote:
Yes, that issue went away when I stopped using Sequential to construct the
code, and created the Input directly instead.
On Fri, Dec 21, 2018, 11:49 AM mikephn ***@***.***> wrote:
> @hosford42 <https://github.com/hosford42> Thanks, I can construct the
> model in code, but the problem seems to be with loading the weight file
> into it...
>
> ValueError: You are trying to load a weight file containing 1 layers into
> a model with 28 layers.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#11683 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AEWlsxjVr9IACng1kpcS07Z02j4guuJoks5u7R82gaJpZM4Yp6NZ>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#11683 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AEh_HGpVtj2a-JLW91AB9fdc9NElsRy5ks5u7Us-gaJpZM4Yp6NZ>.
|
Newer versions of Keras suffer from an inability to serialize a Sequential model with an InputLayer properly (see keras-team/keras#11683), which makes Keras raise a ValueError when loading the model (see keras-team/keras#10417). As a workaround, remove the (auxiliary) InputLayer intil the issue has been fixed.
I am seeing this with class API for models saved within the same session (not cross version). Is it possible this is related? |
Has anyone tried the fix (not a workaround) I proposed in #10417 ? It works for me and I haven't noticed any side effects. |
Another workaround is to replace: InputLayer((64,64)) with this instead: Lambda(tf.identity, input_shape=(64,64)) |
Opening new issue due to #10417 being closed without fix. Below is a demonstration of the issue and a hack to fix existing saved models.
keras.__version__= 2.2.4
The
test1
has the additional structure:"batch_input_shape": [null, 64, 64], "dtype": "float32",
You can fix this using:
The text was updated successfully, but these errors were encountered: