Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Optimized accuracy calculation #5734
+22
−10
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Noiredd commentedJul 3, 2017
•
edited
Accuracy calculation, particularly for segmentation tasks with
top_k: 1, can be unnecessarily slow: note the two nested for loops (over the batch and over image pixels) withpartial_sortinside. The main culprit here is the need to copy all data to a new container so we can sort it.My proposal is to replace that with a dynamically updated
priority_queue. Instead of copying every prediction vector and sorting it later, it is much faster to iterate over it just once and only copy an element when it's larger than the smallest ofkcurrently best ones (provided by an automatically sorted container, priority queue being the fastest).Benchmark settings:
max_iter: 14640,test_interval: 1464,test_iter: 1449,Each build was ran 4 times (Titan Z has two cores so I ran two nets in parallel, making it effectively 2 times 2 runs); times were measured from job initialization to completion (as reported by DIGITS).
Results:
(*) for
top_k==1we don't need any container, just remember the best element's value and index - as we see, this is only marginally faster so for the sake of code clarity I opted against having a separate case for that.For me this is about 10% faster for top-5 accuracy, and over 30% faster for top-1.