-
Notifications
You must be signed in to change notification settings - Fork 7.1k
add consistency tests for prototype container transforms #6525
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import warnings | ||
from typing import Any, Callable, Dict, List, Optional, Sequence | ||
from typing import Any, Callable, List, Optional, Sequence | ||
|
||
import torch | ||
from torchvision.prototype.transforms import Transform | ||
|
||
from ._transform import _RandomApplyTransform | ||
|
||
|
||
class Compose(Transform): | ||
def __init__(self, transforms: Sequence[Callable]) -> None: | ||
|
@@ -21,16 +19,21 @@ def forward(self, *inputs: Any) -> Any: | |
return sample | ||
|
||
|
||
class RandomApply(_RandomApplyTransform): | ||
def __init__(self, transform: Transform, p: float = 0.5) -> None: | ||
super().__init__(p=p) | ||
self.transform = transform | ||
class RandomApply(Compose): | ||
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. I don't really understand why 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. I agree. Maybe, we can extend 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. I think for now we should keep it and review on the future what we want to deprecate. It's true that many of the transforms can be written as a combination of other transforms. For example, the majority of the |
||
def __init__(self, transforms: Sequence[Callable], p: float = 0.5) -> None: | ||
super().__init__(transforms) | ||
|
||
if not (0.0 <= p <= 1.0): | ||
raise ValueError("`p` should be a floating point value in the interval [0.0, 1.0].") | ||
self.p = p | ||
|
||
def forward(self, *inputs: Any) -> Any: | ||
sample = inputs if len(inputs) > 1 else inputs[0] | ||
|
||
def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any: | ||
return self.transform(inpt) | ||
if torch.rand(1) >= self.p: | ||
return sample | ||
|
||
def extra_repr(self) -> str: | ||
return f"p={self.p}" | ||
return super().forward(sample) | ||
|
||
|
||
class RandomChoice(Transform): | ||
|
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.
We don't need to create the transform for ever image.