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

saving tensorflow models #11

Open
ctorney opened this issue Dec 4, 2019 · 4 comments
Open

saving tensorflow models #11

ctorney opened this issue Dec 4, 2019 · 4 comments

Comments

@ctorney
Copy link

ctorney commented Dec 4, 2019

Any thoughts on the best approach to integrating a tensorflow model? specifically I mean how to save model weights and architectures to the database. Right now I've saved a filepath in the stateDict then I load and save weights to/from that file. It doesn't seem possible to save the model directly to the db as done for pytorch

@bkellenb
Copy link
Collaborator

bkellenb commented Dec 7, 2019

Hi,

Good question; I remember saving and loading model states to be a bit of a hassle in TensorFlow.
I found the functions model.get_weights() and model.set_weights(), although they are primarily provided for the Keras wrapper: https://www.tensorflow.org/guide/keras/save_and_serialize#weights-only_saving
For TensorFlow itself the functions tf.all_variables() or tf.trainable_variables() might work instead: google/prettytensor#6 (comment)

@ctorney
Copy link
Author

ctorney commented Dec 17, 2019

Thanks for the info - I guess I was thinking more of how to store in the AIde db. The keras wrapper saves weights and architecture in hdf5 format but I couldn't find a way to save this file format into the database. Storing the filepath in the database and the hdf5 file to disk works but seems a bit clunky

@bkellenb
Copy link
Collaborator

The way I do this for PyTorch models is to just return a Python dict with model parameters inside. What you could do is to instead return a byte array of the HDF5 file at the end of the train function (perhaps like described here).
I know this is just as clunky, but at least it would keep the model parameters completely in the database and not just the reference.

I have plans to provide more flexibility for file storage in the future anyway. An option is to explicitly expose the project's data path to the model, so that it can indeed store the model file under a logical path and just return the directory to the database.

@ctorney
Copy link
Author

ctorney commented Dec 19, 2019

Thanks - I'll have a look at the byte array approach - I agree keeping all parameters in the database would be a much nicer solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants