Esempio n. 1
0
def save(fpath: str, obj: Any, **kwargs) -> None:
    assert isinstance(fpath, str), type(fpath)
    fs.makedir(os.path.dirname(fpath))

    for extension in sorted(__io_registry.keys(), key=len, reverse=True):
        if fpath.endswith(extension) and 'save' in __io_registry[extension]:
            __io_registry[extension]['save'](fpath, obj, **kwargs)
            return

    raise NotImplementedError(f'"{fpath}" cannot be saved.')
Esempio n. 2
0
def set_run_dir(dirpath: str) -> None:
    global _run_dir
    _run_dir = fs.normpath(dirpath)
    fs.makedir(_run_dir)

    prefix = '{time}'
    if dist.size() > 1:
        prefix += '_{:04d}'.format(dist.rank())
    logger.add(os.path.join(_run_dir, 'logging', prefix + '.log'),
               format=('{time:YYYY-MM-DD HH:mm:ss.SSS} | '
                       '{name}:{function}:{line} | '
                       '{level} | {message}'))
Esempio n. 3
0
 def _set_trainer(self, trainer: Trainer) -> None:
     self.scalars: Dict[str, Union[int, float]] = {}
     fs.makedir(self.save_dir)
     self.file = open(os.path.join(self.save_dir, 'scalars.jsonl'), 'a')
Esempio n. 4
0
 def _set_trainer(self, trainer: Trainer) -> None:
     self.scalars = dict()
     fs.makedir(self.save_dir)
     self.file = open(os.path.join(self.save_dir, 'scalars.jsonl'), 'a')