-
Couldn't load subscription status.
- Fork 66
Create Python API for VideoEncoder #990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
test/test_encoders.py
Outdated
| (torch.rand(num_frames, channels, height, width) * 255) | ||
| .to(torch.uint8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use torch.randint(0, 256, size=(num_frames, channels, height, width), dtype=torch.uint8).contiguous()
| contiguous_frames.permute(0, 3, 2, 1).contiguous().permute(0, 3, 2, 1) | ||
| ) | ||
| assert non_contiguous_frames.stride() != contiguous_frames.stride() | ||
| assert not non_contiguous_frames.is_contiguous() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but you should be able to check for this which is stricter:
assert non_contiguous_frames.is_contiguous(memory_format=torch.channels_last)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, I have assumed frames will be in NCHW format. This shape is retained after the permutations, so I do not believe channels_last applies here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The frames are always of NCHW shape . But internally they can have any arbitrary memory layout (format). These are mostly orthogonal concepts, i.e. frames can have NCHW shape while still being represented as NHWC layout (channels last).
I realize now the non_contiguous_frames you created are indeed not channels last. But we can force them to be by changing to:
contiguous_frames.permute(0, 2, 3, 1).contiguous().permute(0, 3, 1, 2)and you should see that assert non_contiguous_frames.is_contiguous(memory_format=torch.channels_last) is passing now. Note how we're now permuting the channels dimension from N*HW to NHW*, and back.
Your test was still correct BTW - I just think it's good to actually explicitly check for channels_last because this is how frames may arrive.
3c6fd84 to
ee2285e
Compare
This PR creates a simple
VideoEncoderclass, and updates several tests to utilize theVideoEncoder.to_filepattern.test_bad_input_parameterizedis theVideoEncoderequivalent to the AudioEncoder test that ensures general error checking occurs, while test_bad_input tests method specific errors.test_contiguity: is theVideoEncoderequivalent to the AudioEncoder test to ensure contiguous and non-contiguous tensors can be encoded, and are encoded equivalently.