-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_csv_fakeavceleb.py
77 lines (60 loc) · 3.37 KB
/
write_csv_fakeavceleb.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
import argparse, os, csv, random
def write_list(data_list, path, ):
with open(path, 'w') as f:
writer = csv.writer(f, delimiter=',')
for row in data_list:
print(row)
if row: writer.writerow(row)
print('split saved to %s' % path)
parser = argparse.ArgumentParser(description="WriteCSV")
parser.add_argument('--out_dir', type=str, default='', help='Output direcotry')
opt = parser.parse_args();
setattr(opt, 'real_dir_test', os.path.join(opt.out_dir, 'FakeAVCeleb_v1.2_inDFDCformat', 'test', 'pytmp', 'real'))
setattr(opt, 'fake_dir_test', os.path.join(opt.out_dir, 'FakeAVCeleb_v1.2_inDFDCformat', 'test', 'pytmp', 'fake'))
setattr(opt, 'real_dir_train', os.path.join(opt.out_dir, 'FakeAVCeleb_v1.2_inDFDCformat', 'train', 'pytmp', 'real'))
setattr(opt, 'fake_dir_train', os.path.join(opt.out_dir, 'FakeAVCeleb_v1.2_inDFDCformat', 'train', 'pytmp', 'fake'))
setattr(opt, 'csv_root', os.path.join(opt.out_dir))
realListTest = []
fakeListTest = []
realListTrain = []
fakeListTrain = []
train_set = []
test_set = []
for directory in os.listdir(opt.real_dir_train):
realListTrain.append(directory)
for directory in os.listdir(opt.fake_dir_train):
fakeListTrain.append(directory)
for directory in os.listdir(opt.real_dir_test):
realListTest.append(directory)
for directory in os.listdir(opt.fake_dir_test):
fakeListTest.append(directory)
random.shuffle(realListTrain)
random.shuffle(fakeListTrain)
random.shuffle(realListTest)
random.shuffle(fakeListTest)
for i in range(len(fakeListTrain)):
for file in os.listdir(os.path.join(opt.fake_dir_train, fakeListTrain[i])):
if os.path.isdir(os.path.join(opt.fake_dir_train, fakeListTrain[i], file)):
audio_file = file + '.wav'
train_set.append([os.path.join(opt.fake_dir_train, fakeListTrain[i], file),
os.path.join(opt.fake_dir_train, fakeListTrain[i], audio_file), 'fake'])
for i in range(len(realListTrain)):
for file in os.listdir(os.path.join(opt.real_dir_train, realListTrain[i])):
if os.path.isdir(os.path.join(opt.real_dir_train, realListTrain[i], file)):
audio_file = file + '.wav'
train_set.append([os.path.join(opt.real_dir_train, realListTrain[i], file),
os.path.join(opt.real_dir_train, realListTrain[i], audio_file), 'real'])
for i in range(len(fakeListTest)):
for file in os.listdir(os.path.join(opt.fake_dir_test_balance, fakeListTest[i])):
if os.path.isdir(os.path.join(opt.fake_dir_test_balance, fakeListTest[i], file)):
audio_file = file + '.wav'
test_set.append([os.path.join(opt.fake_dir_test_balance, fakeListTest[i], file),
os.path.join(opt.fake_dir_test_balance, fakeListTest[i], audio_file), 'fake'])
for i in range(len(realListTest)):
for file in os.listdir(os.path.join(opt.real_dir_test_balance, realListTest[i])):
if os.path.isdir(os.path.join(opt.real_dir_test_balance, realListTest[i], file)):
audio_file = file + '.wav'
test_set.append([os.path.join(opt.real_dir_test_balance, realListTest[i], file),
os.path.join(opt.real_dir_test_balance, realListTest[i], audio_file), 'real'])
write_list(train_set, os.path.join(opt.csv_root, 'train_fakeavceleb_split.csv'))
write_list(test_set, os.path.join(opt.csv_root, 'test_fakeavceleb_split.csv'))