Spaces:
Build error
Build error
Victoria Oberascher
commited on
Commit
·
329abf4
1
Parent(s):
a3751fe
fix error
Browse files- horizonmetrics.py +2 -245
horizonmetrics.py
CHANGED
@@ -17,7 +17,7 @@ import evaluate
|
|
17 |
import datasets
|
18 |
import numpy as np
|
19 |
|
20 |
-
|
21 |
|
22 |
# TODO: Add BibTeX citation
|
23 |
_CITATION = """\
|
@@ -60,247 +60,6 @@ BAD_WORDS_URL = "http://url/to/external/resource/bad_words.txt"
|
|
60 |
|
61 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION,
|
62 |
_KWARGS_DESCRIPTION)
|
63 |
-
# begin utils
|
64 |
-
def xy_points_to_slope_midpoint(xy_points):
|
65 |
-
"""
|
66 |
-
Given two points, return the slope and midpoint of the line
|
67 |
-
|
68 |
-
Args:
|
69 |
-
xy_points: list of two points, each point is a list of two elements
|
70 |
-
Points are in the form of [x, y], where x and y are normalized to [0, 1]
|
71 |
-
|
72 |
-
Returns:
|
73 |
-
slope: Slope of the line
|
74 |
-
midpoint : Midpoint is in the form of [x,y], and is also normalized to [0, 1]
|
75 |
-
"""
|
76 |
-
|
77 |
-
#x1, y1, x2, y2 = xy_points[0][0], xy_points[0][1], xy_points[1][
|
78 |
-
# 0], xy_points[1][1]
|
79 |
-
|
80 |
-
x1, y1, x2, y2 = xy_points[0], xy_points[1], xy_points[2], xy_points[3]
|
81 |
-
slope = (y2 - y1) / (x2 - x1)
|
82 |
-
|
83 |
-
midpoint_x = 0.5
|
84 |
-
midpoint_y = slope * (0.5 - x1) + y1
|
85 |
-
midpoint = [midpoint_x, midpoint_y]
|
86 |
-
return slope, midpoint
|
87 |
-
|
88 |
-
|
89 |
-
def calculate_horizon_error(annotated_horizon, proposed_horizon):
|
90 |
-
"""
|
91 |
-
Calculate the error between the annotated horizon and the proposed horizon
|
92 |
-
|
93 |
-
Args:
|
94 |
-
annotated_horizon: list of two points, each point is a list of two elements
|
95 |
-
Points are in the form of [x, y], where x and y are normalized to [0, 1]
|
96 |
-
proposed_horizon: list of two points, each point is a list of two elements
|
97 |
-
Points are in the form of [x, y], where x and y are normalized to [0, 1]
|
98 |
-
|
99 |
-
Returns:
|
100 |
-
slope_error: Error in the slope of the lines
|
101 |
-
midpoint_error: Error in the midpoint_y of the lines
|
102 |
-
"""
|
103 |
-
|
104 |
-
slope_annotated, midpoint_annotated = xy_points_to_slope_midpoint(
|
105 |
-
annotated_horizon)
|
106 |
-
slope_proposed, midpoint_proposed = xy_points_to_slope_midpoint(
|
107 |
-
proposed_horizon)
|
108 |
-
|
109 |
-
slope_error = abs(slope_annotated - slope_proposed)
|
110 |
-
midpoint_error = abs(midpoint_annotated[1] - midpoint_proposed[1])
|
111 |
-
|
112 |
-
return slope_error, midpoint_error
|
113 |
-
|
114 |
-
|
115 |
-
def calculate_horizon_error_across_sequence(slope_error_list,
|
116 |
-
midpoint_error_list,
|
117 |
-
slope_error_jump_threshold,
|
118 |
-
midpoint_error_jump_threshold):
|
119 |
-
"""
|
120 |
-
Calculate the error statistics across a sequence of frames
|
121 |
-
|
122 |
-
Args:
|
123 |
-
slope_error_list: List of errors in the slope of the lines
|
124 |
-
midpoint_error_list: List of errors in the midpoint_y of the lines
|
125 |
-
|
126 |
-
Returns:
|
127 |
-
average_slope_error: Average error in the slope of the lines
|
128 |
-
average_midpoint_error: Average error in the midpoint_y of the lines
|
129 |
-
"""
|
130 |
-
|
131 |
-
# Calculate the average and standard deviation of the errors
|
132 |
-
average_slope_error = np.mean(slope_error_list)
|
133 |
-
average_midpoint_error = np.mean(midpoint_error_list)
|
134 |
-
|
135 |
-
stddev_slope_error = np.std(slope_error_list)
|
136 |
-
stddev_midpoint_error = np.std(midpoint_error_list)
|
137 |
-
|
138 |
-
# Calculate the maximum errors
|
139 |
-
max_slope_error = np.max(slope_error_list)
|
140 |
-
max_midpoint_error = np.max(midpoint_error_list)
|
141 |
-
|
142 |
-
# Calculate the differences between errors in successive frames
|
143 |
-
diff_slope_error = np.abs(np.diff(slope_error_list))
|
144 |
-
diff_midpoint_error = np.abs(np.diff(midpoint_error_list))
|
145 |
-
|
146 |
-
# Calculate the number of jumps in the errors
|
147 |
-
num_slope_error_jumps = np.sum(
|
148 |
-
diff_slope_error > slope_error_jump_threshold)
|
149 |
-
num_midpoint_error_jumps = np.sum(
|
150 |
-
diff_midpoint_error > midpoint_error_jump_threshold)
|
151 |
-
|
152 |
-
# Create a dictionary to store the results
|
153 |
-
sequence_results = {
|
154 |
-
'average_slope_error': average_slope_error,
|
155 |
-
'average_midpoint_error': average_midpoint_error,
|
156 |
-
'stddev_slope_error': stddev_slope_error,
|
157 |
-
'stddev_midpoint_error': stddev_midpoint_error,
|
158 |
-
'max_slope_error': max_slope_error,
|
159 |
-
'max_midpoint_error': max_midpoint_error,
|
160 |
-
'num_slope_error_jumps': num_slope_error_jumps,
|
161 |
-
'num_midpoint_error_jumps': num_midpoint_error_jumps
|
162 |
-
}
|
163 |
-
|
164 |
-
return sequence_results
|
165 |
-
|
166 |
-
|
167 |
-
def calculate_horizon_error(annotated_horizon, proposed_horizon):
|
168 |
-
"""
|
169 |
-
Calculate the error between the annotated horizon and the proposed horizon
|
170 |
-
|
171 |
-
Args:
|
172 |
-
annotated_horizon: list of two points, each point is a list of two elements
|
173 |
-
Points are in the form of [x, y], where x and y are normalized to [0, 1]
|
174 |
-
proposed_horizon: list of two points, each point is a list of two elements
|
175 |
-
Points are in the form of [x, y], where x and y are normalized to [0, 1]
|
176 |
-
|
177 |
-
Returns:
|
178 |
-
slope_error: Error in the slope of the lines
|
179 |
-
midpoint_error: Error in the midpoint_y of the lines
|
180 |
-
"""
|
181 |
-
|
182 |
-
slope_annotated, midpoint_annotated = xy_points_to_slope_midpoint(
|
183 |
-
annotated_horizon)
|
184 |
-
slope_proposed, midpoint_proposed = xy_points_to_slope_midpoint(
|
185 |
-
proposed_horizon)
|
186 |
-
|
187 |
-
slope_error = abs(slope_annotated - slope_proposed)
|
188 |
-
midpoint_error = abs(midpoint_annotated[1] - midpoint_proposed[1])
|
189 |
-
|
190 |
-
return slope_error, midpoint_error
|
191 |
-
|
192 |
-
|
193 |
-
def calculate_horizon_error_across_sequence(slope_error_list,
|
194 |
-
midpoint_error_list,
|
195 |
-
slope_error_jump_threshold,
|
196 |
-
midpoint_error_jump_threshold):
|
197 |
-
"""
|
198 |
-
Calculate the error statistics across a sequence of frames
|
199 |
-
|
200 |
-
Args:
|
201 |
-
slope_error_list: List of errors in the slope of the lines
|
202 |
-
midpoint_error_list: List of errors in the midpoint_y of the lines
|
203 |
-
|
204 |
-
Returns:
|
205 |
-
average_slope_error: Average error in the slope of the lines
|
206 |
-
average_midpoint_error: Average error in the midpoint_y of the lines
|
207 |
-
"""
|
208 |
-
|
209 |
-
# Calculate the average and standard deviation of the errors
|
210 |
-
average_slope_error = np.mean(slope_error_list)
|
211 |
-
average_midpoint_error = np.mean(midpoint_error_list)
|
212 |
-
|
213 |
-
stddev_slope_error = np.std(slope_error_list)
|
214 |
-
stddev_midpoint_error = np.std(midpoint_error_list)
|
215 |
-
|
216 |
-
# Calculate the maximum errors
|
217 |
-
max_slope_error = np.max(slope_error_list)
|
218 |
-
max_midpoint_error = np.max(midpoint_error_list)
|
219 |
-
|
220 |
-
# Calculate the differences between errors in successive frames
|
221 |
-
diff_slope_error = np.abs(np.diff(slope_error_list))
|
222 |
-
diff_midpoint_error = np.abs(np.diff(midpoint_error_list))
|
223 |
-
|
224 |
-
# Calculate the number of jumps in the errors
|
225 |
-
num_slope_error_jumps = np.sum(
|
226 |
-
diff_slope_error > slope_error_jump_threshold)
|
227 |
-
num_midpoint_error_jumps = np.sum(
|
228 |
-
diff_midpoint_error > midpoint_error_jump_threshold)
|
229 |
-
|
230 |
-
# Create a dictionary to store the results
|
231 |
-
sequence_results = {
|
232 |
-
'average_slope_error': average_slope_error,
|
233 |
-
'average_midpoint_error': average_midpoint_error,
|
234 |
-
'stddev_slope_error': stddev_slope_error,
|
235 |
-
'stddev_midpoint_error': stddev_midpoint_error,
|
236 |
-
'max_slope_error': max_slope_error,
|
237 |
-
'max_midpoint_error': max_midpoint_error,
|
238 |
-
'num_slope_error_jumps': num_slope_error_jumps,
|
239 |
-
'num_midpoint_error_jumps': num_midpoint_error_jumps
|
240 |
-
}
|
241 |
-
|
242 |
-
return sequence_results
|
243 |
-
|
244 |
-
|
245 |
-
def slope_to_roll(slope):
|
246 |
-
"""
|
247 |
-
Convert the slope of the horizon to roll
|
248 |
-
|
249 |
-
Args:
|
250 |
-
slope: Slope of the horizon
|
251 |
-
|
252 |
-
Returns:
|
253 |
-
roll: Roll in degrees
|
254 |
-
"""
|
255 |
-
roll = np.arctan(slope) * 180 / np.pi
|
256 |
-
return roll
|
257 |
-
|
258 |
-
|
259 |
-
def roll_to_slope(roll):
|
260 |
-
"""
|
261 |
-
Convert the roll of the horizon to slope
|
262 |
-
|
263 |
-
Args:
|
264 |
-
roll: Roll of the horizon in degrees
|
265 |
-
|
266 |
-
Returns:
|
267 |
-
slope: Slope of the horizon
|
268 |
-
"""
|
269 |
-
slope = np.tan(roll * np.pi / 180)
|
270 |
-
return slope
|
271 |
-
|
272 |
-
|
273 |
-
def midpoint_to_pitch(midpoint, vertical_fov_degrees):
|
274 |
-
"""
|
275 |
-
Convert the midpoint of the horizon to pitch
|
276 |
-
|
277 |
-
Args:
|
278 |
-
midpoint: Midpoint of the horizon
|
279 |
-
vertical_fov_degrees: Vertical field of view of the camera in degrees
|
280 |
-
|
281 |
-
Returns:
|
282 |
-
pitch: Pitch in degrees
|
283 |
-
"""
|
284 |
-
pitch = midpoint * vertical_fov_degrees
|
285 |
-
return pitch
|
286 |
-
|
287 |
-
|
288 |
-
def pitch_to_midpoint(pitch, vertical_fov_degrees):
|
289 |
-
"""
|
290 |
-
Convert the pitch of the horizon to midpoint
|
291 |
-
|
292 |
-
Args:
|
293 |
-
pitch: Pitch of the horizon in degrees
|
294 |
-
vertical_fov_degrees: Vertical field of view of the camera in degrees
|
295 |
-
|
296 |
-
Returns:
|
297 |
-
midpoint: Midpoint of the horizon
|
298 |
-
"""
|
299 |
-
midpoint = pitch / vertical_fov_degrees
|
300 |
-
return midpoint
|
301 |
-
|
302 |
-
|
303 |
-
# end utils
|
304 |
class horizonmetrics(evaluate.Metric):
|
305 |
"""TODO: Short description of my evaluation module."""
|
306 |
|
@@ -351,9 +110,7 @@ class horizonmetrics(evaluate.Metric):
|
|
351 |
"""
|
352 |
|
353 |
# does not impact the metric, but is required for the interface x_x
|
354 |
-
super(evaluate.Metric, self).add(prediction=
|
355 |
-
references=references,
|
356 |
-
**kwargs)
|
357 |
|
358 |
self.predictions = predictions
|
359 |
self.ground_truth_det = references
|
|
|
17 |
import datasets
|
18 |
import numpy as np
|
19 |
|
20 |
+
from seametrics.horizon.utils import *
|
21 |
|
22 |
# TODO: Add BibTeX citation
|
23 |
_CITATION = """\
|
|
|
60 |
|
61 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION,
|
62 |
_KWARGS_DESCRIPTION)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
class horizonmetrics(evaluate.Metric):
|
64 |
"""TODO: Short description of my evaluation module."""
|
65 |
|
|
|
110 |
"""
|
111 |
|
112 |
# does not impact the metric, but is required for the interface x_x
|
113 |
+
super(evaluate.Metric, self).add(prediction=0, references=0, **kwargs)
|
|
|
|
|
114 |
|
115 |
self.predictions = predictions
|
116 |
self.ground_truth_det = references
|