Exemplo n.º 1
0
def save_yaml(output_dir, config):
    """Save two yaml files.

    1. 'config.yaml' is duplication of python config file as yaml.
    2. 'meta.yaml' for application. The yaml's keys defined by `PARAMS_FOR_EXPORT`.
    """

    if not file_io.exists(output_dir):
        file_io.makedirs(output_dir)

    config_yaml_path = _save_config_yaml(output_dir, config)
    meta_yaml_path = _save_meta_yaml(output_dir, config)

    return config_yaml_path, meta_yaml_path
Exemplo n.º 2
0
def save_npy(dest, outputs, step):
    """Save numpy array to disk.

    Args:
        dest (str): path to save file
        outputs (np.ndarray): save ndarray
        step (int): value of training step

    Raises:
        PermissionError: If dest dir has no permission to write.
        ValueError: If type of step is not int.
    """
    if type(step) is not int:
        raise ValueError("step must be integer.")

    filepath = os.path.join(dest, "npy", "{}.npy".format(step))
    file_io.makedirs(os.path.dirname(filepath))

    file_io.save_npy(filepath, outputs)

    logger.info("save npy: {}".format(filepath))
Exemplo n.º 3
0
def save_json(dest, json, step):
    """Save JSON to disk.

    Args:
        dest (str): path to save file
        json (str): dumped json string
        step (int): value of training step

    Raises:
        PermissionError: If dest dir has no permission to write.
        ValueError: If type of step is not int.
    """
    if type(step) is not int:
        raise ValueError("step must be integer.")

    filepath = os.path.join(dest, "json", "{}.json".format(step))
    file_io.makedirs(os.path.dirname(filepath))

    with file_io.File(filepath, mode="w") as f:
        f.write(json)

    logger.info("save json: {}".format(filepath))
Exemplo n.º 4
0
def save_materials(dest, materials, step):
    """Save materials to disk.

    Args:
        dest (str): path to save file
        materials (list[(str, PIL.Image)]): image data, str in tuple is filename.
        step (int): value of training step

    Raises:
        PermissionError: If dest dir has no permission to write.
        ValueError: If type of step is not int.
    """
    if type(step) is not int:
        raise ValueError("step must be integer.")

    for filename, content in materials:
        filepath = os.path.join(dest, "images", "{}".format(step), filename)
        file_io.makedirs(os.path.dirname(filepath))

        file_io.save_image(filepath, content)

        logger.info("save image: {}".format(filepath))
Exemplo n.º 5
0
def test_makedirs():
    with tempfile.TemporaryDirectory() as d:
        path = os.path.join(d, "test", "test")
        file_io.makedirs(path)
        assert os.path.isdir(path)