forked from ramavedantam/cider
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathloadData.py
31 lines (22 loc) · 883 Bytes
/
loadData.py
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
"""
Load the reference and candidate json files, which are to be evaluated using CIDEr.
Reference file: list of dict('image_id': image_id, 'caption': caption).
Candidate file: list of dict('image_id': image_id, 'caption': caption).
"""
import json
import os
from collections import defaultdict
class LoadData():
def __init__(self, path):
self.pathToData = path
def readJson(self, refname, candname):
path_to_ref_file = os.path.join(self.pathToData, refname)
path_to_cand_file = os.path.join(self.pathToData, candname)
ref_list = json.loads(open(path_to_ref_file, 'r').read())
cand_list = json.loads(open(path_to_cand_file, 'r').read())
gts = defaultdict(list)
res = []
for l in ref_list:
gts[l['image_id']].append({"caption": l['caption']})
res = cand_list;
return gts, res