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


Python predictor.Predictor方法代码示例

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


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

示例1: test

# 需要导入模块: import predictor [as 别名]
# 或者: from predictor import Predictor [as 别名]
def test(cf, logger, max_fold=None):
    """performs testing for a given fold (or held out set). saves stats in evaluator.
    """
    logger.time("test_fold")
    logger.info('starting testing model of fold {} in exp {}'.format(cf.fold, cf.exp_dir))
    net = model.net(cf, logger).cuda()
    batch_gen = data_loader.get_test_generator(cf, logger)

    test_predictor = Predictor(cf, net, logger, mode='test')
    test_results_list = test_predictor.predict_test_set(batch_gen, return_results = not hasattr(
        cf, "eval_test_separately") or not cf.eval_test_separately)

    if test_results_list is not None:
        test_evaluator = Evaluator(cf, logger, mode='test')
        test_evaluator.evaluate_predictions(test_results_list)
        test_evaluator.score_test_df(max_fold=max_fold)

    logger.info('Testing of fold {} took {}.\n'.format(cf.fold, logger.get_time("test_fold", reset=True, format="hms"))) 
开发者ID:MIC-DKFZ,项目名称:RegRCNN,代码行数:20,代码来源:exec.py

示例2: test

# 需要导入模块: import predictor [as 别名]
# 或者: from predictor import Predictor [as 别名]
def test(logger):
    """
    perform testing for a given fold (or hold out set). save stats in evaluator.
    """
    logger.info('starting testing model of fold {} in exp {}'.format(cf.fold, cf.exp_dir))
    net = model.net(cf, logger).cuda()
    test_predictor = Predictor(cf, net, logger, mode='test')
    test_evaluator = Evaluator(cf, logger, mode='test')
    batch_gen = data_loader.get_test_generator(cf, logger)
    test_results_list = test_predictor.predict_test_set(batch_gen, return_results=True)
    test_evaluator.evaluate_predictions(test_results_list)
    test_evaluator.score_test_df() 
开发者ID:MIC-DKFZ,项目名称:medicaldetectiontoolkit,代码行数:14,代码来源:exec.py

示例3: train_epoches

# 需要导入模块: import predictor [as 别名]
# 或者: from predictor import Predictor [as 别名]
def train_epoches(t_dataset, v_dataset, model, n_epochs, teacher_forcing_ratio):
    eval_f = Evaluate_test()
    best_dev = 0
    train_loader = t_dataset.corpus
    len_batch = len(train_loader)
    epoch_examples_total = t_dataset.len
    for epoch in range(1, n_epochs + 1):
        model.train(True)
        torch.set_grad_enabled(True)
        epoch_loss = 0
        for batch_idx in range(len_batch):
            loss, num_examples = train_batch(t_dataset, batch_idx, model, teacher_forcing_ratio)
            epoch_loss += loss * num_examples
            sys.stdout.write(
                '%d batches processed. current batch loss: %f\r' %
                (batch_idx, loss)
            )
            sys.stdout.flush()
        epoch_loss /= epoch_examples_total
        log_msg = "Finished epoch %d with losses: %.4f" % (epoch, epoch_loss)
        print(log_msg)
        predictor = Predictor(model, v_dataset.vocab, args.cuda)
        print("Start Evaluating")
        cand, ref = predictor.preeval_batch(v_dataset)
        print('Result:')
        print('ref: ', ref[1][0])
        print('cand: ', cand[1])
        final_scores = eval_f.evaluate(live=True, cand=cand, ref=ref)
        epoch_score = 2*final_scores['ROUGE_L']*final_scores['Bleu_4']/(final_scores['Bleu_4']+ final_scores['ROUGE_L'])
        if epoch_score > best_dev:
            torch.save(model.state_dict(), args.save)
            print("model saved")
            best_dev = epoch_score 
开发者ID:EagleW,项目名称:Describing_a_Knowledge_Base,代码行数:35,代码来源:main.py

示例4: __init__

# 需要导入模块: import predictor [as 别名]
# 或者: from predictor import Predictor [as 别名]
def __init__(self, config):
        self.config = config
        # model
        self.model_dir = config.get('model', 'model_dir')
        self.model_prefix = config.get('model', 'model_prefix')
        self.model_epoch = config.getint('model', 'model_epoch')
        self.label_num = config.getint('model', 'label_num')
        self.ctx = mx.gpu(config.getint('model', 'gpu'))

        # data
        self.ds_rate = int(config.get('data', 'ds_rate'))
        self.cell_width = int(config.get('data', 'cell_width'))
        self.test_shape = [int(f) for f in config.get('data', 'test_shape').split(',')]
        self.result_shape = [int(f) for f in config.get('data', 'result_shape').split(',')]
        self.rgb_mean = [float(f) for f in config.get('data', 'rgb_mean').split(',')]
        # rescale for test
        self.test_scales = [float(f) for f in config.get('data', 'test_scales').split(',')]
        self.cell_shapes = [[math.ceil(l * s / self.ds_rate)*self.ds_rate for l in self.test_shape]
                            for s in self.test_scales]
        self.modules = []
        for i, test_scale in enumerate(self.test_scales):
            predictor = mx.module.Module.load(
                prefix=os.path.join(self.model_dir, self.model_prefix),
                epoch=self.model_epoch,
                context=self.ctx)
            data_shape = (1, 3, int(self.cell_shapes[i][0]), int(self.cell_shapes[i][1]))
            predictor.bind(data_shapes=[('data', data_shape)], for_training=False)
            self.modules.append(predictor)
        self.predictor = Predictor(
            modules=self.modules,
            label_num=self.label_num,
            ds_rate=self.ds_rate,
            cell_width=self.cell_width,
            result_shape=self.result_shape,
            test_scales=self.test_scales
        ) 
开发者ID:TuSimple,项目名称:TuSimple-DUC,代码行数:38,代码来源:tester.py


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