mlrun.artifacts#

mlrun.artifacts.get_model(model_dir, suffix='')[source]#

return model file, model spec object, and list of extra data items

this function will get the model file, metadata, and extra data the returned model file is always local, when using remote urls (such as v3io://, s3://, store://, ..) it will be copied locally.

returned extra data dict (of key, DataItem objects) allow reading additional model files/objects e.g. use DataItem.get() or .download(target) .as_df() to read

example:

model_file, model_artifact, extra_data = get_model(models_path, suffix='.pkl')
model = load(open(model_file, "rb"))
categories = extra_data['categories'].as_df()
Parameters
  • model_dir – model dir or artifact path (store://..) or DataItem

  • suffix – model filename suffix (when using a dir)

Returns

model filename, model artifact object, extra data dict

mlrun.artifacts.update_model(model_artifact, parameters: Optional[dict] = None, metrics: Optional[dict] = None, extra_data: Optional[dict] = None, inputs: Optional[List[mlrun.features.Feature]] = None, outputs: Optional[List[mlrun.features.Feature]] = None, feature_vector: Optional[str] = None, feature_weights: Optional[list] = None, key_prefix: str = '', labels: Optional[dict] = None, write_spec_copy=True, store_object: bool = True)[source]#

Update model object attributes

this method will edit or add attributes to a model object

example:

update_model(model_path, metrics={'speed': 100},
             extra_data={'my_data': b'some text', 'file': 's3://mybucket/..'})
Parameters
  • model_artifact – model artifact object or path (store://..) or DataItem

  • parameters – parameters dict

  • metrics – model metrics e.g. accuracy

  • extra_data – extra data items key, value dict (value can be: path string | bytes | artifact)

  • inputs – list of input features (feature vector schema)

  • outputs – list of output features (output vector schema)

  • feature_vector – feature store feature vector uri (store://feature-vectors/<project>/<name>[:tag])

  • feature_weights – list of feature weights, one per input column

  • key_prefix – key prefix to add to metrics and extra data items

  • labels – metadata labels

  • write_spec_copy – write a YAML copy of the spec to the target dir

  • store_object – Whether to store the model artifact updated.