-
Notifications
You must be signed in to change notification settings - Fork 2
/
celeb_utils.py
82 lines (80 loc) · 2.51 KB
/
celeb_utils.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
71
72
73
74
75
76
77
78
79
80
81
82
import glob
import numpy as np
import os
import pdb
import random
def produce_txt_list():
videos = glob.glob('/data/fhongac/origDataset/Voxceleb2/vox2_train_frames/mp4/*/*/*')
train_num = 0
test_num = 0
trainfile = open('./celeb2/train_files.txt', 'w', encoding='UTF-8')
train = True
testfile = open('./celeb2/test_file.txt', 'w', encoding='UTF-8')
for v in videos:
print(v)
if train:
imgs = os.listdir(v)
num = len(imgs)
if num<=2:
continue
imglist = range(2,num)
choice = random.sample(imglist,int(num/3))
for ch in choice:
string = v+' '+str(ch)+'\n'
trainfile.write(string)
train_num+=1
else:
imgs = os.listdir(v)
num = len(imgs)
if num<=2:
continue
imglist = range(2,num)
choice = random.sample(imglist,int(num/3))
for ch in choice:
string = v+' '+str(ch)+'\n'
testfile.write(string)
test_num+=1
if test_num>1000:
testfile.close()
exit(0)
trainfile.close()
def produce_txt_list_celeb1():
train_num = 0
test_num = 0
train = True
if train:
videos = glob.glob('/data/fhongac/origDataset/vox1_frames/train/*')
trainfile = open('./celeb1/train_files.txt', 'w', encoding='UTF-8')
else:
videos = glob.glob('/data/fhongac/origDataset/vox1_frames/test/*')
testfile = open('./celeb1/val_files.txt', 'w', encoding='UTF-8')
for v in videos:
print(v)
if train:
imgs = os.listdir(v)
num = len(imgs)
if num<=2:
continue
imglist = range(2,num-1)
choice = random.sample(imglist,int(num/3))
for ch in choice:
string = v+' '+str(ch)+'\n'
trainfile.write(string)
train_num+=1
else:
imgs = os.listdir(v)
num = len(imgs)
if num<=2:
continue
imglist = range(2,num-1)
choice = random.sample(imglist,int(num/3))
for ch in choice:
string = v+' '+str(ch)+'\n'
testfile.write(string)
test_num+=1
if test_num>1000:
testfile.close()
exit(0)
trainfile.close()
if __name__ == '__main__':
produce_txt_list_celeb1()