fix(rfdetr): honor --show-boxes instead of ignoring it - #2024
Conversation
|
The red
This PR touches only |
|
@Anai-Guo Need signed commits |
The rfdetr generate CLI parsed --show-boxes but never passed it down, so boxes were always drawn. Re-created as a single GPG-signed commit; tree is unchanged.
c574cb6 to
e82d557
Compare
|
Also re-signed this one while I was at it (single GPG-signed commit, |
Problem
The RF-DETR CLI declares
--show-boxeswithhelp="Show bounding boxes and labels (default: on)", but the parsed value is never used.show_boxesas an identifier appears nowhere inmlx_vlm/models/rfdetr/outside that oneadd_argumentcall:Two things are wrong, and the file itself supplies the baseline for both:
The value never reaches the annotator. The adjacent
--show-fpsflag in the very same parser is threaded through (predict_video(..., show_fps=args.show_fps)atgenerate.py:802). Both sibling backends honorshow_boxestoo —sam3/generate.pypassesargs.show_boxesinto three call sites, andsam3_1/generate.pythreads it down todraw_frame.The flag could not be turned off even once wired up. It is
action="store_true"withdefault=True, so passing--show-boxesis a no-op and there is no way to get boxes off.sam3_1/generate.py:1002-1003pairs exactly this flag with a--no-show-boxesdual; the RF-DETR parser only has the positive half.Net effect: a user following the documented
(default: on)wording has no way to render mask-only segment output, which is the one thing the option exists for.Fix
_get_annotator()takesshow_boxes: bool = True. When it is off, the default segment chain keepsMaskAnnotatorand dropsBoxAnnotator/LabelAnnotator— the same meaningsam3/generate.pydocuments fordraw_frame: "If False, draw only mask overlays + contours (no boxes/labels)."show_boxes=args.show_boxes if args.task == "segment" else True, and avoids rendering an empty overlay.--annotatorchain still wins, since it names the annotators outright.--no-show-boxes(dest="show_boxes",action="store_false"), matchingsam3_1/generate.py.The default path is unchanged. With
show_boxes=Truethe chain is the sameMaskAnnotator + BoxAnnotator + LabelAnnotatoras before, and the two internal_get_annotator(None, ...)calls inpredict_video/predict_realtimekeep the default.Verification
mlxis Apple-silicon only, so I exercised the real module on another platform by stubbingmlxalone and importingmlx_vlm/models/rfdetr/generate.pyunmodified —sam3/annotators.pyis numpy+cv2 only, so the annotator chain under test is the real one, not a mock.Before the change (3 of the 4 new tests fail):
After:
4 passed.test_show_boxes_defaults_to_onis the one that passes on both sides — it pins the unchanged default chain so this stays a no-op for existing invocations.Observed chains:
show_boxesTrue(default)MaskAnnotator, BoxAnnotator, LabelAnnotatorFalseMaskAnnotatorBoxAnnotator, LabelAnnotatorblack==26.3.1,isort==5.13.2andautoflake==2.2.1(the pinned.pre-commit-config.yamlrevisions) leave both files unchanged.Not in scope
sam3/generate.pydeclares--show-boxeswithoutdefault=True, so it defaults to off there and is already honored — I left its semantics alone rather than unifying the two defaults, since that would change existing sam3 output.🤖 Generated with Claude Code