open-metric-learning icon indicating copy to clipboard operation
open-metric-learning copied to clipboard

Feature/metrics/stable metrics

Open dapladoc opened this issue 1 year ago • 6 comments

Introduce permutation stable version of the retrieval metrics. The idea is to sort gt_tops for which distances are the same, i.e. if distances_tops and gt_tops are

distances_tops = [1, 2, 2, 2, 3]
gt_tops = [0, 1, 0, 1, 0]

then we need to obtain

gt_tops = [0, 0, 1, 1, 0]
#             -------
#             sort gt_tops where there are multiple
#             distances of the same value

The code for the retrieval metrics itself doesn't change.

dapladoc avatar Jun 04 '23 12:06 dapladoc

In the failed test called test_metrics_is_similar_in_ddp it is said that

Metrics shouldn't be equal, but very similar

If I change the atol for the test from 5e-3 to 8e-3 the test passes. Is this workaround ok?

dapladoc avatar Jun 05 '23 10:06 dapladoc

@dapladoc changing tolerance is okay

AlekseySh avatar Jun 05 '23 21:06 AlekseySh

@AlekseySh @DaloroAT hey guys. It looks like this PR is ready to be reviewed.

As I described above the main idea is to sort gt_tops values corresponding to the same distance values. In order to do it properly, first we need to find new value of max_k such that torch.any(distances[:, max_k] == distances[:, max_k + 1] is False (function _estimate_suitable_max_k). Next, we need to make the sorting (function _sort_gt_tops). And all the steps for getting the gt_tops is now encapsulated in function _get_gt_tops.

dapladoc avatar Jun 07 '23 17:06 dapladoc

@DaloroAT What do you think? Does bringing the additional logic worth the benefits of metrics' stability? PS. Initially, I thought that the required extra logic would be smaller and simpler...

AlekseySh avatar Jun 26 '23 13:06 AlekseySh

@dapladoc let's implement what we've decided offline:

  1. measure overhead
  2. introduce a flag for this functionality available for developers only (so, we don't expose is to config)
  3. depends on the first step, set this flag as True or False by default

AlekseySh avatar Jul 16 '23 16:07 AlekseySh

@dapladoc hey! just a reminder :)

AlekseySh avatar Aug 06 '23 17:08 AlekseySh

Let me close it for now due to inactivity.

Metrics code has also been significantly modified. The order of predictions is determined in RetrievalResults, so, I'm not sure this problem is even actual now.

So, anyway, the PR has to be reworked.

AlekseySh avatar Jun 07 '24 15:06 AlekseySh