-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset_statistics.py
117 lines (91 loc) · 3.67 KB
/
dataset_statistics.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 30 09:45:06 2024
@author: nadya
"""
import json, argparse
import os
import statistics as s
################################## Tracking statistics ################################################################
annot_dir = "data/annotations/tracking_annotations/kitti"
annotations = os.listdir(annot_dir)
vehciles_tracklets = 0
pedestrian_tracklets = 0
cyclist_tracklets = 0
motorbike_tracklets = 0
tracklets_length = []
vehicles =set([
'Car',
'Large_vehicle',
'Medium_vehicle',
'Bus',
'Emergency_vehicle',
'Small_motorised_vehicle'])
for ann in annotations:
ann_file = os.path.join(annot_dir, ann)
tracklets = {}
with open(ann_file, 'r') as file:
for line in file:
parts = line.strip().split()
frame_id = parts[0]
track_id = parts[1]
obj_class = parts[2]
if track_id not in tracklets:
tracklets[track_id] = {'obj_class':obj_class, 'frames':[]}
tracklets[track_id]['frames'].append(frame_id)
# count objects and compute mean trakcing length
for k,v in tracklets.items():
if v['obj_class'] in vehicles: vehciles_tracklets += 1
elif v['obj_class'] == "Pedestrian": pedestrian_tracklets += 1
elif v['obj_class'] == "Cyclist": cyclist_tracklets += 1
elif v['obj_class'] == "Motorbike": motorbike_tracklets += 1
tracklets_length.append(len(v['frames']))
print('Tracking Benchmark Statistics:')
print(f'Total number of vehciles: {vehciles_tracklets}')
print(f'Total number of pedestrians: {pedestrian_tracklets}')
print(f'Total number of motorbikes: {motorbike_tracklets}')
print(f'Total number of cyclists: {cyclist_tracklets}')
print(f'Mean tracklet length: {s.mean(tracklets_length)} \n')
#######################################################################################################################
################################## Prediction statistics ################################################################
annot_dir = "data/annotations/prediction_annotations"
annotations = os.listdir(annot_dir)
vehciles_pred = 0
pedestrian_pred = 0
total = 0
vehicles =set([
'Car',
'Large_vehicle',
'Medium_vehicle',
'Bus',
'Emergency_vehicle',
'Small_motorised_vehicle'])
for ann in annotations:
ann_file = os.path.join(annot_dir, ann)
tracklets = {}
with open(ann_file, 'r') as file:
data = json.load(file)
for k,v in data.items():
if v['class'] == 'Pedestrian':
pedestrian_pred += 1
elif v['class'] in vehicles:
vehciles_pred += 1
total += 1
print('Prediction Benchmark Statistics:')
print(f'Total number of agents: {total}')
print(f'Total number of vehciles: {vehciles_pred}')
print(f'Total number of pedestrians: {pedestrian_pred} \n')
#######################################################################################################################
################################## Intention statistics ################################################################
annot_dir = "data/annotations/intention_annotations"
annotations = os.listdir(annot_dir)
total = 0
for ann in annotations:
ann_file = os.path.join(annot_dir, ann)
with open(ann_file, 'r') as file:
data = json.load(file)
total += len(data.keys())
print('Intention Benchmark Statistics:')
print(f'Total number of sequences: {total} \n')
#######################################################################################################################