-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[prototype] Fix BC-breakages on input params of F
#6636
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
Merged
datumbox
merged 23 commits into
pytorch:main
from
datumbox:prototype/fix-function-signatures
Sep 28, 2022
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e41e405
Fix `size` in resize.
datumbox 45fbf87
Merge branch 'main' into prototype/fix-function-signatures
datumbox dd528d9
Update torchvision/prototype/features/_bounding_box.py
datumbox 4b49089
Address some of the comments.
datumbox 0128a3a
Fix `output_size` in center_crop.
datumbox e3f93fb
Fix `CenterCrop` transform
datumbox 5d45374
Fix `size` in five_crop.
datumbox 9fb9db7
Fix `size` in ten_crop.
datumbox 37b415e
Fix `kernel_size` and `sigma` in gaussian_blur.
datumbox 0f16b84
Fix `angle` and `shear` in affine.
datumbox df5a832
Fixing JIT-scriptability issues.
datumbox 5dec03d
Update TODOs.
datumbox e848b40
Merge branch 'main' into prototype/fix-function-signatures
datumbox 6a0c24b
Merge branch 'main' into prototype/fix-function-signatures
datumbox 59d5166
Restore fake types for `Union[int, List[int]]` and `Union[int, float,…
datumbox 58867f0
Merge branch 'main' into prototype/fix-function-signatures
datumbox ea0bc55
Fixing tests
datumbox d62f1eb
Fix linter
datumbox 28119be
revert unnecessary JIT mitigations.
datumbox f0d9d85
Cherrypick Philip's 6dfc9657ce89fe9e018a11ee25a8e26c7d3d43c6
datumbox 350d47c
Linter fix
datumbox 1d2ae82
Adding center float casting
datumbox 352b72d
Merge branch 'main' into prototype/fix-function-signatures
pmeier 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
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
from torchvision.prototype import features | ||
from torchvision.prototype.transforms import functional as F, Transform | ||
|
||
from ._utils import _setup_size, has_any, query_bounding_box | ||
from ._utils import _setup_float_or_seq, _setup_size, has_any, query_bounding_box | ||
|
||
|
||
class Identity(Transform): | ||
|
@@ -112,25 +112,25 @@ def forward(self, *inpts: Any) -> Any: | |
|
||
class GaussianBlur(Transform): | ||
def __init__( | ||
self, kernel_size: Union[int, Sequence[int]], sigma: Union[float, Sequence[float]] = (0.1, 2.0) | ||
self, kernel_size: Union[int, Sequence[int]], sigma: Union[int, float, Sequence[float]] = (0.1, 2.0) | ||
) -> None: | ||
super().__init__() | ||
self.kernel_size = _setup_size(kernel_size, "Kernel size should be a tuple/list of two integers") | ||
for ks in self.kernel_size: | ||
if ks <= 0 or ks % 2 == 0: | ||
raise ValueError("Kernel size value should be an odd and positive number.") | ||
|
||
if isinstance(sigma, float): | ||
if isinstance(sigma, (int, float)): | ||
if sigma <= 0: | ||
raise ValueError("If sigma is a single number, it must be positive.") | ||
sigma = (sigma, sigma) | ||
sigma = float(sigma) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the |
||
elif isinstance(sigma, Sequence) and len(sigma) == 2: | ||
if not 0.0 < sigma[0] <= sigma[1]: | ||
raise ValueError("sigma values should be positive and of the form (min, max).") | ||
else: | ||
raise TypeError("sigma should be a single float or a list/tuple with length 2 floats.") | ||
raise TypeError("sigma should be a single int or float or a list/tuple with length 2 floats.") | ||
|
||
self.sigma = sigma | ||
self.sigma = _setup_float_or_seq(sigma, "sigma", 2) | ||
|
||
def _get_params(self, sample: Any) -> Dict[str, Any]: | ||
sigma = torch.empty(1).uniform_(self.sigma[0], self.sigma[1]).item() | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,23 @@ | |
from typing_extensions import Literal | ||
|
||
|
||
def _setup_float_or_seq(arg: Union[float, Sequence[float]], name: str, req_size: int = 2) -> Sequence[float]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved as-is. |
||
if not isinstance(arg, (float, Sequence)): | ||
raise TypeError(f"{name} should be float or a sequence of floats. Got {type(arg)}") | ||
if isinstance(arg, Sequence) and len(arg) != req_size: | ||
raise ValueError(f"If {name} is a sequence its length should be one of {req_size}. Got {len(arg)}") | ||
if isinstance(arg, Sequence): | ||
for element in arg: | ||
if not isinstance(element, float): | ||
raise ValueError(f"{name} should be a sequence of floats. Got {type(element)}") | ||
|
||
if isinstance(arg, float): | ||
arg = [float(arg), float(arg)] | ||
if isinstance(arg, (list, tuple)) and len(arg) == 1: | ||
arg = [arg[0], arg[0]] | ||
return arg | ||
|
||
|
||
def _check_fill_arg(fill: Union[FillType, Dict[Type, FillType]]) -> None: | ||
if isinstance(fill, dict): | ||
for key, value in fill.items(): | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.