Skip to content

Add tests for category_map argument in detect() / _convert_detections()#282

Merged
tkswanson merged 2 commits into
detect_include_categoriesfrom
copilot/add-tests-category-map-argument
May 1, 2026
Merged

Add tests for category_map argument in detect() / _convert_detections()#282
tkswanson merged 2 commits into
detect_include_categoriesfrom
copilot/add-tests-category-map-argument

Conversation

Copy link
Copy Markdown

Copilot AI commented May 1, 2026

No tests existed to verify that category_map is correctly applied to produce category_label in detection results.

New test classes

TestCategoryMapConvertDetections — exercises _convert_detections directly:

  • Custom map entry produces the correct category_label
  • All entries in a custom map are applied correctly
  • Category ID absent from the map yields "unknown"
  • category_map=None falls back to MD_LABELS
  • Explicit MD_LABELS produces correct labels for mdv5 (category offset included)

TestDetectCategoryMap — exercises detect() via mocking:

  • detect() forwards the caller-supplied category_map as the 5th positional arg to _convert_detections
  • Returned category_label values reflect the custom map
custom_map = {0: 'fox', 1: 'rabbit'}
results = detect(detector, 'image.jpg', 640, 640, category_map=custom_map)
# results[0]['detections'][0]['category_label'] == 'fox'

@tkswanson tkswanson marked this pull request as ready for review May 1, 2026 22:47
@tkswanson tkswanson merged commit c0c2923 into detect_include_categories May 1, 2026
@tkswanson tkswanson deleted the copilot/add-tests-category-map-argument branch May 1, 2026 22:47
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.

2 participants