Skip to content

Add ObjectDetector.getLabels() on the Web Tasks API - #6339

Open
a2105z wants to merge 1 commit into
google-ai-edge:masterfrom
a2105z:object-detector-get-labels
Open

Add ObjectDetector.getLabels() on the Web Tasks API#6339
a2105z wants to merge 1 commit into
google-ai-edge:masterfrom
a2105z:object-detector-get-labels

Conversation

@a2105z

@a2105z a2105z commented Aug 20, 2026

Copy link
Copy Markdown

Summary

  • Apps that let users swap or upload a custom object-detector .tflite cannot show that model's class list without hardcoding it. detect() only returns categories for objects that actually fire.
  • Adds ObjectDetector.getLabels(): string[] on the Web Tasks API, matching ImageSegmenter.getLabels().
  • After graph refresh, reads the labelmap already written onto DetectionLabelIdToTextCalculator from TFLite Model Metadata. Returns [] when the model has no label file. Reloads when setOptions() loads a new model.

Fixes #6294

Test plan

  • Unit tests in object_detector_test.ts: empty labelmap, EfficientDet-style labels, labels refresh after model swap
  • bazel test //mediapipe/tasks/web/vision/object_detector:object_detector_test
  • Manual: ObjectDetector.createFromOptions with efficientdet_lite0, then detector.getLabels() lists COCO classes (person, bicycle, car, …) without running detect()
  • Repeat with a custom .tflite that has metadata labels, then swap models via setOptions({ baseOptions: { modelAssetPath } }) and confirm getLabels() updates

Apps that swap custom detector models cannot list class names without
hardcoding them, because detect() only returns labels for objects that
fire. Read the labelmap already written onto DetectionLabelIdToTextCalculator
from TFLite Model Metadata, matching ImageSegmenter.getLabels().

Fixes google-ai-edge#6294
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.

[Feature Request] Extract supported labels from model at runtime

1 participant