コード例 #1
0
ファイル: main.py プロジェクト: yxr20004/StarNet
def set_cfg():
    c = config.parameter()

    datacfg = mFlags.data
    c.cfgfile = mFlags.config
    c.weightfile = mFlags.weights
    no_eval = mFlags.no_eval

    data_options = read_data_cfg(datacfg)
    net_options = parse_cfg(c.cfgfile)[0]

    c.use_cuda = torch.cuda.is_available() and (True if c.use_cuda is None else
                                                c.use_cuda)
    c.trainlist = data_options['train']
    c.testlist = data_options['valid']
    c.backupdir = data_options['backup']
    c.gpus = data_options['gpus']
    c.ngpus = len(c.gpus.split(','))
    c.num_workers = int(data_options['num_workers'])

    c.batch_size = int(net_options['batch'])
    c.max_batches = 10 * int(net_options['max_batches'])
    c.learning_rate = float(net_options['learning_rate'])
    c.momentum = float(net_options['momentum'])
    c.decay = float(net_options['decay'])
    c.steps = [float(step) for step in net_options['steps'].split(',')]
    c.scales = [float(scale) for scale in net_options['scales'].split(',')]

    try:
        c.max_epochs = int(net_options['max_epochs'])
    except KeyError:
        nsamples = file_lines(c.trainlist)
        c.max_epochs = (c.max_batches * c.batch_size) // nsamples + 1
    seed = int(time.time())
    torch.manual_seed(seed)
    if c.use_cuda:
        os.environ['CUDA_VISIBLE_DEVICES'] = c.gpus
        torch.cuda.manual_seed(seed)

    c.device = torch.device("cuda" if c.use_cuda else "cpu")
    print('set_cfg')

    return c