當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。