forked from hx173149/C3D-tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpose_list.py
67 lines (49 loc) · 1.93 KB
/
pose_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
import json
import os
import activities
import argparse
# Collects all the json files from the folder and assign a
# unique ID for each one
def generate_activity_list(json_dir):
files = os.listdir(json_dir)
activities_list = []
for f in files:
with open(json_dir + f) as file:
Json_dict = json.load(file)
for video in list(Json_dict.keys()):
for activity in list(Json_dict[video]):
if (activity['label'] not in activities_list):
activities_list.append(activity['label'])
activities_ids = dict(map(reversed, enumerate(activities_list)))
return activities_ids
# Show the frequency of each activity
def show_activities_frequency(json_dir):
files = os.listdir(json_dir)
activities_dic = {}
activities_list = activities.activities
for f in files:
with open(json_dir + f) as file:
Json_dict = json.load(file)
for video in list(Json_dict.keys()):
for activity in list(Json_dict[video]):
if activity['label'] in activities_list:
if (activity['label'] not in activities_dic):
activities_dic[activity['label']] = 0
else:
activities_dic[activity['label']] += 1
return activities_dic
# Main function
def main(json):
print('\nTotal list of activities\n')
activities = generate_activity_list(json)
for i in activities:
print(i)
print('\nFrequency of each activity chosen to training\n')
activities = show_activities_frequency(json)
for i in activities:
print(i, ': ', activities[i])
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Print ')
parser.add_argument('--json', dest='json', type=str, default='json/', help='path of the json files')
args = parser.parse_args()
main(args.json)