本文整理匯總了Python中mlflow.log_artifacts方法的典型用法代碼示例。如果您正苦於以下問題:Python mlflow.log_artifacts方法的具體用法?Python mlflow.log_artifacts怎麽用?Python mlflow.log_artifacts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mlflow
的用法示例。
在下文中一共展示了mlflow.log_artifacts方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: log_project_artifacts_to_mlflow
# 需要導入模塊: import mlflow [as 別名]
# 或者: from mlflow import log_artifacts [as 別名]
def log_project_artifacts_to_mlflow(function: Callable):
"""
Log the artifact to mlflow
Parameters
----------
function
function to wrap
"""
@wraps(function)
def wrapped(*args, **kwargs):
if mlflow.active_run() is None:
_warn_about_no_run()
return function(*args, **kwargs)
artifacts_path = project.get_active_artifacts_directory()
artifacts_path_realpath = os.path.realpath(artifacts_path)
mlflow.log_artifacts(artifacts_path_realpath)
return function(*args, **kwargs)
return wrapped
# pylint: disable=invalid-name
# this is method, not a constant, and is used inside of the patch
示例2: etl_data
# 需要導入模塊: import mlflow [as 別名]
# 或者: from mlflow import log_artifacts [as 別名]
def etl_data(ratings_csv, max_row_limit):
with mlflow.start_run() as mlrun:
tmpdir = tempfile.mkdtemp()
ratings_parquet_dir = os.path.join(tmpdir, 'ratings-parquet')
spark = pyspark.sql.SparkSession.builder.getOrCreate()
print("Converting ratings CSV %s to Parquet %s" % (ratings_csv, ratings_parquet_dir))
ratings_df = spark.read \
.option("header", "true") \
.option("inferSchema", "true") \
.csv(ratings_csv) \
.drop("timestamp") # Drop unused column
ratings_df.show()
if max_row_limit != -1:
ratings_df = ratings_df.limit(max_row_limit)
ratings_df.write.parquet(ratings_parquet_dir)
print("Uploading Parquet ratings: %s" % ratings_parquet_dir)
mlflow.log_artifacts(ratings_parquet_dir, "ratings-parquet-dir")
示例3: log_artifacts
# 需要導入模塊: import mlflow [as 別名]
# 或者: from mlflow import log_artifacts [as 別名]
def log_artifacts(local_dir: str, artifact_path: str = None):
mlflow.log_artifacts(local_dir, artifact_path)
示例4: log_artifacts
# 需要導入模塊: import mlflow [as 別名]
# 或者: from mlflow import log_artifacts [as 別名]
def log_artifacts(cls, self):
raise NotImplementedError()
示例5: log_artifacts
# 需要導入模塊: import mlflow [as 別名]
# 或者: from mlflow import log_artifacts [as 別名]
def log_artifacts(local_dir, artifact_path=None):
return None
示例6: _log_artifacts_with_warning
# 需要導入模塊: import mlflow [as 別名]
# 或者: from mlflow import log_artifacts [as 別名]
def _log_artifacts_with_warning(**kwargs):
try_mlflow_log(mlflow.log_artifacts, **kwargs)
示例7: test_log_artifact
# 需要導入模塊: import mlflow [as 別名]
# 或者: from mlflow import log_artifacts [as 別名]
def test_log_artifact():
artifact_src_dir = tempfile.mkdtemp()
# Create artifacts
_, path0 = tempfile.mkstemp(dir=artifact_src_dir)
_, path1 = tempfile.mkstemp(dir=artifact_src_dir)
for i, path in enumerate([path0, path1]):
with open(path, "w") as handle:
handle.write("%s" % str(i))
# Log an artifact, verify it exists in the directory returned by get_artifact_uri
# after the run finishes
artifact_parent_dirs = ["some_parent_dir", None]
for parent_dir in artifact_parent_dirs:
with start_run():
artifact_uri = mlflow.get_artifact_uri()
run_artifact_dir = local_file_uri_to_path(artifact_uri)
mlflow.log_artifact(path0, parent_dir)
expected_dir = os.path.join(run_artifact_dir, parent_dir) \
if parent_dir is not None else run_artifact_dir
assert os.listdir(expected_dir) == [os.path.basename(path0)]
logged_artifact_path = os.path.join(expected_dir, path0)
assert filecmp.cmp(logged_artifact_path, path0, shallow=False)
# Log multiple artifacts, verify they exist in the directory returned by get_artifact_uri
for parent_dir in artifact_parent_dirs:
with start_run():
artifact_uri = mlflow.get_artifact_uri()
run_artifact_dir = local_file_uri_to_path(artifact_uri)
mlflow.log_artifacts(artifact_src_dir, parent_dir)
# Check that the logged artifacts match
expected_artifact_output_dir = os.path.join(run_artifact_dir, parent_dir) \
if parent_dir is not None else run_artifact_dir
dir_comparison = filecmp.dircmp(artifact_src_dir, expected_artifact_output_dir)
assert len(dir_comparison.left_only) == 0
assert len(dir_comparison.right_only) == 0
assert len(dir_comparison.diff_files) == 0
assert len(dir_comparison.funny_files) == 0