-
Notifications
You must be signed in to change notification settings - Fork 7
/
get_test.py
44 lines (38 loc) · 1.38 KB
/
get_test.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
32
33
34
35
36
37
38
39
40
41
42
43
44
import json
import numpy as np
from torch.utils.data import Dataset
import csv
import sys
csv.field_size_limit(sys.maxsize)
FIELDNAMES = ["img_id", "img_h", "img_w", "objects_id", "objects_conf",
"attrs_id", "attrs_conf", "num_boxes", "boxes", "features"]
id_file = 'data/vg_gqa_imgfeat/vg_gqa_obj36.tsv'
coco_file = 'data/mscoco_imgfeat/test2015_obj64.tsv'
outfile = 'data/vg_gqa_imgfeat/vg_gqa_obj64.tsv'
all_id = []
all_id_number = []
coco_data = []
with open(coco_file) as f:
coco_reader = csv.DictReader(f, FIELDNAMES, delimiter="\t")
for i, item in enumerate(coco_reader):
if i % 1000 == 0:
print(i)
coco_data.append(item)
all_id_number.append(int(item['img_id'][14:]))
N = 0
with open(outfile, 'a+') as tsvfile:
writer = csv.DictWriter(tsvfile, delimiter='\t', fieldnames=FIELDNAMES)
with open(id_file) as f:
id_reader = csv.DictReader(f, FIELDNAMES, delimiter="\t")
for i, item in enumerate(id_reader):
if i % 1000 == 0:
print(i)
nlvr2_id = item['img_id']
if nlvr2_id[0] == 'n':
N+=1
nlvr2_id_number=int(nlvr2_id[1:])
index_id = all_id_number.index(nlvr2_id_number)
coco_datum=coco_data[index_id]
coco_datum['img_id'] = item['img_id']
writer.writerow(coco_datum)
print(N)