Datasets:

Modalities:
Image
Text
ArXiv:
License:
NightPro commited on
Commit
c2915d2
·
verified ·
1 Parent(s): 3383315

Upload DroneBird/toolkit/eval.py

Browse files
Files changed (1) hide show
  1. DroneBird/toolkit/eval.py +175 -0
DroneBird/toolkit/eval.py ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sklearn.metrics import mean_squared_error, mean_absolute_error
2
+ from scipy.io import loadmat
3
+ import os
4
+ import re
5
+
6
+ root_path = "."
7
+
8
+
9
+ def get_seq_class(seq, set):
10
+ backlight = [
11
+ "DJI_0021",
12
+ "DJI_0022",
13
+ "DJI_0032",
14
+ "DJI_0202",
15
+ "DJI_0339",
16
+ "DJI_0340",
17
+ "DJI_0463",
18
+ "DJI_0003",
19
+ ]
20
+
21
+ fly = [
22
+ "DJI_0177",
23
+ "DJI_0174",
24
+ "DJI_0022",
25
+ "DJI_0180",
26
+ "DJI_0181",
27
+ "DJI_0200",
28
+ "DJI_0544",
29
+ "DJI_0012",
30
+ "DJI_0178",
31
+ "DJI_0343",
32
+ "DJI_0185",
33
+ "DJI_0195",
34
+ "DJI_0996",
35
+ "DJI_0977",
36
+ "DJI_0945",
37
+ "DJI_0946",
38
+ "DJI_0091",
39
+ "DJI_0442",
40
+ "DJI_0466",
41
+ "DJI_0459",
42
+ "DJI_0464",
43
+ ]
44
+
45
+ angle_90 = [
46
+ "DJI_0179",
47
+ "DJI_0186",
48
+ "DJI_0189",
49
+ "DJI_0191",
50
+ "DJI_0196",
51
+ "DJI_0190",
52
+ "DJI_0070",
53
+ "DJI_0091",
54
+ ]
55
+
56
+ mid_size = [
57
+ "DJI_0012",
58
+ "DJI_0013",
59
+ "DJI_0014",
60
+ "DJI_0021",
61
+ "DJI_0022",
62
+ "DJI_0026",
63
+ "DJI_0028",
64
+ "DJI_0028",
65
+ "DJI_0030",
66
+ "DJI_0028",
67
+ "DJI_0030",
68
+ "DJI_0034",
69
+ "DJI_0200",
70
+ "DJI_0544",
71
+ "DJI_0463",
72
+ "DJI_0001",
73
+ "DJI_0149",
74
+ ]
75
+
76
+ light = "sunny"
77
+ bird = "stand"
78
+ angle = "60"
79
+ size = "small"
80
+ # resolution = '4k'
81
+ if seq in backlight:
82
+ light = "backlight"
83
+ if seq in fly:
84
+ bird = "fly"
85
+ if seq in angle_90:
86
+ angle = "90"
87
+ if seq in mid_size:
88
+ size = "mid"
89
+
90
+ count = "sparse"
91
+ loca = loadmat(
92
+ os.path.join(
93
+ root_path,
94
+ set,
95
+ "ground_truth",
96
+ "GT_img" + str(seq[-3:]) + "000.mat",
97
+ )
98
+ )["locations"]
99
+ if loca.shape[0] > 150:
100
+ count = "crowded"
101
+ return [light, angle, bird, size, count]
102
+
103
+
104
+ with open("./result.txt", "r") as f:
105
+ lines = f.readlines()
106
+ print(len(lines))
107
+
108
+ data = []
109
+ for line in lines:
110
+ match = re.match(
111
+ r"\d+: *err: *(\d+), *gt_count: *(\d+), *pred_count: *(\d+), *name: *(.+)",
112
+ # r'\d+: err: (\d+\.\d+), gt_count: (\d+\.\d+), pred_count: (\d+\.\d+), name: (.+)',
113
+ # r'vi: \d+, name: (.+), gt: (\d+\.\d+), pred: (\d+\.\d+), res: (\d+\.\d+)',
114
+ line,
115
+ )
116
+ if match:
117
+ error = float(match.group(1))
118
+ gt_count = float(match.group(2))
119
+ pred_count = float(match.group(3))
120
+ name = match.group(4)
121
+ data.append(
122
+ {
123
+ "error": error,
124
+ "gt_count": gt_count,
125
+ "pred_count": pred_count,
126
+ "name": name,
127
+ }
128
+ )
129
+ print(error, gt_count, pred_count, name)
130
+
131
+ print(len(data))
132
+
133
+
134
+ preds = []
135
+ gts = []
136
+ preds_hist = [[] for i in range(10)]
137
+ gts_hist = [[] for i in range(10)]
138
+ attri = [
139
+ "sunny",
140
+ "backlight",
141
+ "crowded",
142
+ "sparse",
143
+ "60",
144
+ "90",
145
+ "stand",
146
+ "fly",
147
+ "small",
148
+ "mid",
149
+ ]
150
+
151
+ for d in data:
152
+ name = d["name"]
153
+ error = d["error"]
154
+ gt_count = d["gt_count"]
155
+ pred_count = d["pred_count"]
156
+ seq = "DJI_" + str(int(name[3:6])).zfill(4)
157
+ cur_attris = get_seq_class(seq, "test")
158
+ preds.append(pred_count)
159
+ gts.append(gt_count)
160
+ for cur_attri in cur_attris:
161
+ preds_hist[attri.index(cur_attri)].append(pred_count)
162
+ gts_hist[attri.index(cur_attri)].append(gt_count)
163
+ test_log = "Test: MAE: {:.2f}, MSE: {:.2f}\n".format(
164
+ mean_absolute_error(gts, preds), mean_squared_error(gts, preds)
165
+ )
166
+ for i in range(10):
167
+ if len(preds_hist[i]) == 0:
168
+ continue
169
+ test_log_attri = "{}: MAE: {:.2f}, MSE: {:.2f}\n".format(
170
+ attri[i],
171
+ mean_absolute_error(gts_hist[i], preds_hist[i]),
172
+ mean_squared_error(gts_hist[i], preds_hist[i]),
173
+ )
174
+ test_log += test_log_attri
175
+ print(test_log)