How do you construct a sibling report path in the same experiment directory?

with_name replaces the final component and retains the parent directory in the new path.

Python example and interpretation

A model at runs/a/model.bin can have a sibling metrics.json. Constructing that name does not create the directory or the report.

from pathlib import PurePosixPath as P
str(P('runs/a/model.bin').with_name('metrics.json'))

Result 'runs/a/metrics.json'

中文

如何为同一试验目录生成配套的报告路径?

with_name 仅替换路径的最后一个名称,将上级目录保留在结果中。

Python 算例与适用条件

模型位于 runs/a/model.bin,可生成同级 metrics.json。它只是构造名称,目标目录及文件是否存在须另外检查。

from pathlib import PurePosixPath as P
str(P('runs/a/model.bin').with_name('metrics.json'))

结果 'runs/a/metrics.json'

References / 参考来源

Keep reading / 继续阅读