om.models

omegaml.models = OmegaStore(bucket=omegaml, prefix=models/)

the omegaml.store.base.OmegaStore store for models

Methods:

Mixins:

Backends:

Backends for tensorflow (loaded only if installed):

Backends for keras (loaded only if installed):

  • omegaml.backends.keras.KerasBackend

Backends for mlflow (loaded only if installed)

  • omegaml.backends.mlflow.models.MLFlowModelBackend

  • omegaml.backends.mlflow.registrymodels.MLFlowRegistryBackend

Backends for R (loaded if installed)

Backends

class omegaml.backends.scikitlearn.ScikitLearnBackend(model_store=None, data_store=None, tracking=None, **kwargs)
KIND = 'sklearn.joblib'
class omegaml.backends.experiment.ExperimentBackend(model_store=None, data_store=None, tracking=None, **kwargs)

ExperimentBackend provides storage of tracker configurations

Usage:

To log metrics and other data:

with om.runtime.experiment('myexp') as exp:
    om.runtime.model('mymodel').fit(X, Y)
    om.runtime.model('mymodel').score(X, Y) # automatically log score result
    exp.log_metric('mymetric', value)
    exp.log_param('myparam', value)
    exp.log_artifact(X, 'X')
    exp.log_artifact(Y, 'Y')
    exp.log_artifact(om.models.metadata('mymodel'), 'mymodel')

To log data and automatically profile system data:

with om.runtime.experiment('myexp', provider='profiling') as exp:
    om.runtime.model('mymodel').fit(X, Y)
    om.runtime.model('mymodel').score(X, Y) # automatically log score result
    exp.log_metric('mymetric', value)
    exp.log_param('myparam', value)
    exp.log_artifact(X, 'X')
    exp.log_artifact(Y, 'Y')
    exp.log_artifact(om.models.metadata('mymodel'), 'mymodel')

# profiling data contains metrics for cpu, memory and disk use
data = exp.data(event='profile')

To get back experiment data without running an experiment:

# recommended way
exp = om.runtime.experiment('myexp').use()
exp_df = exp.data()

# experiments exist in the models store
exp = om.models.get('experiments/myexp')
exp_df = exp.data()

See also

KIND = 'experiment.tracker'
get(name, raw=False, data_store=None, **kwargs)

retrieve a model

Parameters:
  • name – the name of the object

  • version – the version of the object (not supported)

put(obj, name, **kwargs)

store a model

Parameters:
  • obj – the model object to be stored

  • name – the name of the object

  • attributes – attributes for meta data

classmethod supports(obj, name, **kwargs)

test if this backend supports this obj

class omegaml.backends.tensorflow.TensorflowKerasBackend(model_store=None, data_store=None, tracking=None, **kwargs)
KIND = 'tfkeras.h5'
fit(modelname, Xname, Yname=None, pure_python=True, tpu_specs=None, **kwargs)

Fit a model

Parameters:
  • modelname – the name of the model

  • Xname – the name of the X dataset

  • Yname – the name of the Y dataset

  • pure_python – deprecated

  • kwargs – any additional kwargs are passed on to model.fit()

Returns:

the meta data object of the model

classmethod supports(obj, name, **kwargs)

test if this backend supports this obj

class omegaml.backends.tensorflow.TensorflowKerasSavedModelBackend(model_store=None, data_store=None, tracking=None, **kwargs)
KIND = 'tfkeras.savedmodel'
fit(modelname, Xname, Yname=None, pure_python=True, tpu_specs=None, **kwargs)

fit the model with data

Parameters:
  • modelname – the name of the model object

  • Xname – the name of the X data set

  • Yname – the name of the Y data set

  • pure_python – if True return a python object. If False return a dataframe. Defaults to True to support any client.

  • kwargs – kwargs passed to the model’s predict method

Returns:

return the meta data object of the model

classmethod supports(obj, name, **kwargs)

test if this backend supports this obj

class omegaml.backends.tensorflow.TensorflowSavedModelBackend(model_store=None, data_store=None, tracking=None, **kwargs)
KIND = 'tf.savedmodel'
fit(modelname, Xname, Yname=None, pure_python=True, tpu_specs=None, **kwargs)

fit the model with data

Parameters:
  • modelname – the name of the model object

  • Xname – the name of the X data set

  • Yname – the name of the Y data set

  • pure_python – if True return a python object. If False return a dataframe. Defaults to True to support any client.

  • kwargs – kwargs passed to the model’s predict method

Returns:

return the meta data object of the model

predict(modelname, Xname, rName=None, pure_python=True, **kwargs)

Predict from a SavedModel

Parameters:
  • modelname

  • Xname

  • rName

  • pure_python

  • kwargs

Returns:

classmethod supports(obj, name, **kwargs)

test if this backend supports this obj

class omegaml.backends.tensorflow.TFEstimatorModelBackend(model_store=None, data_store=None, tracking=None, **kwargs)
KIND = 'tfestimator.model'
fit(modelname, Xname, Yname=None, pure_python=True, **kwargs)

fit the model with data

Parameters:
  • modelname – the name of the model object

  • Xname – the name of the X data set

  • Yname – the name of the Y data set

  • pure_python – if True return a python object. If False return a dataframe. Defaults to True to support any client.

  • kwargs – kwargs passed to the model’s predict method

Returns:

return the meta data object of the model

predict(modelname, Xname, rName=None, pure_python=True, **kwargs)

predict using data stored in Xname

Parameters:
  • modelname – the name of the model object

  • Xname – the name of the X data set

  • rName – the name of the result data object or None

  • pure_python – if True return a python object. If False return a dataframe. Defaults to True to support any client.

  • kwargs – kwargs passed to the model’s predict method

Returns:

return the predicted outcome

score(modelname, Xname, Yname=None, rName=True, pure_python=True, **kwargs)

score using data

Parameters:
  • modelname – the name of the model object

  • Xname – the name of the X data set

  • Yname – the name of the Y data set

  • rName – the name of the transforms’s result data object or None

  • pure_python – if True return a python object. If False return a dataframe. Defaults to True to support any client.

  • kwargs – kwargs passed to the model’s predict method

Returns:

return the score result

classmethod supports(obj, name, **kwargs)

test if this backend supports this obj

class omegaml.backends.rsystem.rmodels.RModelBackend(model_store=None, data_store=None, tracking=None, **kwargs)
KIND = 'model.r'
predict(modelname, Xname, rName=None, pure_python=True, **kwargs)

predict using data stored in Xname

Parameters:
  • modelname – the name of the model object

  • Xname – the name of the X data set

  • rName – the name of the result data object or None

  • pure_python – if True return a python object. If False return a dataframe. Defaults to True to support any client.

  • kwargs – kwargs passed to the model’s predict method

Returns:

return the predicted outcome

classmethod supports(obj, name, **kwargs)

test if this backend supports this obj

Mixins

class omegaml.mixins.store.virtualobj.VirtualObjectMixin

process virtual objects

This checks if an object is a VirtualObject and if so retrieves the handler and processes it.

class omegaml.mixins.store.promotion.PromotionMixin

Promote objects from one bucket to another

promote(name, other, asname=None, drop=True, **kwargs)

Promote object to another bucket.

This effectively copies the object. If the objects exists in the target it will be replaced.

Parameters:
  • name – The name of the object

  • other – the OmegaStore instance to promote to

  • asname – the name to use in other, defaults to .metadata(name).name

  • kwargs – will be forwarded to other.put

Returns:

The Metadata of the new object

Helpers

class omegaml.backends.rsystem.rmodels.RModelProxy(key)

a Python proxy to the R process that runs a model

This provides the model.predict() interface for R models so that we can use the same semantics for R and python scripts.

predict(X_or_name)

call $model.predict()

Parameters:

X_or_name (str) – the X object or name of the dataset