refactor: standardize naming and imports of Detections across modules#1091
Open
Borda wants to merge 2 commits into
Open
refactor: standardize naming and imports of Detections across modules#1091Borda wants to merge 2 commits into
Detections across modules#1091Borda wants to merge 2 commits into
Conversation
- `yolo.py`: replace `cv2.imread` with `PIL.Image.open(...).convert("RGB")`; removes implicit BGR→RGB flip; rename `cv2_image` → `rgb_image`/`image_array` throughout
- `synthetic.py`: replace `cv2.imwrite` with `Image.fromarray(img[..., ::-1]).save()`; explicit BGR→RGB flip preserved since supervision draws in BGR order
- `test_yolo.py`: update mock targets from `cv2.imread` to `Image.Image.convert`; replace return-None mock with on-disk corruption for more realistic failure test
---
Co-authored-by: Claude Code <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors RF-DETR’s integrations with the supervision library to use direct symbol imports (e.g., Detections, BoxAnnotator) instead of import supervision as sv, and standardizes image I/O on PIL.Image (replacing OpenCV-based loading where applicable). It also updates related type annotations/docstrings and adjusts tests to assert that lazy datasets don’t decode pixel buffers during initialization.
Changes:
- Replaced
sv.*usages with directsupervisionimports across visualization, export inference helpers, datasets, and the mainRFDETR.predicttyping surface. - Switched YOLO lazy image loading from
cv2.imreadtoPIL.Image.open(...).convert("RGB"), and updated tests to validate “no pixel decode during init” behavior. - Updated synthetic dataset generation to save images via PIL while accounting for channel-order differences.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
tests/datasets/test_yolo.py |
Updates lazy-mask tests to assert no pixel-buffer decode during dataset init and to simulate unreadable images with PIL. |
src/rfdetr/visualize/data.py |
Converts visualization helpers to direct supervision imports and removes sv alias usage. |
src/rfdetr/models/backbone/projector.py |
Renames internal conv module attributes (cv1/cv2 → conv1/conv2) in backbone projector blocks. |
src/rfdetr/export/_tflite/inference.py |
Uses direct Detections import and updates return typing/construction accordingly. |
src/rfdetr/export/_onnx/inference.py |
Uses direct Detections import and updates return typing/construction accordingly. |
src/rfdetr/detr.py |
Updates type-checking imports and runtime usage to remove sv alias for Detections. |
src/rfdetr/datasets/yolo.py |
Replaces cv2-based image reads with PIL, keeps metadata-only init behavior, and updates Detections typing/usage. |
src/rfdetr/datasets/synthetic.py |
Switches image writing from OpenCV to PIL and updates supervision imports/types. |
src/rfdetr/datasets/save_grids.py |
Refactors supervision usage to direct imports for annotators/colors/detections. |
Comment on lines
129
to
133
| c_ = int(c2 * e) # hidden channels | ||
| self.cv1 = ConvX(c1, c_, k[0], 1, act=act, layer_norm=layer_norm, rms_norm=rms_norm) | ||
| self.cv2 = ConvX(c_, c2, k[1], 1, groups=g, act=act, layer_norm=layer_norm, rms_norm=rms_norm) | ||
| self.conv1 = ConvX(c1, c_, k[0], 1, act=act, layer_norm=layer_norm, rms_norm=rms_norm) | ||
| self.conv2 = ConvX(c_, c2, k[1], 1, groups=g, act=act, layer_norm=layer_norm, rms_norm=rms_norm) | ||
| self.add = shortcut and c1 == c2 | ||
|
|
Comment on lines
145
to
149
| self.c = int(c2 * e) # hidden channels | ||
| self.cv1 = ConvX(c1, 2 * self.c, 1, 1, act=act, layer_norm=layer_norm, rms_norm=rms_norm) | ||
| self.cv2 = ConvX( | ||
| self.conv1 = ConvX(c1, 2 * self.c, 1, 1, act=act, layer_norm=layer_norm, rms_norm=rms_norm) | ||
| self.conv2 = ConvX( | ||
| (2 + n) * self.c, c2, 1, act=act, layer_norm=layer_norm, rms_norm=rms_norm | ||
| ) # optional act=FReLU(c2) |
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 refactors the codebase to use direct imports of specific classes and functions from the
supervisionlibrary instead of importing the entire module assv. This change improves code clarity and reduces unnecessary namespace usage. Additionally, the code now consistently usesPIL.Imagefor image I/O instead ofcv2, standardizing image handling across the project. Some docstrings and type annotations have also been updated to reflect these changes.Refactor: Use direct imports from
supervisioninstead of module aliassv.Detections,sv.Color,sv.BoxAnnotator,sv.LabelAnnotator,sv.box_iou_batch, andsv.draw_filled_polygonwith direct imports and usage ofDetections,Color,BoxAnnotator,LabelAnnotator,box_iou_batch, anddraw_filled_polygonthroughout the codebase. Updated type annotations and docstrings accordingly. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27]Image handling standardization
cv2.imreadand OpenCV BGR-to-RGB conversion withPIL.Image.openand direct RGB handling, ensuring consistency and correctness in image loading and saving. [1] [2] [3] [4]Documentation and type annotation updates
These changes collectively improve code clarity, maintainability, and consistency across the project.