Fix OpenCV video loader normalization scale - #603
Conversation
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
There was a problem hiding this comment.
Pull request overview
Fixes inconsistent normalization for the OpenCV (cv2) video-file loader by scaling decoded uint8 frames into [0, 1] before applying img_mean/img_std, aligning it with the other image/video input paths.
Changes:
- Scale cv2-decoded video frames by
1/255prior to normalization. - Add a regression test that generates a tiny temporary MJPG video and checks cv2 loader output against manually normalized decoded frames.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
sam3/model/io_utils.py |
Applies the missing /255.0 scaling step in the cv2 video loader before mean/std normalization. |
test/test_io_utils.py |
Adds a regression test that writes/reads a small cv2 video and compares loader output to an independently normalized decode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
74490bd to
a2771fb
Compare
|
Updated this PR to address the Copilot review comments:
Validation rerun:
|
a2771fb to
8cd357a
Compare
8cd357a to
323a42f
Compare
The OpenCV video-file loader normalized decoded uint8 frames without first scaling them to [0, 1]. Other image/video input paths divide by 255 before applying image_mean/image_std, so cv2-loaded videos could enter the model at a different scale.
This PR adds the missing scaling step and a generated temporary-video regression test that verifies the cv2 loader output against normalized decoded frames.
Validation:
/home/skapoor/oss_work/.venvs/sam3/bin/python -m pytest test/test_io_utils.py -q/home/skapoor/oss_work/.venvs/sam3/bin/python -m py_compile sam3/model/io_utils.py test/test_io_utils.py