当前位置: 首页>>代码示例>>Python>>正文


Python solver.Solver方法代码示例

本文整理汇总了Python中solver.Solver方法的典型用法代码示例。如果您正苦于以下问题:Python solver.Solver方法的具体用法?Python solver.Solver怎么用?Python solver.Solver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在solver的用法示例。


在下文中一共展示了solver.Solver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(_):
    
    with tf.device(FLAGS.device):
	model_save_path = FLAGS.model_save_path + '/' + FLAGS.method + '/alpha_' + FLAGS.alpha
	log_dir = 'logs/' + FLAGS.method + '/alpha_' + FLAGS.alpha
	model = logDcoral(mode=FLAGS.mode, method=FLAGS.method, hidden_size = 64, learning_rate=0.0001, alpha=float(FLAGS.alpha))
	solver = Solver(model, model_save_path=model_save_path, log_dir=log_dir)
	
	# create directory if it does not exist
	if not tf.gfile.Exists(model_save_path):
		tf.gfile.MakeDirs(model_save_path)
	
	if FLAGS.mode == 'train':
		solver.train()
	elif FLAGS.mode == 'test':
		solver.test()
	elif FLAGS.mode == 'tsne':
		solver.tsne()
	else:
	    print 'Unrecognized mode.' 
开发者ID:pmorerio,项目名称:minimal-entropy-correlation-alignment,代码行数:22,代码来源:main.py

示例2: layerwise_pretrain

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def layerwise_pretrain(self, X, batch_size, n_iter, optimizer, l_rate, decay,
                           lr_scheduler=None, print_every=1000):
        def l2_norm(label, pred):
            return np.mean(np.square(label-pred))/2.0
        solver = Solver(optimizer, momentum=0.9, wd=decay, learning_rate=l_rate,
                        lr_scheduler=lr_scheduler)
        solver.set_metric(mx.metric.CustomMetric(l2_norm))
        solver.set_monitor(Monitor(print_every))
        data_iter = mx.io.NDArrayIter({'data': X}, batch_size=batch_size, shuffle=True,
                                      last_batch_handle='roll_over')
        for i in range(self.N):
            if i == 0:
                data_iter_i = data_iter
            else:
                X_i = list(model.extract_feature(
                    self.internals[i-1], self.args, self.auxs, data_iter, X.shape[0],
                    self.xpu).values())[0]
                data_iter_i = mx.io.NDArrayIter({'data': X_i}, batch_size=batch_size,
                                                last_batch_handle='roll_over')
            logging.info('Pre-training layer %d...', i)
            solver.solve(self.xpu, self.stacks[i], self.args, self.args_grad, self.auxs,
                         data_iter_i, 0, n_iter, {}, False) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:24,代码来源:autoencoder.py

示例3: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(config):
    svhn_loader, mnist_loader = get_loader(config)
    
    solver = Solver(config, svhn_loader, mnist_loader)
    cudnn.benchmark = True 
    
    # create directories if not exist
    if not os.path.exists(config.model_path):
        os.makedirs(config.model_path)
    if not os.path.exists(config.sample_path):
        os.makedirs(config.sample_path)
    
    if config.mode == 'train':
        solver.train()
    elif config.mode == 'sample':
        solver.sample() 
开发者ID:yunjey,项目名称:mnist-svhn-transfer,代码行数:18,代码来源:main.py

示例4: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(_):
    
    with tf.device(FLAGS.device):
	
	model_save_path = 'model/'+FLAGS.model_save_path	
	# create directory if it does not exist
	if not tf.gfile.Exists(model_save_path):
		tf.gfile.MakeDirs(model_save_path)
	log_dir = 'logs/'+ model_save_path
	
	model = Model(learning_rate=0.0003, mode=FLAGS.mode)
	solver = Solver(model, model_save_path=model_save_path, log_dir=log_dir)
	
	# create directory if it does not exist
	if not tf.gfile.Exists(model_save_path):
		tf.gfile.MakeDirs(model_save_path)
	
	if FLAGS.mode == 'train':
		solver.train()
	elif FLAGS.mode == 'test':
		solver.test(checkpoint=FLAGS.checkpoint)
	else:
	    print 'Unrecognized mode.' 
开发者ID:pmorerio,项目名称:dl-uncertainty,代码行数:25,代码来源:main.py

示例5: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(_):
    
    model = DTN(mode=FLAGS.mode, learning_rate=0.0003)
    solver = Solver(model, batch_size=100, pretrain_iter=20000, train_iter=2000, sample_iter=100, 
                    svhn_dir='svhn', mnist_dir='mnist', model_save_path=FLAGS.model_save_path, sample_save_path=FLAGS.sample_save_path)
    
    # create directories if not exist
    if not tf.gfile.Exists(FLAGS.model_save_path):
        tf.gfile.MakeDirs(FLAGS.model_save_path)
    if not tf.gfile.Exists(FLAGS.sample_save_path):
        tf.gfile.MakeDirs(FLAGS.sample_save_path)
    
    if FLAGS.mode == 'pretrain':
        solver.pretrain()
    elif FLAGS.mode == 'train':
        solver.train()
    else:
        solver.eval() 
开发者ID:yunjey,项目名称:domain-transfer-network,代码行数:20,代码来源:main.py

示例6: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(config):
    if config.mode == 'train':
        train_loader = get_loader(config)
        run = 0
        while os.path.exists("%s/run-%d" % (config.save_folder, run)):
            run += 1
        os.mkdir("%s/run-%d" % (config.save_folder, run))
        os.mkdir("%s/run-%d/models" % (config.save_folder, run))
        config.save_folder = "%s/run-%d" % (config.save_folder, run)
        train = Solver(train_loader, None, config)
        train.train()
    elif config.mode == 'test':
        config.test_root, config.test_list = get_test_info(config.sal_mode)
        test_loader = get_loader(config, mode='test')
        if not os.path.exists(config.test_fold): os.mkdir(config.test_fold)
        test = Solver(None, test_loader, config)
        test.test()
    else:
        raise IOError("illegal input!!!") 
开发者ID:Res2Net,项目名称:Res2Net-PoolNet,代码行数:21,代码来源:main.py

示例7: finetune

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def finetune(self, X, batch_size, n_iter, optimizer, l_rate, decay, lr_scheduler=None,
                 print_every=1000):
        def l2_norm(label, pred):
            return np.mean(np.square(label-pred))/2.0
        solver = Solver(optimizer, momentum=0.9, wd=decay, learning_rate=l_rate,
                        lr_scheduler=lr_scheduler)
        solver.set_metric(mx.metric.CustomMetric(l2_norm))
        solver.set_monitor(Monitor(print_every))
        data_iter = mx.io.NDArrayIter({'data': X}, batch_size=batch_size, shuffle=True,
                                      last_batch_handle='roll_over')
        logging.info('Fine tuning...')
        solver.solve(self.xpu, self.loss, self.args, self.args_grad, self.auxs, data_iter,
                     0, n_iter, {}, False) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:15,代码来源:autoencoder.py

示例8: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main():
    cur_dir = file_abs_path(__file__)
    manager = Manager(cur_dir, seed=None, mode='Train')
    logger = manager.logger
    ParseArgs(logger)
    if manager.seed is not None:
        random.seed(manager.seed)
        np.random.seed(manager.seed)
        torch.manual_seed(manager.seed)

    # ['iLIDS-VID', 'PRID-2011', 'LPW', 'MARS', 'VIPeR', 'Market1501', 'CUHK03', 'CUHK01', 'DukeMTMCreID', 'GRID', 'DukeMTMC-VideoReID']
    #       0            1         2      3        4          5           6         7             8           9             10

    manager.set_dataset(4)

    perf_box = {}
    repeat_times = 10
    for task_i in range(repeat_times):
        manager.split_id = int(task_i) 
        task = Solver(manager)
        train_test_time = timer_lite(task.run)
        perf_box[str(task_i)] = task.perf_box
        manager.store_performance(perf_box)

        logger.info('-----------Total time------------')
        logger.info('Split ID:' + str(task_i) + '  ' + str(train_test_time))
        logger.info('---------------------------------')

    compute_rank(perf_box, logger) 
开发者ID:yolomax,项目名称:person-reid-lib,代码行数:31,代码来源:train_test.py

示例9: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main():
    cur_dir = file_abs_path(__file__)
    manager = Manager(cur_dir, seed=None, mode='Train')
    logger = manager.logger
    ParseArgs(logger)
    if manager.seed is not None:
        random.seed(manager.seed)
        np.random.seed(manager.seed)
        torch.manual_seed(manager.seed)

    # ['iLIDS-VID', 'PRID-2011', 'LPW', 'MARS', 'VIPeR', 'Market1501', 'CUHK03', 'CUHK01', 'DukeMTMCreID', 'GRID', 'DukeMTMC-VideoReID']
    #       0            1         2      3        4          5           6         7             8           9             10

    manager.set_dataset(0)

    perf_box = {}
    repeat_times = 10
    for task_i in range(repeat_times):
        manager.split_id = int(task_i) 
        task = Solver(manager)
        train_test_time = timer_lite(task.run)
        perf_box[str(task_i)] = task.perf_box
        manager.store_performance(perf_box)

        logger.info('-----------Total time------------')
        logger.info('Split ID:' + str(task_i) + '  ' + str(train_test_time))
        logger.info('---------------------------------')

    compute_rank(perf_box, logger) 
开发者ID:yolomax,项目名称:person-reid-lib,代码行数:31,代码来源:train_test.py

示例10: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(args):
    seed = args.seed
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    np.random.seed(seed)

    net = Solver(args)

    if args.train:
        net.train()
    else:
        net.traverse() 
开发者ID:1Konny,项目名称:Beta-VAE,代码行数:14,代码来源:main.py

示例11: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(_):
    
    with tf.device(FLAGS.device):
	
	model_save_path = 'model/'+FLAGS.model_save_path	
	# create directory if it does not exist
	if not tf.gfile.Exists(model_save_path):
		tf.gfile.MakeDirs(model_save_path)
	log_dir = 'logs/'+ model_save_path
	
	if FLAGS.mode == 'test':
	    checkpoint = model_save_path+'/model'
	
	model = Model(learning_rate=0.0003, mode=FLAGS.mode)
	solver = Solver(model, model_save_path=model_save_path, 
					log_dir=log_dir, 
					training_size=int(FLAGS.training_size)
					)
	
	# create directory if it does not exist
	if not tf.gfile.Exists(model_save_path):
		tf.gfile.MakeDirs(model_save_path)
	
	if FLAGS.mode == 'train':
		solver.train()
	elif FLAGS.mode == 'test':
		solver.test(checkpoint=checkpoint)
	else:
	    print 'Unrecognized mode.' 
开发者ID:pmorerio,项目名称:dl-uncertainty,代码行数:31,代码来源:main.py

示例12: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(config):
    # For fast training.
    cudnn.benchmark = True

    # Create directories if not exist.
    if not os.path.exists(config.log_dir):
        os.makedirs(config.log_dir)
    if not os.path.exists(config.model_save_dir):
        os.makedirs(config.model_save_dir)
    if not os.path.exists(config.sample_dir):
        os.makedirs(config.sample_dir)
    if not os.path.exists(config.result_dir):
        os.makedirs(config.result_dir)

    # Data loader.
    celeba_loader = None
    rafd_loader = None

    if config.dataset in ['CelebA', 'Both']:
        celeba_loader = get_loader(config.celeba_image_dir, config.attr_path, config.selected_attrs,
                                   config.celeba_crop_size, config.image_size, config.batch_size,
                                   'CelebA', config.mode, config.num_workers)
    if config.dataset in ['RaFD', 'Both']:
        rafd_loader = get_loader(config.rafd_image_dir, None, None,
                                 config.rafd_crop_size, config.image_size, config.batch_size,
                                 'RaFD', config.mode, config.num_workers)
    

    # Solver for training and testing StarGAN.
    solver = Solver(celeba_loader, rafd_loader, config)

    if config.mode == 'train':
        if config.dataset in ['CelebA', 'RaFD']:
            solver.train()
        elif config.dataset in ['Both']:
            solver.train_multi()
    elif config.mode == 'test':
        if config.dataset in ['CelebA', 'RaFD']:
            solver.test()
        elif config.dataset in ['Both']:
            solver.test_multi() 
开发者ID:yunjey,项目名称:stargan,代码行数:43,代码来源:main.py

示例13: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(config):
    # For fast training.
    cudnn.benchmark = True

    # Create directories if not exist.
    if not os.path.exists(config.log_dir):
        os.makedirs(config.log_dir)
    if not os.path.exists(config.model_save_dir):
        os.makedirs(config.model_save_dir)

    imgdirs_train = ['data/afw/', 'data/helen/trainset/', 'data/lfpw/trainset/']
    imgdirs_test_commomset = ['data/helen/testset/','data/lfpw/testset/']

    # Dataset and Dataloader
    if config.phase == 'test':
        trainset=None
        train_loader = None
    else:
        trainset = Dataset(imgdirs_train, config.phase, 'train', config.rotFactor, config.res, config.gamma)
        train_loader = data.DataLoader(trainset,
                                       batch_size=config.batch_size,
                                       shuffle=True,
                                       num_workers=config.num_workers,
                                       pin_memory=True)
    testset = Dataset(imgdirs_test_commomset, 'test', config.attr, config.rotFactor, config.res, config.gamma)
    test_loader = data.DataLoader(testset,
                                  batch_size=config.batch_size,
                                  num_workers=config.num_workers,
                                  pin_memory=True)
    
    # Solver for training and testing.
    solver = Solver(train_loader, test_loader, config)
    if config.phase == 'train':
        solver.train()
    else:
        solver.load_state_dict(config.best_model)
        solver.test() 
开发者ID:face-alignment-group-of-ahucs,项目名称:SHN-based-2D-face-alignment,代码行数:39,代码来源:main.py

示例14: main

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def main(args):
    # Construct Solver
    # data
    tr_dataset = AudioDataset(args.train_dir, args.batch_size,
                              sample_rate=args.sample_rate, segment=args.segment)
    cv_dataset = AudioDataset(args.valid_dir, batch_size=1,  # 1 -> use less GPU memory to do cv
                              sample_rate=args.sample_rate,
                              segment=-1, cv_maxlen=args.cv_maxlen)  # -1 -> use full audio
    tr_loader = AudioDataLoader(tr_dataset, batch_size=1,
                                shuffle=args.shuffle,
                                num_workers=args.num_workers)
    cv_loader = AudioDataLoader(cv_dataset, batch_size=1,
                                num_workers=0)
    data = {'tr_loader': tr_loader, 'cv_loader': cv_loader}
    # model
    model = ConvTasNet(args.N, args.L, args.B, args.H, args.P, args.X, args.R,
                       args.C, norm_type=args.norm_type, causal=args.causal,
                       mask_nonlinear=args.mask_nonlinear)
    print(model)
    if args.use_cuda:
        model = torch.nn.DataParallel(model)
        model.cuda()
    # optimizer
    if args.optimizer == 'sgd':
        optimizier = torch.optim.SGD(model.parameters(),
                                     lr=args.lr,
                                     momentum=args.momentum,
                                     weight_decay=args.l2)
    elif args.optimizer == 'adam':
        optimizier = torch.optim.Adam(model.parameters(),
                                      lr=args.lr,
                                      weight_decay=args.l2)
    else:
        print("Not support optimizer")
        return

    # solver
    solver = Solver(data, model, optimizier, args)
    solver.train() 
开发者ID:kaituoxu,项目名称:Conv-TasNet,代码行数:41,代码来源:train.py

示例15: train

# 需要导入模块: import solver [as 别名]
# 或者: from solver import Solver [as 别名]
def train(train_params, common_params, data_params, net_params):
    train_data, test_data = load_data(data_params)

    train_loader = torch.utils.data.DataLoader(train_data, batch_size=train_params['train_batch_size'], shuffle=True,
                                               num_workers=4, pin_memory=True)
    val_loader = torch.utils.data.DataLoader(test_data, batch_size=train_params['val_batch_size'], shuffle=False,
                                             num_workers=4, pin_memory=True)

    if train_params['use_pre_trained']:
        quicknat_model = torch.load(train_params['pre_trained_path'])
    else:
        quicknat_model = QuickNat(net_params)

    solver = Solver(quicknat_model,
                    device=common_params['device'],
                    num_class=net_params['num_class'],
                    optim_args={"lr": train_params['learning_rate'],
                                "betas": train_params['optim_betas'],
                                "eps": train_params['optim_eps'],
                                "weight_decay": train_params['optim_weight_decay']},
                    model_name=common_params['model_name'],
                    exp_name=train_params['exp_name'],
                    labels=data_params['labels'],
                    log_nth=train_params['log_nth'],
                    num_epochs=train_params['num_epochs'],
                    lr_scheduler_step_size=train_params['lr_scheduler_step_size'],
                    lr_scheduler_gamma=train_params['lr_scheduler_gamma'],
                    use_last_checkpoint=train_params['use_last_checkpoint'],
                    log_dir=common_params['log_dir'],
                    exp_dir=common_params['exp_dir'])

    solver.train(train_loader, val_loader)
    final_model_path = os.path.join(common_params['save_model_dir'], train_params['final_model_file'])
    quicknat_model.save(final_model_path)
    print("final model saved @ " + str(final_model_path)) 
开发者ID:ai-med,项目名称:quickNAT_pytorch,代码行数:37,代码来源:run.py


注:本文中的solver.Solver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。