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

fix databricks dbfs file path #4674

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions python/orca/src/bigdl/orca/learn/tf/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ def to_dataset(data, batch_size, batch_per_thread, validation_data,
return dataset


def save_model_dir(model_dir):
if model_dir.startswith("dbfs:/"):
model_dir = "/dbfs/" + model_dir[len("dbfs:/"):]
return model_dir


class TensorFlowEstimator(Estimator):
def __init__(self, *, inputs, outputs, labels, loss,
optimizer, clip_norm, clip_value,
Expand Down Expand Up @@ -775,6 +781,8 @@ def shutdown(self):

class KerasEstimator(Estimator):
def __init__(self, keras_model, metrics, model_dir, optimizer):
if model_dir and model_dir.startswith("dbfs:/"):
model_dir = save_model_dir(model_dir)
self.model = KerasModel(keras_model, model_dir)
self.load_checkpoint = False
self.metrics = metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from bigdl.orca.learn.tf.estimator import Estimator
from bigdl.dllib.nncontext import *
from bigdl.orca.learn.utils import convert_predict_rdd_to_dataframe
from bigdl.orca.learn.tf.estimator import save_model_dir


class TestEstimatorForKeras(TestCase):
Expand Down Expand Up @@ -681,6 +682,11 @@ def test_estimator_keras_get_model(self):
validation_data=df)
assert est.get_model() is model

def test_model_path_dbfs_from_keras(self):
model_dir = "dbfs:/FileStore/shared_uploads/models"
processed_model_dir = save_model_dir(model_dir)
assert processed_model_dir == "/dbfs/FileStore/shared_uploads/models"


if __name__ == "__main__":
import pytest
Expand Down