Skip to content

Commit

Permalink
Merge pull request #145 from tryolabs/default-optimized-filter
Browse files Browse the repository at this point in the history
Set optimized filter as default
  • Loading branch information
aguscas committed Aug 16, 2022
2 parents 3bdaf04 + 3d373e2 commit 4b5081a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
2 changes: 2 additions & 0 deletions demos/motmetrics4norfair/motmetrics4norfair.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np

from norfair import Tracker, drawing, metrics, video
from norfair.filter import FilterPyKalmanFilterFactory

frame_skip_period = 1
detection_threshold = 0.01
Expand Down Expand Up @@ -124,6 +125,7 @@ def keypoints_distance(detected_pose, tracked_pose):
detection_threshold=detection_threshold,
pointwise_hit_counter_max=pointwise_hit_counter_max,
hit_counter_max=hit_counter_max,
filter_factory=FilterPyKalmanFilterFactory(),
)

# Initialize accumulator for this video
Expand Down
2 changes: 2 additions & 0 deletions demos/motmetrics4norfair/motmetrics4norfair_xyah.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
sys.path.append('../../norfair')
from tracker import Tracker
from norfair import drawing, metrics, video, Detection
from norfair.filter import FilterPyKalmanFilterFactory

frame_skip_period = 1
detection_threshold = 0.01
Expand Down Expand Up @@ -129,6 +130,7 @@ def iou_xyah(detected_pose, tracked_pose):
detection_threshold=detection_threshold,
pointwise_hit_counter_max=pointwise_hit_counter_max,
hit_counter_max=hit_counter_max,
filter_factory=FilterPyKalmanFilterFactory(),
)

# Initialize accumulator for this video
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The class in charge of performing the tracking of the detections produced by the
- `initialization_delay (optional)`: The argument `initialization_delay` determines by how large the object's hit counter must be in order to be considered as initialized, and get returned to the user as a real object. It must be smaller than `hit_counter_max` or otherwise the object would never be initialized. If set to 0, objects will get returned to the user as soon as they are detected for the first time, which can be problematic as this can result in objects appearing and immediately dissapearing. Defaults to `hit_counter_max / 2`.
- `pointwise_hit_counter_max (optional)`: Each tracked object keeps track of how often the points it's tracking have been getting matched. Points that are getting matched (`pointwise_hit_counter > 0`) are said to be live, and points which aren't (`pointwise_hit_counter = 0`) are said to not be live. This is used to determine things like which individual points in a tracked object get drawn by [`draw_tracked_objects`](#draw_tracked_objects) and which don't. This argument (`pointwise_hit_counter_max`) defines how large the inertia for each point of a tracker can grow. Defaults to `5`.
- `detection_threshold (optional)`: Sets the threshold at which the scores of the points in a detection being fed into the tracker must dip below to be ignored by the tracker. Defaults to `0`.
- `filter_factory (optional)`: This parameter can be used to change what filter the [`TrackedObject`](#trackedobject) instances created by the tracker will use. Defaults to [`FilterPyKalmanFilterFactory()`](#filterpykalmanfilterfactory).
- `filter_factory (optional)`: This parameter can be used to change what filter the [`TrackedObject`](#trackedobject) instances created by the tracker will use. Defaults to [`OptimizedKalmanFilterFactory()`](#optimizedkalmanfilterfactory).
- `past_detections_length`: How many past detections to save for each tracked object. Norfair tries to distribute these past detections uniformly through the object's lifetime so they're more representative. Very useful if you want to add metric learning to your model, as you can associate an embedding to each detection and access them in your distance function. Defaults to `4`.

### Tracker.update
Expand Down
7 changes: 3 additions & 4 deletions norfair/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import numpy as np
from rich import print

from norfair.distances import get_distance_by_name

from .filter import FilterPyKalmanFilterFactory
from .distances import get_distance_by_name
from .filter import OptimizedKalmanFilterFactory
from .utils import validate_points


Expand All @@ -19,7 +18,7 @@ def __init__(
initialization_delay: Optional[int] = None,
pointwise_hit_counter_max: int = 4,
detection_threshold: float = 0,
filter_factory: "FilterPyKalmanFilterFactory" = FilterPyKalmanFilterFactory(),
filter_factory: "OptimizedKalmanFilterFactory" = OptimizedKalmanFilterFactory(),
past_detections_length: int = 4,
):
self.tracked_objects: Sequence["TrackedObject"] = []
Expand Down
46 changes: 23 additions & 23 deletions tests/metrics.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
IDF1 IDP IDR Rcll Prcn GT MT PT ML FP FN IDs FM MOTA MOTP IDt IDa IDm
MOT17-04-FRCNN 55.7% 73.9% 44.6% 56.3% 93.2% 83 18 43 22 1962 20778 90 104 52.0% 0.107 5 88 3
MOT17-11-FRCNN 54.6% 68.6% 45.3% 61.5% 93.1% 75 19 33 23 431 3631 64 61 56.3% 0.101 15 52 5
MOT17-05-SDP 58.5% 67.6% 51.5% 66.7% 87.6% 133 32 81 20 653 2301 134 140 55.4% 0.165 48 99 15
MOT17-10-FRCNN 39.9% 44.7% 36.0% 61.0% 75.8% 57 16 35 6 2504 5013 319 313 39.0% 0.173 125 193 10
MOT17-05-DPM 36.1% 57.1% 26.4% 38.0% 82.2% 133 10 58 65 570 4291 96 96 28.3% 0.242 33 72 12
MOT17-11-DPM 38.8% 49.7% 31.8% 54.2% 84.5% 75 12 24 39 935 4321 88 64 43.4% 0.217 20 69 4
MOT17-04-DPM 29.0% 43.1% 21.9% 42.5% 83.6% 83 7 44 32 3965 27336 401 420 33.3% 0.210 43 352 1
MOT17-10-SDP 47.4% 51.8% 43.6% 74.2% 88.1% 57 30 24 3 1292 3316 308 289 61.7% 0.198 139 165 6
MOT17-11-SDP 55.4% 61.0% 50.8% 75.8% 91.1% 75 34 30 11 697 2285 103 101 67.3% 0.140 43 69 13
MOT17-13-SDP 54.4% 66.4% 46.1% 57.0% 82.1% 110 45 28 37 1444 5008 229 209 42.6% 0.201 73 166 18
MOT17-09-DPM 33.4% 37.7% 30.0% 59.9% 75.4% 26 4 18 4 1042 2137 119 113 38.1% 0.262 41 81 3
MOT17-13-DPM 21.3% 59.9% 12.9% 18.0% 83.5% 110 5 28 77 416 9543 120 125 13.4% 0.268 35 94 9
MOT17-05-FRCNN 54.7% 72.0% 44.1% 54.7% 89.2% 133 24 68 41 457 3136 95 96 46.7% 0.181 44 68 17
MOT17-02-FRCNN 33.9% 53.8% 24.7% 36.6% 79.7% 62 7 26 29 1736 11783 119 131 26.6% 0.134 31 95 8
MOT17-09-SDP 53.2% 63.8% 45.6% 67.6% 94.6% 26 12 14 0 204 1726 52 55 62.8% 0.130 21 37 6
MOT17-09-FRCNN 54.0% 72.4% 43.1% 58.6% 98.5% 26 7 17 2 49 2207 40 39 56.9% 0.095 14 30 4
MOT17-02-SDP 34.4% 42.9% 28.7% 51.0% 76.1% 62 11 39 12 2979 9103 268 284 33.5% 0.182 82 190 8
MOT17-02-DPM 16.2% 41.0% 10.1% 20.2% 81.6% 62 5 14 43 843 14834 111 112 15.0% 0.246 19 91 1
MOT17-13-FRCNN 47.0% 52.9% 42.3% 58.8% 73.6% 110 29 57 24 2455 4802 371 366 34.5% 0.185 117 264 20
MOT17-10-DPM 28.0% 45.8% 20.2% 37.3% 84.6% 57 6 20 31 871 8051 127 154 29.5% 0.248 15 118 6
MOT17-04-SDP 66.2% 74.7% 59.5% 77.6% 97.4% 83 48 26 9 1001 10672 225 254 75.0% 0.132 89 136 5
OVERALL 45.3% 59.5% 36.6% 53.6% 87.2% 1638 381 727 530 26506 156274 3479 3526 44.7% 0.163 1052 2529 174
IDF1 IDP IDR Rcll Prcn GT MT PT ML FP FN IDs FM MOTA MOTP IDt IDa IDm
MOT17-10-DPM 27.4% 44.8% 19.8% 37.5% 84.9% 57 6 19 32 856 8024 127 153 29.8% 0.249 19 116 9
MOT17-04-SDP 66.2% 74.6% 59.4% 77.5% 97.4% 83 49 25 9 1003 10680 232 257 74.9% 0.132 94 136 4
MOT17-11-SDP 55.2% 60.8% 50.6% 75.7% 90.9% 75 34 30 11 719 2297 112 105 66.9% 0.141 47 73 13
MOT17-13-FRCNN 48.1% 54.3% 43.1% 59.3% 74.7% 110 33 53 24 2334 4735 342 331 36.3% 0.184 115 232 17
MOT17-05-FRCNN 55.2% 72.9% 44.4% 54.9% 90.0% 133 23 69 41 420 3123 78 84 47.7% 0.180 39 55 16
MOT17-02-SDP 34.4% 42.8% 28.7% 50.9% 75.9% 62 11 38 13 3003 9122 272 290 33.3% 0.184 72 203 7
MOT17-13-SDP 56.0% 68.5% 47.4% 57.6% 83.3% 110 46 26 38 1349 4934 164 163 44.6% 0.200 47 126 21
MOT17-10-SDP 47.5% 51.9% 43.7% 74.1% 88.0% 57 30 24 3 1295 3323 283 286 61.8% 0.198 119 157 5
MOT17-02-FRCNN 33.9% 53.8% 24.7% 36.5% 79.5% 62 7 26 29 1751 11796 124 136 26.4% 0.134 37 95 9
MOT17-13-DPM 22.1% 62.3% 13.4% 18.5% 85.8% 110 6 31 73 355 9490 90 100 14.7% 0.267 14 81 5
MOT17-04-FRCNN 55.7% 73.9% 44.7% 56.3% 93.2% 83 18 43 22 1959 20775 90 104 52.0% 0.107 5 88 3
MOT17-04-DPM 29.2% 43.3% 22.0% 42.5% 83.5% 83 7 44 32 3985 27365 406 432 33.2% 0.211 48 352 1
MOT17-09-FRCNN 54.0% 72.4% 43.1% 58.5% 98.5% 26 7 17 2 49 2209 40 39 56.8% 0.096 15 29 4
MOT17-11-DPM 39.2% 50.3% 32.2% 54.2% 84.7% 75 12 24 39 927 4321 87 63 43.5% 0.217 20 68 4
MOT17-09-DPM 33.4% 37.7% 30.0% 59.7% 75.1% 26 4 17 5 1052 2147 120 117 37.7% 0.263 41 82 3
MOT17-05-SDP 58.1% 67.3% 51.1% 66.8% 87.9% 133 32 81 20 637 2299 134 133 55.6% 0.165 51 98 18
MOT17-09-SDP 53.2% 63.8% 45.6% 67.7% 94.6% 26 12 14 0 204 1722 54 56 62.8% 0.130 22 38 6
MOT17-11-FRCNN 54.3% 68.3% 45.1% 61.4% 92.9% 75 18 34 23 443 3639 65 62 56.1% 0.102 16 54 6
MOT17-10-FRCNN 39.8% 44.7% 35.9% 60.9% 75.7% 57 14 37 6 2507 5020 310 306 39.0% 0.172 122 186 9
MOT17-05-DPM 36.5% 57.9% 26.6% 38.1% 82.9% 133 11 58 64 544 4281 90 100 28.9% 0.243 33 68 13
MOT17-02-DPM 16.2% 40.9% 10.1% 20.2% 81.4% 62 5 14 43 856 14833 113 109 15.0% 0.246 20 92 1
OVERALL 45.4% 59.7% 36.7% 53.7% 87.3% 1638 385 724 529 26248 156135 3333 3426 44.9% 0.164 996 2429 174
7 changes: 4 additions & 3 deletions tests/test_mot_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pandas as pd

from norfair import Tracker, metrics
from norfair import Tracker, metrics, FilterPyKalmanFilterFactory

DATASET_PATH = "train"
MOTA_ERROR_THRESHOLD = 0.0
Expand Down Expand Up @@ -80,6 +80,7 @@ def test_mot_metrics():
detection_threshold=DETECTION_THRESHOLD,
pointwise_hit_counter_max=POINTWISE_HIT_COUNTER_MAX,
hit_counter_max=HIT_COUNTER_MAX,
filter_factory=FilterPyKalmanFilterFactory(),
)

# Initialize accumulator for this video
Expand All @@ -103,8 +104,8 @@ def test_mot_metrics():
# Unify the scores to be able to compare them. new metrics is the percentage
# expressed between 0 and 1, the previous metrics have the percentage as a string
# with the % character at the end
new_overall_mota = new_metrics.loc["OVERALL", "mota"] * 100
previous_overall_mota = float(previous_metrics.loc["OVERALL", "mota"][:-1])
new_overall_mota = np.around(new_metrics.loc["OVERALL", "mota"] * 100, 1)
previous_overall_mota = np.around(float(previous_metrics.loc["OVERALL", "mota"][:-1]), 1)

accumulator.print_metrics()
assert new_overall_mota >= previous_overall_mota * (1 - MOTA_ERROR_THRESHOLD), f"New overall MOTA score: {new_overall_mota} is too low, previous overall MOTA score: {previous_overall_mota}"

0 comments on commit 4b5081a

Please sign in to comment.