Fix dimension indexing in separation_content_motion()#32
Open
Mr-Neutr0n wants to merge 1 commit intoVchitect:mainfrom
Open
Fix dimension indexing in separation_content_motion()#32Mr-Neutr0n wants to merge 1 commit intoVchitect:mainfrom
Mr-Neutr0n wants to merge 1 commit intoVchitect:mainfrom
Conversation
The function was incorrectly indexing dimension 0 (batch) instead of dimension 1 (frames) when extracting the base frame and computing motion differences. This caused incorrect results for any batch size other than the number of frames, and would fail entirely when batch and frame dimensions differed. Fix by using proper slicing along the frame dimension (dim=1): - base_frame: video_clip[:, 0:1] instead of video_clip[0] - motions: video_clip[:, 1:] - video_clip[:, 0:1] instead of iterating over batch indices This also simplifies the motion computation by using vectorized subtraction and removes the unnecessary torch.cat call.
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
separation_content_motion()inutils.pyincorrectly indexes dimension 0 (batch) instead of dimension 1 (frames) when separating a video clip into its base frame and motion components.Bug: The original code uses
video_clip[0]andvideo_clip[i], which index into the batch dimension. According to the docstring, the input shape is[B, F, C, H, W], so frames live on dimension 1.Before (broken):
After (fixed):
This also simplifies the motion computation by replacing the loop +
torch.catwith a single vectorized subtraction, which is both cleaner and more efficient.Test plan
[B, 1, C, H, W]for base frame and[B, F-1, C, H, W]for motions