Spaces:
Runtime error
Runtime error
Commit
•
ddf2165
1
Parent(s):
b1934ba
Min_travel restriction
Browse files- app.py +3 -2
- gradio_scripts/upload_ui.py +3 -1
- inference.py +7 -5
- lib/fish_eye/tracker.py +2 -2
app.py
CHANGED
@@ -27,7 +27,7 @@ result = {}
|
|
27 |
|
28 |
|
29 |
# Called when an Aris file is uploaded for inference
|
30 |
-
def on_aris_input(file_list, model_id, conf_thresh, iou_thresh, min_hits, max_age, use_associative, boost_power, boost_decay, min_length):
|
31 |
|
32 |
# Reset Result
|
33 |
reset_state(result, state)
|
@@ -42,7 +42,8 @@ def on_aris_input(file_list, model_id, conf_thresh, iou_thresh, min_hits, max_ag
|
|
42 |
'use_associative_tracking': use_associative,
|
43 |
'boost_power': boost_power,
|
44 |
'boost_decay': boost_decay,
|
45 |
-
'min_length': min_length
|
|
|
46 |
}
|
47 |
|
48 |
print(" ")
|
|
|
27 |
|
28 |
|
29 |
# Called when an Aris file is uploaded for inference
|
30 |
+
def on_aris_input(file_list, model_id, conf_thresh, iou_thresh, min_hits, max_age, use_associative, boost_power, boost_decay, min_length, min_travel):
|
31 |
|
32 |
# Reset Result
|
33 |
reset_state(result, state)
|
|
|
42 |
'use_associative_tracking': use_associative,
|
43 |
'boost_power': boost_power,
|
44 |
'boost_decay': boost_decay,
|
45 |
+
'min_length': min_length,
|
46 |
+
'min_travel': min_travel
|
47 |
}
|
48 |
|
49 |
print(" ")
|
gradio_scripts/upload_ui.py
CHANGED
@@ -39,7 +39,9 @@ def Upload_Gradio(gradio_components):
|
|
39 |
settings.append(gr.Slider(0, 1, value=1, label="Boost Decay", info=""))
|
40 |
|
41 |
gr.Markdown("Other")
|
42 |
-
|
|
|
|
|
43 |
|
44 |
gradio_components['hyperparams'] = settings
|
45 |
|
|
|
39 |
settings.append(gr.Slider(0, 1, value=1, label="Boost Decay", info=""))
|
40 |
|
41 |
gr.Markdown("Other")
|
42 |
+
with gr.Row():
|
43 |
+
settings.append(gr.Slider(0, 3, value=0.3, label="Min Length", info="Minimum length of fish (meters) in order for it to count"))
|
44 |
+
settings.append(gr.Slider(0, 5, value=1, label="Min Travel", info="Minimum travel distance of track (meters) in order for it to count"))
|
45 |
|
46 |
gradio_components['hyperparams'] = settings
|
47 |
|
inference.py
CHANGED
@@ -32,6 +32,7 @@ MAX_AGE = 14 # time until missing fish get's new id
|
|
32 |
MIN_HITS = 16 # minimum number of frames with a specific fish for it to count
|
33 |
MIN_LENGTH = 0.3 # minimum fish length, in meters
|
34 |
IOU_THRES = 0.01 # IOU threshold for tracking
|
|
|
35 |
###
|
36 |
|
37 |
def norm(bbox, w, h):
|
@@ -62,6 +63,7 @@ def do_full_inference(dataloader, image_meter_width, image_meter_height, gp=None
|
|
62 |
if 'boost_decay' not in hyperparams: hyperparams['maxboost_decay_age'] = 1
|
63 |
if 'AT_decay' not in hyperparams: hyperparams['AT_decay'] = MIN_HITS
|
64 |
if 'min_length' not in hyperparams: hyperparams['min_length'] = MIN_LENGTH
|
|
|
65 |
|
66 |
model, device = setup_model(hyperparams['model'])
|
67 |
|
@@ -101,7 +103,7 @@ def do_full_inference(dataloader, image_meter_width, image_meter_height, gp=None
|
|
101 |
|
102 |
all_preds, real_width, real_height = format_predictions(image_shapes, outputs, width, height, gp=gp)
|
103 |
|
104 |
-
results = do_tracking(all_preds, image_meter_width, image_meter_height, min_hits=hyperparams['min_hits'], max_age=hyperparams['max_age'], min_length=hyperparams['min_length'], gp=gp)
|
105 |
|
106 |
return results
|
107 |
|
@@ -308,7 +310,7 @@ def boost_frame(safe_frame, base_frame, dt, power=1, decay=1):
|
|
308 |
base_frame[:, 4] *= 1 + power*(score)*math.exp(-decay*(dt*dt-1))
|
309 |
return base_frame
|
310 |
|
311 |
-
def do_tracking(all_preds, image_meter_width, image_meter_height, gp=None, max_age=MAX_AGE, iou_thres=IOU_THRES, min_hits=MIN_HITS, min_length=MIN_LENGTH, verbose=True):
|
312 |
|
313 |
if (gp): gp(0, "Tracking...")
|
314 |
|
@@ -332,11 +334,11 @@ def do_tracking(all_preds, image_meter_width, image_meter_height, gp=None, max_a
|
|
332 |
tracker.update()
|
333 |
pbar.update(1)
|
334 |
|
335 |
-
json_data = tracker.finalize(min_length=min_length)
|
336 |
|
337 |
return json_data
|
338 |
|
339 |
-
def do_associative_tracking(low_preds, high_preds, image_meter_width, image_meter_height, reverse=False, gp=None, max_age=MAX_AGE, iou_thres=IOU_THRES, min_hits=MIN_HITS, min_length=MIN_LENGTH, verbose=True):
|
340 |
|
341 |
if (gp): gp(0, "Tracking...")
|
342 |
|
@@ -363,7 +365,7 @@ def do_associative_tracking(low_preds, high_preds, image_meter_width, image_mete
|
|
363 |
tracker.update((np.empty((0, 5)), np.empty((0, 5))))
|
364 |
pbar.update(1)
|
365 |
|
366 |
-
json_data = tracker.finalize(min_length=min_length)
|
367 |
|
368 |
return json_data
|
369 |
|
|
|
32 |
MIN_HITS = 16 # minimum number of frames with a specific fish for it to count
|
33 |
MIN_LENGTH = 0.3 # minimum fish length, in meters
|
34 |
IOU_THRES = 0.01 # IOU threshold for tracking
|
35 |
+
MIN_TRAVEL = -1 # Minimum distance a track has to travel
|
36 |
###
|
37 |
|
38 |
def norm(bbox, w, h):
|
|
|
63 |
if 'boost_decay' not in hyperparams: hyperparams['maxboost_decay_age'] = 1
|
64 |
if 'AT_decay' not in hyperparams: hyperparams['AT_decay'] = MIN_HITS
|
65 |
if 'min_length' not in hyperparams: hyperparams['min_length'] = MIN_LENGTH
|
66 |
+
if 'min_travel' not in hyperparams: hyperparams['min_travel'] = MIN_TRAVEL
|
67 |
|
68 |
model, device = setup_model(hyperparams['model'])
|
69 |
|
|
|
103 |
|
104 |
all_preds, real_width, real_height = format_predictions(image_shapes, outputs, width, height, gp=gp)
|
105 |
|
106 |
+
results = do_tracking(all_preds, image_meter_width, image_meter_height, min_hits=hyperparams['min_hits'], max_age=hyperparams['max_age'], min_length=hyperparams['min_length'], min_travel=hyperparams['min_travel'], gp=gp)
|
107 |
|
108 |
return results
|
109 |
|
|
|
310 |
base_frame[:, 4] *= 1 + power*(score)*math.exp(-decay*(dt*dt-1))
|
311 |
return base_frame
|
312 |
|
313 |
+
def do_tracking(all_preds, image_meter_width, image_meter_height, gp=None, max_age=MAX_AGE, iou_thres=IOU_THRES, min_hits=MIN_HITS, min_length=MIN_LENGTH, min_travel=MIN_TRAVEL, verbose=True):
|
314 |
|
315 |
if (gp): gp(0, "Tracking...")
|
316 |
|
|
|
334 |
tracker.update()
|
335 |
pbar.update(1)
|
336 |
|
337 |
+
json_data = tracker.finalize(min_length=min_length, min_travel=min_travel)
|
338 |
|
339 |
return json_data
|
340 |
|
341 |
+
def do_associative_tracking(low_preds, high_preds, image_meter_width, image_meter_height, reverse=False, gp=None, max_age=MAX_AGE, iou_thres=IOU_THRES, min_hits=MIN_HITS, min_length=MIN_LENGTH, min_travel=MIN_TRAVEL, verbose=True):
|
342 |
|
343 |
if (gp): gp(0, "Tracking...")
|
344 |
|
|
|
365 |
tracker.update((np.empty((0, 5)), np.empty((0, 5))))
|
366 |
pbar.update(1)
|
367 |
|
368 |
+
json_data = tracker.finalize(min_length=min_length, min_travel=min_travel)
|
369 |
|
370 |
return json_data
|
371 |
|
lib/fish_eye/tracker.py
CHANGED
@@ -68,7 +68,7 @@ class Tracker:
|
|
68 |
else:
|
69 |
self.frame_id += 1
|
70 |
|
71 |
-
def finalize(self, output_path=None, min_length=-1.0): # vert_margin=0.0
|
72 |
json_data = deepcopy(self.json_data)
|
73 |
|
74 |
# map (valid) fish IDs to 0, 1, 2, ...
|
@@ -136,7 +136,7 @@ class Tracker:
|
|
136 |
if min_length != -1.0:
|
137 |
new_fish = []
|
138 |
for fish in json_data['fish']:
|
139 |
-
if fish['length'] > min_length:
|
140 |
new_fish.append(fish)
|
141 |
else:
|
142 |
invalid_ids.append(fish['id'])
|
|
|
68 |
else:
|
69 |
self.frame_id += 1
|
70 |
|
71 |
+
def finalize(self, output_path=None, min_length=-1.0, min_travel=-1.0): # vert_margin=0.0
|
72 |
json_data = deepcopy(self.json_data)
|
73 |
|
74 |
# map (valid) fish IDs to 0, 1, 2, ...
|
|
|
136 |
if min_length != -1.0:
|
137 |
new_fish = []
|
138 |
for fish in json_data['fish']:
|
139 |
+
if fish['length'] > min_length and fish['travel_dist'] > min_travel:
|
140 |
new_fish.append(fish)
|
141 |
else:
|
142 |
invalid_ids.append(fish['id'])
|