Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize one-to-one match computation #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vincent-leonardo
Copy link

Problem: Repeating same computation when calling one-to-one match.
Especially slow when each individual GT/submission file has large number of bounding boxes (>100). The first 2 conditions of the one_to_one_match only need to be computed once.

How to reproduce:

  1. Prepare a gt.zip in which each .txt file contains large number of bounding boxes.
  2. Similarly, the subm.zip can also contains large number of bounding boxes.
  3. Run python script.py -g="gt.zip" -s="subm.zip" [--E2E] [-t 4]

Output (average bbox per gt/subm: 100~):

'Calculated!'
{'Detection': {'hmean': 0.9995194475865179,
               'precision': 0.9992978099060543,
               'recall': 0.999741183604351},
 'Detection_Metadata': {'char_false_pos': 0,
                        'char_miss': 0,
                        'char_overlap': 60,
                        'num_false_pos': 0,
                        'num_merge': 34,
                        'num_split': 35},
 'EndtoEnd': {'hmean': 0.999741183604351,
              'precision': 0.999741183604351,
              'recall': 0.999741183604351,
              'recognition_score': 1.0},
 'EndtoEnd_Metadata': {'char_false_pos': 0.0,
                       'char_miss': 35.0,
                       'num_false_pos': 0,
                       'num_merge': 34,
                       'num_split': 35}}
Evaluated in 226305.144 ms

After optimization:

'Calculated!'
{'Detection': {'hmean': 0.9995194475865179,
               'precision': 0.9992978099060543,
               'recall': 0.999741183604351},
 'Detection_Metadata': {'char_false_pos': 0,
                        'char_miss': 0,
                        'char_overlap': 60,
                        'num_false_pos': 0,
                        'num_merge': 34,
                        'num_split': 35},
 'EndtoEnd': {'hmean': 0.999741183604351,
              'precision': 0.999741183604351,
              'recall': 0.999741183604351,
              'recognition_score': 1.0},
 'EndtoEnd_Metadata': {'char_false_pos': 0.0,
                       'char_miss': 35.0,
                       'num_false_pos': 0,
                       'num_merge': 34,
                       'num_split': 35}}
Evaluated in 11632.926 ms

Explanation & Solutions: the one_to_one_match is called n_gt * n_sumb times.
The first condition relies only on the row (always sum all second axis) while the second condition relies only on the col (always sum the first axis). All of which can just be computed once and reuse for all the n_gt * n_sumb iterations.
We can immediately filter out the indices that doesn't meet the first & second condition and iterate through those that still possible for one-to-one match (and check with the third condition)

Vincent Leonardo and others added 2 commits February 25, 2021 13:24
Calculate 1-to-1 matching condition for all rows and all columns once and re-use it for the iteration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant