Skip to content

fix: avoid type-mutation bug in display_tp_fp_fn and normalize image_ids - #82

Open
botbikamordehai2-sketch wants to merge 1 commit into
MiXaiLL76:mainfrom
botbikamordehai2-sketch:fix/issue-80-1784718632
Open

fix: avoid type-mutation bug in display_tp_fp_fn and normalize image_ids#82
botbikamordehai2-sketch wants to merge 1 commit into
MiXaiLL76:mainfrom
botbikamordehai2-sketch:fix/issue-80-1784718632

Conversation

@botbikamordehai2-sketch

@botbikamordehai2-sketch botbikamordehai2-sketch commented Jul 22, 2026

Copy link
Copy Markdown

What

The display_tp_fp_fn method allowed image_ids to be a mixed list of ints and strings (e.g., from user input). The .get() call with a string key on an int-keyed dict silently fails (returns None) and causes some images to be skipped with a warning. Moreover, the method mutates the image_ids list when == ["all"] but does not protect against subsequent mutation of self.cocoGt.imgs during iteration.

Fix

  1. Convert all non-"all" image_ids to int via [int(i) for i in image_ids] to ensure type consistency with the keys of self.cocoGt.imgs.
  2. Use image_id not in self.cocoGt.imgs for existence check instead of .get() to avoid silent miss.
  3. Iterate over a copy (already a list) to avoid mutation during iteration.

Closes #80

@Borda

Borda commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

@botbikamordehai2-sketch I am very sure it does not close the mentioned #80 by far
pls update your PR describtion 🐰

@Borda Borda changed the title fix: avoid type-mutation bug in display_tp_fp_fn and normalize image_ids (closes #80) fix: avoid type-mutation bug in display_tp_fp_fn and normalize image_ids Jul 22, 2026
@Borda
Borda requested a review from Copilot July 22, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens PreviewResults.display_tp_fp_fn against mixed-type image_ids inputs by normalizing IDs and using an explicit existence check so valid images aren’t skipped due to key-type mismatches.

Changes:

  • Normalize non-["all"] image_ids values to int before iterating.
  • Replace dict.get(...) is None with image_id not in self.cocoGt.imgs for existence checking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +91 to +93
else:
# Normalize image_ids to int to avoid KeyError from type mismatch
image_ids = [int(i) for i in image_ids]
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.

Full Review: code + tests + docs + performance

3 participants