In [15]:
# demo script for running CIDEr
from pydataformat.loadData import LoadData
import pdb
import json
from pyciderevalcap.eval import CIDErEvalCap as ciderEval

pathToData = 'data/'

refName = 'pascal50S.json'
candName = 'pascal_candsB.json'

result_file = 'results.json'
df_mode = 'coco-val-df'

In [16]:
# load reference and candidate sentences
loadDat = LoadData(pathToData)
gts, res = loadDat.readJson(refName, candName)

In [17]:
# calculate cider scores
scorer = ciderEval(gts, res, df_mode)
# scores: dict of list with key = metric and value = score given to each candidate
scores = scorer.evaluate()


tokenization...
tokenized refs
tokenized cands
setting up scorers...
computing CIDEr score...
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-17-7a605a1240a5> in <module>()
      2 scorer = ciderEval(gts, res, df_mode)
      3 # scores: dict of list with key = metric and value = score given to each candidate
----> 4 scores = scorer.evaluate()

/Users/rama/Research/code/cider/pyciderevalcap/eval.py in evaluate(self)
     35         for scorer, method in scorers:
     36             print 'computing %s score...' % (scorer.method())
---> 37             score, scores = scorer.compute_score(self.gts, self.res)
     38             print "Mean %s score: %0.3f" % (method, score)
     39             metric_scores[method] = list(scores)

/Users/rama/Research/code/cider/pyciderevalcap/cider/cider.py in compute_score(self, gts, res)
     53             cider_scorer += (hypo[0], ref)
     54 
---> 55         (score, scores) = cider_scorer.compute_score(self._df)
     56 
     57         return score, scores

/Users/rama/Research/code/cider/pyciderevalcap/cider/cider_scorer.py in compute_score(self, df_mode, option, verbose)
    192             # import json for now and write the corresponding files
    193         else:
--> 194             self.document_frequency = pickle.load(open(os.path.join('data', df_mode + '.p'),'r'))
    195         # compute cider score
    196         score = self.compute_cider(df_mode)

/Users/rama/anaconda2/lib/python2.7/pickle.pyc in load(file)
   1382 
   1383 def load(file):
-> 1384     return Unpickler(file).load()
   1385 
   1386 def loads(str):

/Users/rama/anaconda2/lib/python2.7/pickle.pyc in load(self)
    862             while 1:
    863                 key = read(1)
--> 864                 dispatch[key](self)
    865         except _Stop, stopinst:
    866             return stopinst.value

/Users/rama/anaconda2/lib/python2.7/pickle.pyc in load_tuple(self)
    998 
    999     def load_tuple(self):
-> 1000         k = self.marker()
   1001         self.stack[k:] = [tuple(self.stack[k+1:])]
   1002     dispatch[TUPLE] = load_tuple

/Users/rama/anaconda2/lib/python2.7/pickle.pyc in marker(self)
    878         mark = self.mark
    879         k = len(stack)-1
--> 880         while stack[k] is not mark: k = k-1
    881         return k
    882 

KeyboardInterrupt: 

In [8]:
# scores['CIDEr'] contains CIDEr scores
# scores['CIDErD'] contains CIDEr-D scores

with open(result_file, 'w') as outfile:
    json.dump(scores, outfile)