-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaudio_type_analysis.py
86 lines (70 loc) · 2.81 KB
/
audio_type_analysis.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
83
import json
import os
AMT_testset = json.load(open('data/AMT_test_set.json', 'r'))
AMT_trainset = json.load(open('data/greatesthit_train_2.00.json', 'r'))
AMT_validset = json.load(open('data/greatesthit_val_2.00.json', 'r'))
greatest_testset = json.load(open('data/greatesthit_test_2.00.json', 'r'))
record_dir = 'data/greatesthit/greatesthit_processed'
match_dict = {}
type_dict = {}
overall_cnt = {True: 0, False: 0}
def process_action(name, st):
record_path = os.path.join(record_dir, name, 'hit_record.json')
record = json.load(open(record_path, 'r'))
action_cnt = {}
for (t, action) in record:
if t >= st and t <= st + 2:
_, act = action.split(' ')
if act not in action_cnt.keys():
action_cnt[act] = 0
action_cnt[act] += 1
return action_cnt
def process_type(name, st, drop_none=False):
record_path = os.path.join(record_dir, name, 'hit_record.json')
record = json.load(open(record_path, 'r'))
action_cnt = {}
for (t, action) in record:
if 'None' in action:
continue
if t >= st and t <= st + 2:
if action not in action_cnt.keys():
action_cnt[action] = 0
action_cnt[action] += 1
return action_cnt
def check_match(cnt1, cnt2):
type1 = list(cnt1.keys())
if 'None' in type1:
type1.remove('None')
type2 = list(cnt2.keys())
if 'None' in type2:
type2.remove('None')
for t in type1:
if t not in type2:
return False
for t in type2:
if t not in type1:
return False
return True
if __name__ == '__main__':
if not os.path.exists('data/AMT_test_set_match_dict.json'):
for target in AMT_testset:
target_name, start_time = target.split('_')
target_action_cnt = process_action(target_name, float(start_time))
match_dict[target] = {}
type_dict[target] = target_action_cnt
for condition in AMT_testset[target]:
cond_name, start_time = condition.split('_')
cond_action_cnt = process_action(cond_name, float(start_time))
match_dict[target][condition] = check_match(target_action_cnt, cond_action_cnt)
overall_cnt[match_dict[target][condition]] += 1
type_dict[condition] = cond_action_cnt
json.dump(match_dict, open('data/AMT_test_set_match_dict.json', 'w'))
print(len(greatest_testset))
for video_idx in greatest_testset:
name, idx = video_idx.split('_')
time = float(idx) / 22050
action_cnt = process_type(name, time)
if len(action_cnt.keys()) == 1:
type_dict[video_idx] = list(action_cnt.keys())[0]
print(len(type_dict))
json.dump(type_dict, open('data/greatesthit_test_2.00_single_type_only.json', 'w'))