š DataChain Open-Source Release. Star us on !
Load MlemObject.
def load_meta(
path: Union[str, os.PathLike],
project: Optional[str] = None,
rev: Optional[str] = None,
follow_links: bool = True,
load_value: bool = False,
fs: Optional[AbstractFileSystem] = None,
try_migrations: bool = False,
*,
force_type: Optional[Type[T]] = None,
) -> T
import os
from mlem.api import load_meta
out_path = os.path.join(os.getcwd(), "saved-model")
loaded = load_meta(out_path)
Loads a MlemObject from a given
path. This differs from load since the latter loads
the actual Python object incorporated within MlemObject. In fact, load
uses
load_meta
beneath and uses its get_value()
method to get the underlying
Python object.
path
(required) - Path to the object. Could be local path or path inside
a git repo.project
(optional) - URL to project if object is located there.rev
(optional) - revision, could be git commit SHA, branch name or tag.follow_links
(optional) - If object we read is a MLEM link, whether to load
theactual object link points to. Defaults to True.load_value
(optional) - Load actual python object incorporated in
MlemObject. Defaults to False.fs
(optional) - filesystem to load from. If not provided, will be inferred
from pathtry_migrations
(optional) - If loading older versions of metadata, try to
apply migrationsforce_type
(optional) - type of meta to be loaded. Defaults to MlemObject
(any mlem meta)MlemObject
: Saved MlemObject
WrongMetaType
- Thrown if the loaded meta object has a different type than
what is expected (force_type or MlemObject)import os
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from mlem.core.objects import MlemModel
from mlem.api import load_meta
train, _ = load_iris(return_X_y=True)
out_path = os.path.join(os.getcwd(), "saved-model")
meta = load_meta(out_path, load_value=True, force_type=MlemModel)
model = meta.get_value()
assert isinstance(model, DecisionTreeClassifier)
model.predict(train)