Skip to content
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

Improved RandomShortestSize Functionality #8684

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions torchvision/transforms/v2/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,9 +1329,15 @@ def __init__(

def make_params(self, flat_inputs: List[Any]) -> Dict[str, Any]:
orig_height, orig_width = query_size(flat_inputs)
min_o_size = min(orig_height, orig_width)

min_size = self.min_size[int(torch.randint(len(self.min_size), ()))]
r = min_size / min(orig_height, orig_width)
if len(self.min_size) == 1:
min_size = self.min_size[0]
assert min_size <= min_o_size
min_size = torch.empty(1).uniform_(min_size, min_o_size).int()
else:
min_size = self.min_size[int(torch.randint(len(self.min_size), ()))]
r = min_size / min_o_size
if self.max_size is not None:
r = min(r, self.max_size / max(orig_height, orig_width))

Expand Down