mlflow.artifacts

APIs for interacting with artifacts in MLflow

mlflow.artifacts.download_artifacts(artifact_uri: Optional[str] = None, run_id: Optional[str] = None, artifact_path: Optional[str] = None, dst_path: Optional[str] = None, tracking_uri: Optional[str] = None)str[source]

Download an artifact file or directory to a local directory.

Parameters
  • artifact_uri – URI pointing to the artifacts, such as "runs:/500cf58bee2b40a4a82861cc31a617b1/my_model.pkl", "models:/my_model/Production", or "s3://my_bucket/my/file.txt". Exactly one of artifact_uri or run_id must be specified.

  • run_id – ID of the MLflow Run containing the artifacts. Exactly one of run_id or artifact_uri must be specified.

  • artifact_path – (For use with run_id) If specified, a path relative to the MLflow Run’s root directory containing the artifacts to download.

  • dst_path – Path of the local filesystem destination directory to which to download the specified artifacts. If the directory does not exist, it is created. If unspecified, the artifacts are downloaded to a new uniquely-named directory on the local filesystem, unless the artifacts already exist on the local filesystem, in which case their local path is returned directly.

  • tracking_uri – The tracking URI to be used when downloading artifacts.

Returns

The location of the artifact file or directory on the local filesystem.

mlflow.artifacts.list_artifacts(artifact_uri: Optional[str] = None, run_id: Optional[str] = None, artifact_path: Optional[str] = None, tracking_uri: Optional[str] = None)[source]

List artifacts at the specified URI.

Parameters
  • artifact_uri – URI pointing to the artifacts, such as "runs:/500cf58bee2b40a4a82861cc31a617b1/my_model.pkl", "models:/my_model/Production", or "s3://my_bucket/my/file.txt". Exactly one of artifact_uri or run_id must be specified.

  • run_id – ID of the MLflow Run containing the artifacts. Exactly one of run_id or artifact_uri must be specified.

  • artifact_path – (For use with run_id) If specified, a path relative to the MLflow Run’s root directory containing the artifacts to list.

  • tracking_uri – The tracking URI to be used when list artifacts.

Returns

List of artifacts as FileInfo listed directly under path.

mlflow.artifacts.load_dict(artifact_uri: str)dict[source]

Loads the artifact contents as a dictionary.

Parameters

artifact_uri – artifact location.

Returns

A dictionary.

Example
import mlflow

with mlflow.start_run() as run:
    artifact_uri = run.info.artifact_uri
    mlflow.log_dict({"mlflow-version": "0.28", "n_cores": "10"}, "config.json")
    config_json = mlflow.artifacts.load_dict(artifact_uri + "/config.json")
    print(config_json)
Output
{'mlflow-version': '0.28', 'n_cores': '10'}
mlflow.artifacts.load_image(artifact_uri: str)[source]

Loads artifact contents as a PIL.Image.Image object

Parameters

artifact_uri – Artifact location.

Returns

A PIL.Image object.

Example
import mlflow
from PIL import Image

with mlflow.start_run() as run:
    image = Image.new("RGB", (100, 100))
    artifact_uri = run.info.artifact_uri
    mlflow.log_image(image, "image.png")
    image = mlflow.artifacts.load_image(artifact_uri + "/image.png")
    print(image)
Output
<PIL.PngImagePlugin.PngImageFile image mode=RGB size=100x100 at 0x11D2FA3D0>
mlflow.artifacts.load_text(artifact_uri: str)str[source]

Loads the artifact contents as a string.

Parameters

artifact_uri – Artifact location.

Returns

The contents of the artifact as a string.

Example
import mlflow

with mlflow.start_run() as run:
    artifact_uri = run.info.artifact_uri
    mlflow.log_text("This is a sentence", "file.txt")
    file_content = mlflow.artifacts.load_text(artifact_uri + "/file.txt")
    print(file_content)
Output
This is a sentence