Fix video preprocessing bug in OpenCV loader#522
Open
OrangeSodahub wants to merge 1 commit intofacebookresearch:mainfrom
Open
Fix video preprocessing bug in OpenCV loader#522OrangeSodahub wants to merge 1 commit intofacebookresearch:mainfrom
OrangeSodahub wants to merge 1 commit intofacebookresearch:mainfrom
Conversation
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.
Summary
This PR fixes a bug in the OpenCV video loader used for video-file inputs. Specifically, the function
load_video_frames_from_video_file_using_cv2insam3/sam3/model/io_utils.py
Lines 332 to 345 in 44ef224
where decoded video frames were normalized without first being scaled from
[0, 255]to[0, 1], even though the normalization parameters assume[0, 1]inputs. This leads to incorrectly scaled model inputs during video inference.While in image folder loadings,
/ 255.0is correctly placed:sam3/sam3/model/io_utils.py
Line 56 in 44ef224
And in torchcodec, too:
sam3/sam3/model/io_utils.py
Line 689 in 44ef224
Changes
255.0before mean/std normalizationValidation
imagestensor afterinit_stateas below is in [-1, 509] when loading mp4 video through opencv which is incorrect, and I have also seen the unusual resultssam3/sam3/model/sam3_video_inference.py
Lines 63 to 71 in 44ef224
imagestensor is always in [-1, 1], and the segmentation results are good