Exemplo n.º 1
0
def restore_or_init(net, logger, dest_dir, args):
    from_scratch = False
    if utils.isint(args.restore):
        restore_from, restore_iter = (dest_dir, args.restore)
        restore_fromthis = True
    else:
        restore_from, restore_iter = utils.parent_dir(args.restore)
        if not osp.isabs(restore_from):
            restore_from = osp.join(utils.parent_dir(dest_dir)[0], restore_from)
        restore_fromthis = False
    saved = utils.get_saves(restore_from)
    restore_iter = int(restore_iter)
    if restore_iter == -1:
        if saved:
            start_iter, iter_dir = saved[-1]
        else:
            if restore_fromthis:
                from_scratch = True
            else:
                raise ValueError('No checkpoints found in {}'.format(restore_from))
    else:
        for start_iter, iter_dir in saved:
            if start_iter == restore_iter:
                break
        else:
            if restore_iter == 0:
                from_scratch = True
            else:
                raise ValueError('Checkpoint {} not found in {}'.format(restore_iter, restore_from))
    if from_scratch:
        start_iter = 0
    if not from_scratch:
        snap_dest = osp.join(iter_dir, 'state_dict.pth')  # map to cpu in case the optim was done with different devices
        print("Restoring net and logger state from", snap_dest)
        saved_state_dict = torch.load(snap_dest, map_location=lambda storage, loc: storage)
        if hasattr(saved_state_dict,'_OrderedDict__root'):
            load_weights(net, saved_state_dict)
        else:
            net.initialize_from_file(snap_dest)
        logger.restore(iter_dir)
    return start_iter
Exemplo n.º 2
0
 def cleanup(self):
     clean_dir = os.path.join(parent_dir(__file__), "examples")
     delete_files_in_dir(clean_dir, ["README"])
 def get_tests_directory(self):
     module = self.__class__.__module__.split(".")[-2]
     return os.path.join(parent_dir(__file__), module)
Exemplo n.º 4
0
# -*- coding: utf-8 -*-

import os.path

from utils import parent_dir

DEFAULT_CONFIG_FILE = parent_dir(__file__) + os.path.sep + 'serverrc'


def load_config(confpath):
    exec(compile(open(confpath).read(), confpath, 'exec'))
    return locals()


def load_global_config():
    return load_config(DEFAULT_CONFIG_FILE)


if __name__ == '__main__':
    print load_config()
# -*- coding: utf-8 -*-

import os.path

from configobj import ConfigObj

from utils import encode, decode, parent_dir

# _ = lambda f: os.path.dirname(os.path.abspath(f))

config_dir = parent_dir(__file__) + os.path.sep + "config"
# config_dir = _(_(__file__)) + os.path.sep + 'config'
GLOBAL_CONFIG = config_dir + os.path.sep + "agent.conf"
METRIC_CONFIG = config_dir + os.path.sep + "metric.conf"
METRIC_LIST = config_dir + os.path.sep + "metric.list"
DEFAULT_METRIC_LIST = config_dir + os.path.sep + "metric.list.default"

# print GLOBAL_CONFIG

# def load_config():
# exec(compile(open(GLOBAL_CONFIG).read(), GLOBAL_CONFIG, 'exec'))
# return locals()


def load_config(filename):
    return ConfigObj(filename)


def load_global_config():
    return ConfigObj(GLOBAL_CONFIG)