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

marshal: Save TF models under a versioned folder #228

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions backend/kale/marshal/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ def resource_tf_load(uri, **kwargs):
try:
from tensorflow.keras.models import load_model
log.info(f"Loading tf.Keras model: {uri}")
obj_tfkeras = load_model(uri, compile=False)
try:
obj_tfkeras = load_model(uri)
except OSError:
# XXX: try to load a model that was saved within a versioned
# folder (for tensorflow serve)
obj_tfkeras = load_model(uri + "/1")
return obj_tfkeras
except ImportError:
return fallback_load(uri, **kwargs)
Expand All @@ -151,7 +156,9 @@ def resource_tf_load(uri, **kwargs):
def resource_tf_save(obj, path, **kwargs):
"""Save a tf.Keras model."""
try:
log.info("Saving Keras model: %s", _get_obj_name(path))
obj.save(path + ".tfkeras")
log.info("Saving TF Keras model: %s", _get_obj_name(path))
# XXX: Adding `/1` since tensorflow serve expects the model's models
# to be saved under a versioned folder
obj.save(path + ".tfkeras/1")
except ImportError:
fallback_save(obj, path, **kwargs)