nwojke / deep_sort

Simple Online Realtime Tracking with a Deep Association Metric
GNU General Public License v3.0
5.35k stars 1.49k forks source link

Cosine similarity range problem #205

Open corentin87 opened 4 years ago

corentin87 commented 4 years ago

Hi everyone, The definition of similarity using cosine is which give us a number between [-1, 1].

But in the code the similarity is defined by which will give a number between [0, 2]. Should we divide by 2? Because we want to get a normalised distance to be thresholded.

Thanks!

studentbrad commented 3 years ago

Good observation, the cost is a value in [0, 2]. Think of the cost as a remap of the similarity. If the similarity is in [-1, 1], then the cost is in [0, 2]. Now you can see that a similarity of -1 maps to a cost of 2, and a similarity of 1 maps to a cost of 0. This is desired functionality, because the matching cascade matches indices with relatively low cost values (high similarity). To learn more about this I would look at the Hungarian algorithm which performs a similar matching to that of the matching cascade. If you want to match based on similarity and not cost you can also look at maximum weighted matching, another solution to the assignment problem.