當前位置: 首頁>>代碼示例>>Python>>正文


Python meteor.Meteor方法代碼示例

本文整理匯總了Python中pycocoevalcap.meteor.meteor.Meteor方法的典型用法代碼示例。如果您正苦於以下問題:Python meteor.Meteor方法的具體用法?Python meteor.Meteor怎麽用?Python meteor.Meteor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pycocoevalcap.meteor.meteor的用法示例。


在下文中一共展示了meteor.Meteor方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: calc_scores

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def calc_scores(ref, hypo):
    """
    ref, dictionary of reference sentences (id, sentence)
    hypo, dictionary of hypothesis sentences (id, sentence)
    score, dictionary of scores
    """
    scorers = [
        (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
        (Meteor(),"METEOR"),
        (Rouge(), "ROUGE_L"),
        (Cider(), "CIDEr")
    ]
    final_scores = {}
    for scorer, method in scorers:
        score, scores = scorer.compute_score(ref, hypo)
        if type(score) == list:
            for m, s in zip(method, score):
                final_scores[m] = s
        else:
            final_scores[method] = score
    return final_scores 
開發者ID:hobincar,項目名稱:RecNet,代碼行數:23,代碼來源:utils.py

示例2: score_all

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def score_all(ref, hypo):
    scorers = [
        (Bleu(4),["Bleu_1","Bleu_2","Bleu_3","Bleu_4"]),
        (Meteor(),"METEOR"),
        (Rouge(),"ROUGE_L"),
        (Cider(),"CIDEr")
    ]
    final_scores = {}
    for scorer,method in scorers:
        score,scores = scorer.compute_score(ref,hypo)
        if type(score)==list:
            for m,s in zip(method,score):
                final_scores[m] = s
        else:
            final_scores[method] = score

    return final_scores 
開發者ID:weili-ict,項目名稱:SelfCriticalSequenceTraining-tensorflow,代碼行數:19,代碼來源:bleu.py

示例3: score

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def score(ref, hypo):
    """
    ref, dictionary of reference sentences (id, sentence)
    hypo, dictionary of hypothesis sentences (id, sentence)
    score, dictionary of scores
    """
    scorers = [
        (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
        (Meteor(),"METEOR"),
        (Rouge(), "ROUGE_L"),
        (Cider(), "CIDEr")
    ]
    final_scores = {}
    for scorer, method in scorers:
        score, scores = scorer.compute_score(ref, hypo)
        if type(score) == list:
            for m, s in zip(method, score):
                final_scores[m] = s
        else:
            final_scores[method] = score
    return final_scores 
開發者ID:WingsBrokenAngel,項目名稱:Semantics-AssistedVideoCaptioning,代碼行數:23,代碼來源:train_model.py

示例4: test

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def test(model, dataloader, args):
    scorer = Bleu(4)
    m_scorer = Meteor()
    r_scorer = Rouge()
    hyp = []
    ref = []
    model.eval()
    gold_file = open('tmp_gold.txt', 'w')
    pred_file = open('tmp_pred.txt', 'w')
    with tqdm(dataloader, desc='Test ',  mininterval=1) as tq:
        for batch in tq:
            with torch.no_grad():
                seq = model(batch, beam_size=args.beam_size)
            r = write_txt(batch, batch['tgt_text'], gold_file, args)
            h = write_txt(batch, seq, pred_file, args)
            hyp.extend(h)
            ref.extend(r)
    hyp = dict(zip(range(len(hyp)), hyp))
    ref = dict(zip(range(len(ref)), ref))
    print(hyp[0], ref[0])
    print('BLEU INP', len(hyp), len(ref))
    print('BLEU', scorer.compute_score(ref, hyp)[0])
    print('METEOR', m_scorer.compute_score(ref, hyp)[0])
    print('ROUGE_L', r_scorer.compute_score(ref, hyp)[0])
    gold_file.close()
    pred_file.close() 
開發者ID:dmlc,項目名稱:dgl,代碼行數:28,代碼來源:train.py

示例5: __init__

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def __init__(self):
        self.scorers = [
            (Bleu(4),  ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
            # (Meteor(), "METEOR"),
            (Rouge(), "ROUGE_L")
        ]#,        (Cider(), "CIDEr") 
開發者ID:EagleW,項目名稱:Describing_a_Knowledge_Base,代碼行數:8,代碼來源:eval.py

示例6: __init__

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def __init__(self):
        self.scorers = [
            (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
            (Meteor(), "METEOR"),
            (Rouge(), "ROUGE_L")
        ]#,        (Cider(), "CIDEr") 
開發者ID:EagleW,項目名稱:Describing_a_Knowledge_Base,代碼行數:8,代碼來源:eval_final.py

示例7: get_dcc_scores

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def get_dcc_scores(self):

    imgIds = self.params['image_id']
    # imgIds = self.coco.getImgIds()
    gts = {}
    res = {}
    for imgId in imgIds:
        gts[imgId] = self.coco.imgToAnns[imgId]
        res[imgId] = self.cocoRes.imgToAnns[imgId]

    tokenizer = PTBTokenizer()
    gts = tokenizer.tokenize(gts)
    res = tokenizer.tokenize(res)
    scorers = [
        (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
        (Meteor(), "METEOR"),
        (Rouge(), "ROUGE_L"),
        (Cider(df='noc_test_freq'), "CIDEr"),
        (Spice(), "SPICE")
    ]
    score_dict = {}
    for scorer, method in scorers:
      print('computing %s score...' % (scorer.method()))
      score, scores = scorer.compute_score(gts, res)
      if type(method) == list:
        for sc, scs, m in zip(score, scores, method):
          score_dict[m] = sc
          print("%s: %0.3f" % (m, sc))
      else:
        score_dict[method] = score
        print("%s: %0.3f" % (method, score))

    return score_dict 
開發者ID:jiasenlu,項目名稱:NeuralBabyTalk,代碼行數:35,代碼來源:coco_eval.py

示例8: __init__

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def __init__(self):
        implementation = meteor.Meteor()
        super(METEOR, self).__init__('meteor', implementation) 
開發者ID:danieljl,項目名稱:keras-image-captioning,代碼行數:5,代碼來源:metrics.py

示例9: __init__

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def __init__(self, ground_truth_filenames=None, prediction_filename=None,
                 tious=None, max_proposals=1000,
                 prediction_fields=PREDICTION_FIELDS, verbose=False):
        # Check that the gt and submission files exist and load them
        if len(tious) == 0:
            raise IOError('Please input a valid tIoU.')
        if not ground_truth_filenames:
            raise IOError('Please input a valid ground truth file.')
        if not prediction_filename:
            raise IOError('Please input a valid prediction file.')

        self.verbose = verbose
        self.tious = tious
        self.max_proposals = max_proposals
        self.pred_fields = prediction_fields
        self.ground_truths = self.import_ground_truths(ground_truth_filenames)
        self.prediction = self.import_prediction(prediction_filename)
        self.tokenizer = PTBTokenizer()

        # Set up scorers, if not verbose, we only use the one we're
        # testing on: METEOR
        if self.verbose:
            self.scorers = [
                (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
                (Meteor(),"METEOR"),
                (Rouge(), "ROUGE_L"),
                (Cider(), "CIDEr")
            ]
        else:
            self.scorers = [(Meteor(), "METEOR")] 
開發者ID:JaywongWang,項目名稱:DenseVideoCaptioning,代碼行數:32,代碼來源:evaluate_old.py

示例10: CocoScore

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def CocoScore(ref, hyp, metrics_list=None, language='en'):
    """
    Obtains the COCO scores from the references and hypotheses.

    :param ref: Dictionary of reference sentences (id, sentence)
    :param hyp: Dictionary of hypothesis sentences (id, sentence)
    :param metrics_list: List of metrics to evaluate on
    :param language: Language of the sentences (for METEOR)
    :return: dictionary of scores
    """
    if metrics_list is None:
        metrics_list = ['bleu', 'ter', 'meteor', 'rouge_l', 'cider']

    metrics_list = map(lambda x: x.lower(), metrics_list)
    scorers = []
    if 'bleu' in metrics_list:
        scorers.append((Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]))
    if 'meteor' in metrics_list:
        scorers.append((Meteor(language), "METEOR"))
    if 'ter' in metrics_list:
        scorers.append((Ter(), "TER"))
    if 'rouge_l' in metrics_list or 'rouge' in metrics_list:
        scorers.append((Rouge(), "ROUGE_L"))
    if 'cider' in metrics_list:
        scorers.append((Cider(), "CIDEr"))

    final_scores = {}
    for scorer, method in scorers:
        score, _ = scorer.compute_score(ref, hyp)
        if isinstance(score, list):
            for m, s in zip(method, score):
                final_scores[m] = s
        else:
            final_scores[method] = score
    return final_scores 
開發者ID:sheffieldnlp,項目名稱:deepQuest,代碼行數:37,代碼來源:evaluate_from_file.py

示例11: score

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def score(self, GT, RES, IDs):
        self.eval = {}
        self.imgToEval = {}
        gts = {}
        res = {}
        for ID in IDs:
            #            print ID
            gts[ID] = GT[ID]
            res[ID] = RES[ID]
        print('tokenization...')
        tokenizer = PTBTokenizer()
        gts = tokenizer.tokenize(gts)
        res = tokenizer.tokenize(res)

        # =================================================
        # Set up scorers
        # =================================================
        print('setting up scorers...')
        scorers = [
            (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
            (Meteor(),"METEOR"),
            (Rouge(), "ROUGE_L"),
            (Cider(), "CIDEr"),
            #(Spice(), "SPICE")
        ]

        # =================================================
        # Compute scores
        # =================================================
        eval = {}
        for scorer, method in scorers:
            print('computing %s score...' % (scorer.method()))
            score, scores = scorer.compute_score(gts, res)
            if type(method) == list:
                for sc, scs, m in zip(score, scores, method):
                    self.setEval(sc, m)
                    self.setImgToEvalImgs(scs, IDs, m)
                    print("%s: %0.3f" % (m, sc))
            else:
                self.setEval(score, method)
                self.setImgToEvalImgs(scores, IDs, method)
                print("%s: %0.3f" % (method, score))

        # for metric, score in self.eval.items():
        #    print '%s: %.3f'%(metric, score)
        return self.eval 
開發者ID:xiadingZ,項目名稱:video-caption-openNMT.pytorch,代碼行數:48,代碼來源:cocoeval.py

示例12: score

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def score(self, GT, RES, IDs):
        self.eval = {}
        self.imgToEval = {}
        gts = {}
        res = {}
        for ID in IDs:
            gts[ID] = GT[ID]
            res[ID] = RES[ID]
        print 'tokenization...'
        tokenizer = PTBTokenizer()
        gts  = tokenizer.tokenize(gts)
        res = tokenizer.tokenize(res)

        # =================================================
        # Set up scorers
        # =================================================
        print 'setting up scorers...'
        scorers = [
            (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
            (Meteor(),"METEOR"),
            (Rouge(), "ROUGE_L"),
            (Cider(), "CIDEr")
        ]

        # =================================================
        # Compute scores
        # =================================================
        eval = {}
        for scorer, method in scorers:
            print 'computing %s score...'%(scorer.method())
            score, scores = scorer.compute_score(gts, res)
            if type(method) == list:
                for sc, scs, m in zip(score, scores, method):
                    self.setEval(sc, m)
                    self.setImgToEvalImgs(scs, IDs, m)
                    #print "%s: %0.3f"%(m, sc)
            else:
                self.setEval(score, method)
                self.setImgToEvalImgs(scores, IDs, method)
                #print "%s: %0.3f"%(method, score)
                
        for metric, score in self.eval.items():
            print '%s: %.3f'%(metric, score)
        return self.eval 
開發者ID:VisionLearningGroup,項目名稱:caption-guided-saliency,代碼行數:46,代碼來源:cocoeval.py

示例13: score

# 需要導入模塊: from pycocoevalcap.meteor import meteor [as 別名]
# 或者: from pycocoevalcap.meteor.meteor import Meteor [as 別名]
def score(self, GT, RES, IDs):
        # edited by rgh
        #self.eval = {}
        self.eval = OrderedDict()
        self.imgToEval = {}
        gts = {}
        res = {}
        for ID in IDs:
            #            print ID
            gts[ID] = GT[ID]
            res[ID] = RES[ID]
        print('tokenization...')
        tokenizer = PTBTokenizer()
        gts = tokenizer.tokenize(gts)
        res = tokenizer.tokenize(res)

        # =================================================
        # Set up scorers
        # =================================================
        print('setting up scorers...')
        # edited by rgh
        # scorers = [
        #     (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
        #     (Meteor(),"METEOR"),
        #     (Rouge(), "ROUGE_L"),
        #     (Cider(), "CIDEr"),
        #     #(Spice(), "SPICE")
        # ]
        scorers = [
            (Bleu(4), ["Bleu_1", "Bleu_2", "Bleu_3", "Bleu_4"]),
            (Meteor(), "METEOR"),
            (Cider(), "CIDEr"),
            (Rouge(), "ROUGE_L"),
            # (Spice(), "SPICE")
        ]

        # =================================================
        # Compute scores
        # =================================================
        eval = {}
        for scorer, method in scorers:
            print('computing %s score...' % (scorer.method()))
            score, scores = scorer.compute_score(gts, res)
            if type(method) == list:
                # added by rgh
                # for sc, scs, m in zip(score, scores, method):
                #     self.setEval(sc, m)
                #     self.setImgToEvalImgs(scs, IDs, m)
                #     print("%s: %0.3f" % (m, sc))
                self.setEval("%.4f" % score[-1], method[-1])
                self.setImgToEvalImgs(scores[-1], IDs, method[-1])
                print("%s: %0.4f" % (method[-1], score[-1]))
            else:
                self.setEval("%.4f" % score, method)
                self.setImgToEvalImgs(scores, IDs, method)
                print("%s: %0.4f" % (method, score))

        # for metric, score in self.eval.items():
        #    print '%s: %.3f'%(metric, score)
        return self.eval 
開發者ID:Sundrops,項目名稱:video-caption.pytorch,代碼行數:62,代碼來源:cocoeval.py


注:本文中的pycocoevalcap.meteor.meteor.Meteor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。