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. Supported formats include: - runs:/<run_id>/<artifact_path>Example:- runs:/500cf58bee2b40a4a82861cc31a617b1/my_model.pkl
- models:/<model_name>/<stage>Example:- models:/my_model/Production
- models:/<model_name>/<version>/path/to/modelExample:- models:/my_model/2/path/to/model
- models:/<model_name>@<alias>/path/to/modelExample:- models:/my_model@staging/path/to/model
- Cloud storage URIs: - s3://<bucket>/<path>or- gs://<bucket>/<path>
- Tracking server artifact URIs: - http://<host>/mlartifactsor- mlflow-artifacts://<host>/mlartifacts
 - Exactly one of - artifact_urior- run_idmust be specified.
- run_id – ID of the MLflow Run containing the artifacts. Exactly one of - run_idor- artifact_urimust 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) list[FileInfo][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_urior- run_idmust be specified.
- run_id – ID of the MLflow Run containing the artifacts. Exactly one of - run_idor- artifact_urimust 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[str, typing.Any][source]
- Loads the artifact contents as a dictionary. - Parameters
- artifact_uri – artifact location. 
- Returns
- A dictionary. 
 - 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) 
- mlflow.artifacts.load_image(artifact_uri: str)[source]
- Loads artifact contents as a - PIL.Image.Imageobject- Parameters
- artifact_uri – Artifact location. 
- Returns
- A PIL.Image object. 
 - 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) 
- 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. 
 - 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)