Skip to content

Choose either 'long' or 'short' options for the resize anchor edge if the size variable is scalar #8358

@sidijju

Description

@sidijju

🚀 The feature

Choose either 'long' or 'short' options for the resize anchor edge if the size variable is scalar

Motivation, pitch

torchvision.transforms.Resize() does not provide a clean interface for resizing images based off the longer edge.

Consider the following use case - a user wants to resize a set of images such that the dimensions are constrained by size, e.g. the longer edge of the images is always equal to size. Consider two images of size [1000, 500] and [500, 1000]. We want to resize both such that the maximum dimension is 500, e.g. resize the first image to [500, 250]and the second to [250, 500].

The naive method approach would be to set size = 500. As noted in the docs,

If size is an int, smaller edge of the image will be matched to this number.

But in both our cases, the smaller edge of the image is already 500 so this essentially does nothing.

Setting max_size = 500 also doesn't solve the issue since the current implementation specifically doesn't allow max_size == size in the code. While we could select a value for size that is less than max_size, there's no clear way to pick a value of size that would result in the desired effect.

Right now there's no clean way to resize images based solely off the size of the longer edge. Adding the ability to pick the resize anchor edge would allow this.

Alternatives

No response

Additional context

A similar comment was made in #2868, but it seems like the discussion about the longer edge was lost in the final implementation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions