Created
November 10, 2019 06:55
-
-
Save Manikanta-Munnangi/9d61cbfb760381c9b3f035cb3bd6e362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Two ways of doing it. | |
""" | |
1.Using pickle a python library. | |
2.With keras. | |
""" | |
""" 1.Serialzing with pickle.""" | |
with open("path/name.pkl","wb") as file: | |
pickle.dump(model,file) | |
""" 2.Saving model with keras. """ | |
# 1.Entire model saving. | |
from keras.models import load_model | |
model.save('model_name.h5') # create a h5 file | |
# 2.Saving model weights with architecture. | |
# it's is recommended to save architecture first as a json (or) yaml file then save weights. Otherwise you get an | |
# error "read only mode" while loading. | |
json_arch=model.to_json() # after getting architecture write as json file to disk for loading with weights in future. | |
for open("model_arch.json","wb") as file: | |
file.write(json_arch) | |
model.save_weights("model_weights.h5") | |
# Note: It is not recommended to use pickle for saving keras model. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment