Skip to content

Ten crop annotation #7254

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
merged 3 commits into from
Feb 15, 2023
Merged

Ten crop annotation #7254

merged 3 commits into from
Feb 15, 2023

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Feb 15, 2023

Towards #7159. Although we annotated as List[torch.Tensor]

def ten_crop(img: Tensor, size: List[int], vertical_flip: bool = False) -> List[Tensor]:

the addition of two tuples

second_five = five_crop(img, size)
return first_five + second_five

def five_crop(img: Tensor, size: List[int]) -> Tuple[Tensor, Tensor, Tensor, Tensor, Tensor]:

will also be a tuple.

Our docstrings also say as much:

Returns:
tuple: tuple (tl, tr, bl, br, center, tl_flip, tr_flip, bl_flip, br_flip, center_flip)

Returns:
tuple of 10 images. Image can be PIL Image or Tensor

It seems the automagic handling described in #7252 also kicks in for return types or otherwise the v1 script tests should have never passed.

cc @vfdev-5 @bjuncek

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Philip, if it fixes the original failure then let's get this in

Comment on lines +238 to +247
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
ImageOrVideoTypeJIT,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.... wow

Comment on lines +1982 to +1991
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh it keeps on giving 😅

@@ -234,7 +234,18 @@ def _check_inputs(self, flat_inputs: List[Any]) -> None:

def _transform(
self, inpt: Union[datapoints.ImageType, datapoints.VideoType], params: Dict[str, Any]
) -> Union[List[datapoints.ImageTypeJIT], List[datapoints.VideoTypeJIT]]:
) -> Tuple[
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all of this is ugly and verbose AF. We can also try to keep the List annotation (which we should have gone for in the first place).

Comment on lines +2027 to +2029
flipped = five_crop_image_pil(image, size)

return non_flipped + flipped
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual functional fix. v1 returned a tuple and so should v2.

@pmeier
Copy link
Collaborator Author

pmeier commented Feb 15, 2023

Test failures are unrelated.

@pmeier pmeier merged commit 316cc25 into pytorch:main Feb 15, 2023
@pmeier pmeier deleted the ten-crop-annotation branch February 15, 2023 14:07
@NicolasHug NicolasHug mentioned this pull request Feb 15, 2023
49 tasks
facebook-github-bot pushed a commit that referenced this pull request Mar 28, 2023
Reviewed By: vmoens

Differential Revision: D44416586

fbshipit-source-id: e506d56435133a7761f59a3ac9d0208f1fab4884
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants