forked from 610265158/face_landmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_list.py
executable file
·70 lines (53 loc) · 1.78 KB
/
make_list.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
62
63
64
65
66
67
68
69
70
import os
import random
def GetFileList(dir, fileList):
newDir = dir
if os.path.isfile(dir):
fileList.append(dir)
elif os.path.isdir(dir):
for s in os.listdir(dir):
# if s == "pts":
# continue
newDir=os.path.join(dir,s)
GetFileList(newDir, fileList)
return fileList
data_dir='PUB' ########points to your director
pic_list=[]
GetFileList(data_dir,pic_list)
pic_list=[x for x in pic_list if '.jpg' in x or 'png' in x or 'jpeg' in x ]
random.shuffle(pic_list)
ratio=0.9
train_list=pic_list[:int(ratio*len(pic_list))]
val_list=pic_list[int(ratio*len(pic_list)):]
# train_list=[x for x in pic_list if '300W/' not in x]
# val_list=[x for x in pic_list if '300W/' in x]
train_file=open('./train.txt',mode='w')
val_file=open('./val.txt',mode='w')
for pic in train_list:
tmp_str=pic+'|'
pts=pic.rsplit('.',1)[0]+'.pts'
if os.access(pic,os.F_OK) and os.access(pts,os.F_OK):
try:
with open(pts) as p_f:
labels=p_f.readlines()[3:-1]
for _one_p in labels:
xy = _one_p.rstrip().split(' ')
tmp_str = tmp_str + xy[0] + ' ' + xy[1] + ' '
tmp_str = tmp_str + '\n'
train_file.write(tmp_str)
except:
print(pic)
for pic in val_list:
tmp_str=pic+'|'
pts=pic.rsplit('.',1)[0]+'.pts'
if os.access(pic,os.F_OK) and os.access(pts,os.F_OK):
try:
with open(pts) as p_f:
labels=p_f.readlines()[3:-1]
for _one_p in labels:
xy = _one_p.rstrip().split(' ')
tmp_str = tmp_str + xy[0] + ' ' + xy[1] + ' '
tmp_str = tmp_str + '\n'
val_file.write(tmp_str)
except:
print(pic)