-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.py
More file actions
70 lines (50 loc) · 1.44 KB
/
Copy pathscore.py
File metadata and controls
70 lines (50 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from config import *
from helper import *
from evaluation import *
from evaluation.spice.spice import Spice
import pickle
import sys
def run_score_on_file(filename):
with open(filename, "rb") as f:
dataset = pickle.load(f)
run_score(dataset)
def run_score(dataset):
# get spice score
sscore = run_score_spice(dataset)
# get bleu score
bleu = Bleu()
bscore = bleu.compute(dataset)
# get cider score
cider = Cider()
cscore = cider.compute(dataset)
# get rouge score
rouge = Rouge()
rscore = rouge.compute(dataset)
print("Scores")
print("BLEU: ", bscore)
print("CIDEr: ", cscore)
print("ROUGE: ", rscore)
print("SPICE: ", sscore)
def run_score_spice(dataset):
result_lst = {}
for id, item in enumerate(dataset):
result_lst["image_" + str(id)] = item
# fixed the hypothesis/caption wrong lableing
reference = { }
hypothesis = { }
no = 0
for filename in result_lst:
for ref in result_lst[filename]["reference"]:
reference[no] = [" ".join(ref)]
hypothesis[no] = [" ".join(result_lst[filename]["hypothesis"])]
no += 1
# get spice score
spice = Spice()
sscore = spice.compute_score(reference, hypothesis)
return sscore[0]
if __name__ == "__main__":
if len(sys.argv) >= 2:
# get filename
filename = sys.argv[1]
# open file
run_score_on_file(filename)