예제 #1
0
파일: sys.py 프로젝트: baibaidj/catalyst
def dump_environment(
    experiment_config: Dict,
    logdir: str,
    configs_path: List[str] = None,
) -> None:
    """
    Saves config, environment variables and package list in JSON into logdir

    Args:
        experiment_config (dict): experiment config
        logdir (str): path to logdir
        configs_path: path(s) to config
    """
    configs_path = configs_path or []
    configs_path = [
        Path(path) for path in configs_path if isinstance(path, str)
    ]
    config_dir = Path(logdir) / "configs"
    config_dir.mkdir(exist_ok=True, parents=True)

    environment = get_environment_vars()

    utils.save_config(experiment_config, config_dir / "_config.json")
    utils.save_config(environment, config_dir / "_environment.json")

    pip_pkg = list_pip_packages()
    (config_dir / "pip-packages.txt").write_text(pip_pkg)
    conda_pkg = list_conda_packages()
    if conda_pkg:
        (config_dir / "conda-packages.txt").write_text(conda_pkg)

    for path in configs_path:
        name: str = path.name
        outpath = config_dir / name
        shutil.copyfile(path, outpath)

    config_str = json.dumps(experiment_config, indent=2, ensure_ascii=False)
    config_str = config_str.replace("\n", "\n\n")

    environment_str = json.dumps(environment, indent=2, ensure_ascii=False)
    environment_str = environment_str.replace("\n", "\n\n")

    pip_pkg = pip_pkg.replace("\n", "\n\n")
    conda_pkg = conda_pkg.replace("\n", "\n\n")
    with SummaryWriter(config_dir) as writer:
        writer.add_text("_config", config_str, 0)
        writer.add_text("_environment", environment_str, 0)
        writer.add_text("pip-packages", pip_pkg, 0)
        if conda_pkg:
            writer.add_text("conda-packages", conda_pkg, 0)
예제 #2
0
 def save_metric(self, logdir: Union[str, Path], metrics: Dict) -> None:
     utils.save_config(metrics,
                       f"{logdir}/checkpoints/{self.metrics_filename}")
예제 #3
0
 def save_metric(self, logdir: str, metrics: Dict) -> None:
     utils.save_config(metrics, f"{logdir}/{self.checkpoints_dir}/{self.metrics_filename}")