-
Notifications
You must be signed in to change notification settings - Fork 66
Decoder-native resize public implementation #1003
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
Open
scotts
wants to merge
15
commits into
meta-pytorch:main
Choose a base branch
from
scotts:transform_api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
dd24dfa
Decoder-native resize public implementation
scotts 3a2df84
Lint
scotts 5344ab4
Merge branch 'main' of github.com:pytorch/torchcodec into transform_api
scotts 98cf81b
Implement decoder native transforms API
scotts 65c4ad7
Correct merge
scotts f300c70
Actually add new file
scotts 2c3b7f0
Lint
scotts 80e84b5
Better assert
scotts 5ac60d8
Better comment
scotts 531b40f
Top level transforms import
scotts cc333ac
Add the init file. Sigh.
scotts 238a8ff
Linter now needs torchvision in the environment
scotts 55d362c
Avoid missing import errors
scotts 0d2492e
Better names, better docs
scotts a2da767
More testing, docstring editing
scotts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| from ._decoder_transforms import DecoderTransform, Resize # noqa |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from dataclasses import dataclass | ||
| from typing import Sequence | ||
|
|
||
|
|
||
| @dataclass | ||
| class DecoderTransform(ABC): | ||
| """Base class for all decoder transforms. | ||
|
|
||
| A DecoderTransform is a transform that is applied by the decoder before | ||
| returning the decoded frame. The implementation does not live in TorchCodec | ||
| itself, but in the underyling decoder. Applying DecoderTransforms to frames | ||
| should be both faster and more memory efficient than receiving normally | ||
| decoded frames and applying the same kind of transform. | ||
|
|
||
| Most DecoderTransforms have a complementary transform in TorchVision, | ||
| specificially in torchvision.transforms.v2. For such transforms, we ensure | ||
| that: | ||
|
|
||
| 1. Default behaviors are the same. | ||
| 2. The parameters for the DecoderTransform are a subset of the | ||
| TorchVision transform. | ||
| 3. Parameters with the same name control the same behavior and accept a | ||
| subset of the same types. | ||
| 4. The difference between the frames returned by a DecoderTransform and | ||
| the complementary TorchVision transform are small. | ||
|
|
||
| All DecoderTranforms are applied in the output pixel format and colorspace. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def make_params(self) -> str: | ||
| pass | ||
|
|
||
|
|
||
| @dataclass | ||
| class Resize(DecoderTransform): | ||
| """Resize the decoded frame to a given size. | ||
|
|
||
| Complementary TorchVision transform: torchvision.transforms.v2.Resize. | ||
| Interpolation is always bilinear. Anti-aliasing is always on. | ||
|
|
||
| Args: | ||
| size: (sequence of int): Desired output size. Must be a sequence of | ||
| the form (height, width). | ||
| """ | ||
|
|
||
| size: Sequence[int] | ||
|
|
||
| def make_params(self) -> str: | ||
| assert len(self.size) == 2 | ||
| return f"resize, {self.size[0]}, {self.size[1]}" |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
I was getting linting errors like: https://github.com/meta-pytorch/torchcodec/actions/runs/19157614790/job/54761644331
Which points to docs which recommend the above change: https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports