⚡ Optimize _classify_entry membership check#44
Conversation
Replaced the $O(N)$ `any()` generator check with $O(1)$ logic using dictionary length. Since the background class "0" is checked explicitly, the presence of other classes is equivalent to len(counts) > 1 (if "0" is present) or len(counts) > 0 (if "0" is absent). This provides a measurable speed boost in dataset splitting, especially for manifests with many patches and multiple classes. Co-authored-by: tahamukhtar20 <91777330+tahamukhtar20@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Optimized the
_classify_entryfunction insrc/mapcv/splitter.pyby replacing theany()generator-based existence check for labeled pixels with more efficient logic usinglen(counts).🎯 Why: The previous implementation used$O(N)$ operation where $N$ is the number of classes. Since we already check for the presence of the background class $O(1)$ time by checking the length of the dictionary.
any(k != "0" for k in counts), which is an"0", the presence of any other class can be determined in📊 Measured Improvement: Focused benchmarks showed a significant performance boost for this function across all common scenarios:
The overall impact scales with the number of patches in the manifest during the stratified split process.
PR created automatically by Jules for task 13093316185413589860 started by @tahamukhtar20