-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmake_turk.py
42 lines (32 loc) · 1.17 KB
/
make_turk.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
#!/usr/bin/env python2
import sys
import numpy as np
results_file = sys.argv[1]
dest_file = ".".join(results_file.split(".")[:-1]) + ".turk.csv"
records = []
with open(results_file) as results_f:
results_f.readline()
for line in results_f:
example_id, tgt, dis, _, _, _, _, caption = line.strip().split(",")
if "abstract" in results_file:
tgt = "http://fromage.banatao.berkeley.edu/pragma/data/abstract/RenderedScenes/Scene%s.png" % tgt
dis = "http://fromage.banatao.berkeley.edu/pragma/data/abstract/RenderedScenes/Scene%s.png" % dis
elif "birds" in results_file:
assert False
if np.random.random() < 0.5:
img1 = tgt
img2 = dis
tgt_id = 1
else:
img1 = dis
img2 = tgt
tgt_id = 2
caption = caption.replace(",", " ")
parts = [example_id, caption, img1, img2, tgt_id]
records.append(parts)
np.random.shuffle(records)
print len(records)
with open(dest_file, "w") as dest_f:
print >>dest_f, "id,caption,img1,img2,tgt_id"
for parts in records:
print >>dest_f, ",".join([str(s) for s in parts])