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

Loading models without pre-defining them #84

Closed
mirestrepo opened this issue Apr 11, 2018 · 8 comments
Closed

Loading models without pre-defining them #84

mirestrepo opened this issue Apr 11, 2018 · 8 comments

Comments

@mirestrepo
Copy link
Contributor

Loading models requires predefining the values and functions that construct them. Ideally the loader should do that. Serialization may not be possible in some cases but we should look into this

@DilumAluthge
Copy link
Member

Yeah I would really like this to work. Actually it's how I originally envisioned it working. I think the only thing we have to do is figure out how to serialize functions to/from file, since we need that for Knet (predict function and loss function).

@DilumAluthge
Copy link
Member

The other idea I once had was this - instead of having the user define the predict and loss functions as functions, they actually define strings that contain the source code of the function. Then we can serialize those strings really easily. The tricky part is parsing and eval-ing those strings without getting weird errors.

@DilumAluthge
Copy link
Member

We would need eval() to evaluate the predict and loss functions in the context of, e.g., the fit!() function... but I think eval() always evaluates in the top-level module. So that's where I got stuck, and I didn't pursue the idea further.

@mirestrepo
Copy link
Contributor Author

As an intermediate step could just reload all data-structures and require setting the predict and loss functions.

Or have the predict and loss be loaded from a Julia file and only the path be save....

Buts let's keep exploring, none seem like and elegant solution

@DilumAluthge
Copy link
Member

@mirestrepo Take a look at the discussion here - denizyuret/Knet.jl#144

@DilumAluthge
Copy link
Member

Also take a look here - https://github.com/denizyuret/Knet.jl/blob/master/examples/dl-tutorial/mlp.ipynb (see input cell 30). They use JLD to save the models to file, but they only save the weights (as well as the current training loss, testing loss, etc). They don't serialize the predict function ( multilinear(w,x) in this example).

@DilumAluthge
Copy link
Member

One last thought: I've been playing around with BSON.jl (https://github.com/MikeInnes/BSON.jl), and it seems that BSON.jl supports saving functions to file. So this may be an easy way to solve this issue.

@DilumAluthge
Copy link
Member

Fixed in develop. You can load models without predefining them. The one exception is Knet models - you have to define predict() and loss() before loading the model.

@DilumAluthge DilumAluthge added this to the 0.19 milestone Jul 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants