Last active
September 28, 2020 07:22
-
-
Save CleanPegasus/420a684faed737eb4395778a4de15551 to your computer and use it in GitHub Desktop.
Saving model for serving
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
import tempfile | |
model_dir = tempfile.gettempdir() # gets the path of the temporary folder | |
version = 1 # version of the specific model | |
export_path = os.path.join(model_dir, str(version)) | |
if os.path.isdir(export_path): | |
print("Found an existing version of the model. Deleting the previous version\n") | |
!rm -r {export_path} # terminal command to remove a directory | |
# Saving the model | |
tf.keras.models.save_model( | |
model, # the trained model | |
export_path, # export path for the model | |
overwrite = True, # overwrite if existing version found | |
include_optimizer = True, # include the model optimizer | |
save_format = None, | |
signature = None, | |
options = None | |
) | |
# If tf.keras.models.save_model() doesn't work, use the model.save function | |
model.save(export_path, save_format="tf") | |
print("Model Saved\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment