-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_rand_input_txt.py
54 lines (43 loc) · 1.12 KB
/
create_rand_input_txt.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
45
46
47
48
49
50
51
52
import fileinput
import random
# Create the text files containing training and test image
# names and their classes.
TRAIN_NUM = 10000
VAL_NUM = 1000
# The average score is 5.39. We take 5.5 as the threshold
GOOD_THRES = 5.5
def get_avg(split_line):
print line
print cells
sum = 0;
count = 0;
for i in range(2, 12):
sum += (i - 1) * float(split_line[i])
count += float(split_line[i])
avg = sum / count
return avg
f_train = open("input_txt/train_tmp.txt", "w")
f_test = open("input_txt/val_tmp.txt", "w")
f_in = open("AVA_dataset/AVA.txt");
lines = f_in.readlines();
lines = lines[:30000]
random.shuffle(lines)
print "Lines has "+str(len(lines))
for line in lines[:TRAIN_NUM]:
cells = line.split()
idx = int(cells[0])
avg = get_avg(cells)
isGood = 0;
if(avg >= GOOD_THRES):
isGood = 1;
f_train.write(cells[0]+"-"+cells[1]+".jpg");
f_train.write(" "+str(isGood)+"\n");
for line in lines[TRAIN_NUM:TRAIN_NUM+VAL_NUM]:
cells = line.split()
idx = int(cells[0])
avg = get_avg(cells)
isGood = 0;
if(avg >= GOOD_THRES):
isGood = 1;
f_test.write(cells[0]+"-"+cells[1]+".jpg");
f_test.write(" "+str(isGood)+"\n");