예제 #1
0
 def to_json(self, log_dir, filename):
     utils.check_dir(log_dir)
     json_file = os.path.join(log_dir,filename)
     var_dict = copy.copy(vars(self))
     var_dict.pop('meters')
     #for key in ('viz', 'viz_dict'):
     #    if key in list(var_dict.keys()):
     #        var_dict.pop(key)    
     with open(json_file, 'w') as f:
         json.dump(var_dict, f, cls=utils.NpEncoder)
예제 #2
0
def save_checkpoint(state, is_best, log_dir, filename='checkpoint.pth.tar'):
    utils.check_dir(log_dir)
    filename = os.path.join(log_dir, filename)
    torch.save(state, filename)
    if is_best:
        shutil.copyfile(filename, os.path.join(log_dir, 'model_best.pth.tar'))

    fn = os.path.join(log_dir, 'checkpoint_epoch{}.pth.tar')
    torch.save(state, fn.format(state['epoch']))

    if (state['epoch'] - 1) % 5 != 0:
        #remove intermediate saved models, e.g. non-modulo 5 ones
        if os.path.exists(fn.format(state['epoch'] - 1)):
            os.remove(fn.format(state['epoch'] - 1))

    state['exp_logger'].to_json(log_dir=log_dir, filename='logger.json')
예제 #3
0
def init_output_env(_config, root_dir, log_dir, path_dataset):
    utils.check_dir(os.path.join(root_dir, 'runs'))
    utils.check_dir(log_dir)
    utils.check_dir(path_dataset)
    with open(os.path.join(log_dir, 'config.json'), 'w') as f:
        json.dump(_config, f)
def init_output_env(_config, root_dir, log_dir, path_dataset):
    utils.check_dir(os.path.join(root_dir, "runs"))
    utils.check_dir(log_dir)
    utils.check_dir(path_dataset)
    with open(os.path.join(log_dir, "config.json"), "w") as f:
        json.dump(_config, f)