-
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
Bug with saving the model #6442
Comments
It's likely that your issue is with the type of In general, saving models that have I recommend that you write a custom layer with a |
In order to make it serializable, make sure that the numpy array is defined within your function. Any information required to create the numpy array can be passed using the def func(x, std, avg):
shape = # scale factor shape
scale_factor = np.random.normal(shape) * std + avg
return x * scale_factor
out = Lambda(func, output_shape=(n_out,), arguments={'std': 0.5, 'avg': 0.4})(h) |
Thanks a lot for the answer. Your example works like a charm, but unfortunately, it is not what I intended to do. But, it did help me figure out what the issue was! What I tried to do is the following: def func(x, np_scale_array):
# print np_scale_array.shape gives (17,)
return x * np_scale_array
np_scale_array = np.array(...
out = Lambda(func, output_shape=(n_out,), arguments={'np_scale_array': np_scale_array})(h) This still gives me the error: But, when I converted the arguments to a Python list and converted them back in the function, it worked like a charm: def func(x, scale_array):
# print np_scale_array.shape gives (17,)
np_scale_array = np.array(scale_array)
return x * np_scale_array
np_scale_array = np.array(...
out = Lambda(func, output_shape=(n_out,), arguments={'np_scale_array': np_scale_array.tolist()})(h) This works like a charm! |
I want to rescale the outputs of my model, so I do the following.
I get:
If I, on the other hand do
I get:
I want to emphasize that the model compiles, works, I can see that I am getting proper outputs, but the save fails.
The text was updated successfully, but these errors were encountered: