-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Adding support of Video to remaining Transforms and Kernels #6724
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
ec20920
ae8b31c
8c383fb
1b78d0a
6fe3c7f
123856b
99b529e
d896c3d
fb4b76e
25cacbd
7e7701d
9cbec19
11bc8c2
d502942
ac58aec
da98c37
5f33ef1
93f697b
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 |
---|---|---|
|
@@ -155,12 +155,13 @@ class FiveCrop(Transform): | |
""" | ||
Example: | ||
>>> class BatchMultiCrop(transforms.Transform): | ||
... def forward(self, sample: Tuple[Tuple[features.Image, ...], features.Label]): | ||
... images, labels = sample | ||
... batch_size = len(images) | ||
... images = features.Image.wrap_like(images[0], torch.stack(images)) | ||
... def forward(self, sample: Tuple[Tuple[Union[features.Image, features.Video], ...], features.Label]): | ||
... images_or_videos, labels = sample | ||
... batch_size = len(images_or_videos) | ||
... image_or_video = images_or_videos[0] | ||
... images_or_videos = image_or_video.wrap_like(image_or_video, torch.stack(images_or_videos)) | ||
... labels = features.Label.wrap_like(labels, labels.repeat(batch_size)) | ||
... return images, labels | ||
... return images_or_videos, labels | ||
... | ||
>>> image = features.Image(torch.rand(3, 256, 256)) | ||
pmeier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
>>> label = features.Label(0) | ||
|
@@ -172,15 +173,21 @@ class FiveCrop(Transform): | |
torch.Size([5]) | ||
""" | ||
|
||
_transformed_types = (features.Image, PIL.Image.Image, features.is_simple_tensor) | ||
_transformed_types = (features.Image, PIL.Image.Image, features.is_simple_tensor, features.Video) | ||
|
||
def __init__(self, size: Union[int, Sequence[int]]) -> None: | ||
super().__init__() | ||
self.size = _setup_size(size, error_msg="Please provide only two dimensions (h, w) for size.") | ||
|
||
def _transform( | ||
self, inpt: features.ImageType, params: Dict[str, Any] | ||
) -> Tuple[features.ImageType, features.ImageType, features.ImageType, features.ImageType, features.ImageType]: | ||
self, inpt: features.ImageOrVideoType, params: Dict[str, Any] | ||
) -> Tuple[ | ||
features.ImageOrVideoType, | ||
features.ImageOrVideoType, | ||
features.ImageOrVideoType, | ||
features.ImageOrVideoType, | ||
features.ImageOrVideoType, | ||
]: | ||
Comment on lines
+184
to
+190
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. Feel free to ignore if mypy is happy This is not accurate. We don't have 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. This is why IMO we should avoid |
||
return F.five_crop(inpt, self.size) | ||
|
||
def forward(self, *inputs: Any) -> Any: | ||
|
@@ -194,14 +201,14 @@ class TenCrop(Transform): | |
See :class:`~torchvision.prototype.transforms.FiveCrop` for an example. | ||
""" | ||
|
||
_transformed_types = (features.Image, PIL.Image.Image, features.is_simple_tensor) | ||
_transformed_types = (features.Image, PIL.Image.Image, features.is_simple_tensor, features.Video) | ||
|
||
def __init__(self, size: Union[int, Sequence[int]], vertical_flip: bool = False) -> None: | ||
super().__init__() | ||
self.size = _setup_size(size, error_msg="Please provide only two dimensions (h, w) for size.") | ||
self.vertical_flip = vertical_flip | ||
|
||
def _transform(self, inpt: features.ImageType, params: Dict[str, Any]) -> List[features.ImageType]: | ||
def _transform(self, inpt: features.ImageOrVideoType, params: Dict[str, Any]) -> List[features.ImageOrVideoType]: | ||
datumbox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return F.ten_crop(inpt, self.size, vertical_flip=self.vertical_flip) | ||
|
||
def forward(self, *inputs: Any) -> Any: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,10 @@ def get_spatial_size_image_pil(image: PIL.Image.Image) -> List[int]: | |
return [height, width] | ||
|
||
|
||
# TODO: Should we have get_spatial_size_video here? How about masks/bbox etc? What is the criterion for deciding when | ||
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.
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've already updated I think you are trying to answer a different question from what I ask here. What I think we should discuss is whether there should be specific kernels for each type, unrelated to whether the dispatcher can handle everything. We already have kernels (like 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. Ah, sorry, yes I was confused. That is a good question and I don't have an answer for it yet. My gut says that we should stay consistent and provide the kernels just as we do for the other transforms. 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. Same feeling here. I'll leave the TODO for the follow up. I think we can answer this on the PR where we switch |
||
# a kernel will be created? | ||
|
||
|
||
def get_spatial_size(inpt: features.InputTypeJIT) -> List[int]: | ||
if isinstance(inpt, torch.Tensor) and (torch.jit.is_scripting() or not isinstance(inpt, features._Feature)): | ||
return get_spatial_size_image_tensor(inpt) | ||
|
@@ -246,7 +250,7 @@ def convert_color_space( | |
): | ||
if old_color_space is None: | ||
raise RuntimeError( | ||
"In order to convert the color space of simple tensor images, " | ||
"In order to convert the color space of simple tensors, " | ||
"the `old_color_space=...` parameter needs to be passed." | ||
) | ||
return convert_color_space_image_tensor( | ||
|
Uh oh!
There was an error while loading. Please reload this page.