-
Notifications
You must be signed in to change notification settings - Fork 11
/
preprocess.py
64 lines (50 loc) · 2.3 KB
/
preprocess.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
import argparse
from tqdm import tqdm
import pickle
import dgcn
log = dgcn.utils.get_logger()
def split():
dgcn.utils.set_seed(args.seed)
video_ids, video_speakers, video_labels, video_text, \
video_audio, video_visual, video_sentence, trainVids, \
test_vids = pickle.load(open('data/iemocap/IEMOCAP_features.pkl', 'rb'), encoding='latin1')
train, dev, test = [], [], []
dev_size = int(len(trainVids) * 0.1)
train_vids, dev_vids = trainVids[dev_size:], trainVids[:dev_size]
for vid in tqdm(train_vids, desc="train"):
train.append(dgcn.Sample(vid, video_speakers[vid], video_labels[vid],
video_text[vid], video_audio[vid], video_visual[vid],
video_sentence[vid]))
for vid in tqdm(dev_vids, desc="dev"):
dev.append(dgcn.Sample(vid, video_speakers[vid], video_labels[vid],
video_text[vid], video_audio[vid], video_visual[vid],
video_sentence[vid]))
for vid in tqdm(test_vids, desc="test"):
test.append(dgcn.Sample(vid, video_speakers[vid], video_labels[vid],
video_text[vid], video_audio[vid], video_visual[vid],
video_sentence[vid]))
log.info("train vids:")
log.info(sorted(train_vids))
log.info("dev vids:")
log.info(sorted(dev_vids))
log.info("test vids:")
log.info(sorted(test_vids))
return train, dev, test
def main(args):
train, dev, test = split()
log.info("number of train samples: {}".format(len(train)))
log.info("number of dev samples: {}".format(len(dev)))
log.info("number of test samples: {}".format(len(test)))
data = {"train": train, "dev": dev, "test": test}
dgcn.utils.save_pkl(data, args.data)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="preprocess.py")
parser.add_argument("--data", type=str, required=True,
help="Path to data")
parser.add_argument("--dataset", type=str, required=True,
choices=["iemocap", "avec", "meld"],
help="Dataset name.")
parser.add_argument("--seed", type=int, default=24,
help="Random seed.")
args = parser.parse_args()
main(args)