Skip to content

Fix #607: support older yolov5 versions lacking scale_boxes#659

Open
proofbyhuman wants to merge 1 commit into
microsoft:mainfrom
proofbyhuman:fix-607-yolov5-scale-boxes-import
Open

Fix #607: support older yolov5 versions lacking scale_boxes#659
proofbyhuman wants to merge 1 commit into
microsoft:mainfrom
proofbyhuman:fix-607-yolov5-scale-boxes-import

Conversation

@proofbyhuman

Copy link
Copy Markdown

Summary

PytorchWildlife/models/detection/ultralytics_based/yolov5_base.py imported
scale_boxes from yolov5.utils.general, which raises ImportError on older
yolov5 releases where the helper is named scale_coords. Since yolov5 is an
unpinned dependency (setup.py, requirements.txt), users can end up with
either name, breaking import PytorchWildlife.

Changes

  • Wrapped the import in a try/except ImportError that falls back to
    scale_coords as scale_boxes (same signature), so both older and newer
    yolov5 versions work. No dependency changes required.

Testing

Simulated both a "old" yolov5 (only scale_coords) and a "new" one (with
scale_boxes) and confirmed the import resolves scale_boxes correctly in both
cases. py_compile passes.

Closes #607

AI assistance

Diagnosis and implementation were done with AI assistance (Claude).

yolov5_base.py imported `scale_boxes` from `yolov5.utils.general`, which fails
with `ImportError` on older yolov5 releases where the helper is named
`scale_coords` (it was later renamed to `scale_boxes` with the same signature).
Since `yolov5` is an unpinned dependency, users could end up with either name.

Wrap the import in a try/except that falls back to `scale_coords as scale_boxes`,
so both older and newer yolov5 versions work.

Closes microsoft#607

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

Error importing scale_boxes

1 participant