-
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
model_from_json fails with "TypeError: arg 5 (closure) must be tuple" #2814
Comments
Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short). |
Apologies @fchollet, I forgot to add the I'm using the stochastic_depth_keras model - you can quickly create a Stochastic Depth |
(I just tried writing the same StochasticDepth model using the yaml method, but this fails on the write step - traceback linked here) |
Any success? I am trying to use
|
I have not had any success I'm afraid. |
I have fixed it in PR #3639. Although it works fine, one needs to be aware of how to properly use closures (if you want to use them). Only the code of lambda functions was serialized, missing was their defaults and closure (essential for successful deserialization). To reconstruct a custom function completely one would need: fn = types.FunctionType(func.func_code,
func.func_globals.copy(),
name=func.func_name,
argdefs=func.func_defaults,
closure=func.func_closure) Also these The solution is based a solution that does not introduce new dependencies on StackOverflow. One may test it with something like: def get_closure(x):
def the_closure(a, b=1):
return a * x + b
return the_closure
f = get_closure(10)
code, defaults, closure = func_dump(f)
dump = pickle.dumps((code, defaults, closure))
code, defaults, closure = pickle.loads(dump)
f = func_load(code, defaults=defaults, closure=closure, globals=globals())
print f(2) For the lambda merge layer I am using something like the following. The value of i = ...
def mul_sum((x1, x2), i=i):
return x1 + x2 * i
def mul_sum_shape((s, _)):
return s
x = merge([x1, x2], mode=mul_sum, output_shape=mul_sum_shape) |
Having saved a successfully trained model with:
When trying to reload it, I'm getting:
I'm using the functional API if it helps. Thanks
pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
The text was updated successfully, but these errors were encountered: