Conversation
- Reserve img_cat_to_anns for distinct (img, cat) pairs, not the annotation count (~400K vs ~1.5M on the RF-DETR workload). - Derive cat_to_imgs from img_cat_to_anns's unique keys after the annotation loop instead of pushing once per annotation. - Switch all six index maps (anns, imgs, cats, img_to_anns, cat_to_imgs, img_cat_to_anns) from std HashMap to rustc_hash::FxHashMap. All six are private; no public signature changes. Map iteration never reaches output (every iteration site feeds a sort), verified before the swap. - Add rustc-hash as a direct dependency (already present transitively via numpy); MIT/Apache-2.0, passes deny.toml. - No value changes: precision/recall/scores/stats bit-identical to main on 10 freshly-generated configs (the original baseline dumps' exact args for two configs were unrecoverable, so a new set was authored and dumped from a throwaway main worktree). - loadRes 34% faster, COCOeval ctor 49% faster, end-to-end 20% faster on the RF-DETR-shaped harness workload (both phases call create_index). - Add test_cat_to_imgs_derived_from_pair_keys, pinning cat_to_imgs's membership/dedup and get_ann_ids_for_img_cat's dataset-order contract; verified it fails on three injected defects (swapped pair fields, wrong source map, sorted values). --- Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request significantly optimizes the
COCO::create_indexmethod and related data structures for handling COCO datasets, focusing on performance and memory efficiency. The main changes include switching to a faster hash map implementation, optimizing how indices are built (especially for large datasets), and adding comprehensive tests to ensure correctness and maintain important invariants.Performance and Data Structure Optimizations:
COCOstruct from the standard library'sHashMaptorustc_hash::FxHashMap, which is much faster for integer and integer-pair keys. This change improves performance, especially on large datasets. [1] [2] [3] [4]img_cat_to_annsto reserve capacity based on the number of distinct (image, category) pairs instead of the total number of annotations, reducing memory waste for dense workloads.cat_to_imgsto derive its entries from the set of unique (img, cat) pairs, rather than pushing once per annotation. This results in fewer insertions and guarantees deduplication.cat_to_imgsis sorted and deduplicated after construction for deterministic iteration order and safety, even though the construction method now guarantees uniqueness.Testing and Documentation:
test_cat_to_imgs_derived_from_pair_keys) to verify thatcat_to_imgsis built from unique (img, cat) pairs and thatimg_cat_to_annspreserves annotation order, maintaining compatibility with COCO evaluation semantics.Changelog and Dependency Updates:
rustc-hashas a direct dependency. [1] [2]rustc-hashas a direct dependency inCargo.toml.