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: dict | None = None, metrics: dict | None = None, extra_data: dict | None = None, inputs: list[mlrun.features.Feature] | None = None, outputs: list[mlrun.features.Feature] | None = None, feature_vector: str | None = None, feature_weights: list | None = None, key_prefix: str = '', labels: dict | None = 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.