-
Notifications
You must be signed in to change notification settings - Fork 1
/
split_setting3.py
61 lines (54 loc) · 1.25 KB
/
split_setting3.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
53
54
55
56
57
58
59
60
61
import os,random
imgdir = './data/morph/' ## dir for data
def splitbw(race,gender):
b_w = [im+' '+im[-7:-5]+'\n' for im in os.listdir(imgdir) if ('.jpg' in im and race in im and gender in im)]
b_w.sort()
random.seed(1)
random.shuffle(b_w)
return b_w
other = [im+' '+im[-7:-5]+'\n' for im in os.listdir(imgdir) if ('.jpg' in im and 'B' not in im and 'W' not in im)]
s=[]
s2=[]
race = 'B'
gender = 'F'
b_f = splitbw(race, gender)
black_num = len(b_f)
s+=b_f[0:1285]
s2+=b_f[1285:1285*2]
other += b_f[1285*2::]
race = 'W'
gender = 'F'
w_f = splitbw(race, gender)
white_num = len(w_f)
s+=w_f[0:1285]
s2+=w_f[1285:1285*2]
other += w_f[1285*2::]
race = 'B'
gender = 'M'
b_m = splitbw(race, gender)
black_num += len(b_m)
s+=b_m[0:3980]
s2+=b_m[3980:3980*2]
other += b_m[3980*2::]
race = 'W'
gender = 'M'
w_m = splitbw(race, gender)
white_num = len(w_m)
s+=w_m[0:3980]
s2+=w_m[3980:3980*2]
other += w_m[3980*2::]
print black_num
print white_num
##file to write list
stxt = 'train1.txt'
s2txt = 'train2.txt'
other1txt = 'test1.txt'
other2txt = 'test2.txt'
with open(stxt,'w') as f:
f.writelines(s)
with open(s2txt,'w') as f:
f.writelines(s2)
with open(other1txt,'w') as f:
f.writelines(s2+other)
with open(other2txt,'w') as f:
f.writelines(s+other)