File tree 3 files changed +30
-6
lines changed
3 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,25 @@ def no_empty_frames(
170
170
return int (is_valid )
171
171
172
172
173
+ def no_empty_tracking_result (
174
+ tracks : np .ndarray
175
+ ):
176
+ """
177
+ Checks if there is at least one detection in th results.
178
+
179
+ Args:
180
+ tracks: The tracks to inspect
181
+
182
+ Returns:
183
+ 1 if there are detections, 0 otherwise.
184
+ """
185
+ is_valid = 1
186
+ warnings .warn ("No tracks in result." , UserWarning )
187
+ if len (tracks ) == 0 :
188
+ is_valid = 0
189
+ return is_valid
190
+
191
+
173
192
def valid (
174
193
masks : list ,
175
194
tracks : np .ndarray ,
@@ -195,6 +214,8 @@ def valid(
195
214
196
215
"""
197
216
is_valid = 1
217
+ # If tracks is empty, the result is invalid
218
+ is_valid = no_empty_tracking_result (tracks )
198
219
# Get the labels in each frame
199
220
num_frames = max (tracks [:, 2 ].max () + 1 , len (masks ))
200
221
frames = [[] for _ in range (num_frames )]
Original file line number Diff line number Diff line change @@ -151,6 +151,13 @@ def calculate_metrics(
151
151
Returns:
152
152
The results stored in a dictionary.
153
153
"""
154
+ # Check if results are valid
155
+ results = {x : None for x in metrics }
156
+ if not is_valid :
157
+ print ("Invalid results!" )
158
+ results ["Valid" ] = 0
159
+ return results
160
+
154
161
# Create merge tracks
155
162
if traj :
156
163
new_tracks , new_labels , new_mapped = merge_tracks (
@@ -175,12 +182,6 @@ def calculate_metrics(
175
182
)
176
183
177
184
# Calculate metrics
178
- results = {x : None for x in metrics }
179
- if not is_valid :
180
- print ("Invalid results!" )
181
- results ["Valid" ] = 0
182
- return results
183
-
184
185
if "Valid" in metrics :
185
186
results ["Valid" ] = is_valid
186
187
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ def read_tracking_file(
73
73
return None
74
74
with open (path , "r" , encoding = "utf-8" ) as f :
75
75
lines = f .readlines ()
76
+ if len (lines ) == 0 :
77
+ return np .zeros ((0 , 4 ))
76
78
seperator = " " if " " in lines [0 ] else "\t "
77
79
lines = [x .strip ().split (seperator ) for x in lines ]
78
80
lines = [[int (y ) for y in x if y != "" ] for x in lines ]
You can’t perform that action at this time.
0 commit comments