Skip to content

Add torchvision.transforms.Resize interpolation and antialias. #1441

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 6 commits into from
Apr 10, 2025

Conversation

hiyuh
Copy link
Contributor

@hiyuh hiyuh commented Feb 3, 2025

torchvision.transforms.Resize forced nearest interpolation and no antialias, but shouln't.
Based on my understanding, original torchvision.transforms.Resize calls like;

  • torchvision.transforms.Resize
    • torchvision.transforms.functional.resize
      • torchvision.transforms._functional_pil.resize
        • PIL.Image.Image.resize
      • torchvision.transforms._functional_tensor.resize
        • torch.nn.functional.interpolate

Note, this PR still keeps nearest interpolation and no antialias by default for torchvision.transforms.Resize to maximize compatibility for existing code using TorchSharp and results in incompatible to original torchvision.transforms.Resize default, however, it would be up to the upstream decision.
See also;

@hiyuh
Copy link
Contributor Author

hiyuh commented Feb 5, 2025

@dotnet-policy-service agree company="HACARUS"

@alinpahontu2912
Copy link
Member

Hey @hiyuh, can you rebase and update releasenotes?

@hiyuh hiyuh force-pushed the add-Resize-interpolation-antialias branch from edfd4f5 to f6d6213 Compare March 25, 2025 14:16
@hiyuh
Copy link
Contributor Author

hiyuh commented Mar 25, 2025

@alinpahontu2912
done, please go ahead.

@ozanMSFT
Copy link
Contributor

I added a few more comments.

@hiyuh I have some concerns regarding the compatibility between the current TorchSharp's TorchVision and your changes. Could you specify in which version of TorchVision the antialias parameter was introduced, and whether it is compatible with the current TorchSharp's native dependencies?

@ozanMSFT
Copy link
Contributor

@hiyuh ; if you can give us permission for your branch as following setting, we can also resolve some RELEASENOTES conflicts on behalf of you:

image

NOTE: We're planning a solution for the releasenotes conflicts.

@hiyuh
Copy link
Contributor Author

hiyuh commented Mar 28, 2025

@ozanMSFT

  • regarding your review comments on several source codes, let me try to improve, so wait a moment.
  • about allowing maintaner's change on pulll request, from my best knowledge, it's unavailble option if the forked branch is under organization.
    • next time, i can work under my account (not my organization) if you guys preferred.

@hiyuh
Copy link
Contributor Author

hiyuh commented Mar 31, 2025

@ozanMSFT

Could you specify in which version of TorchVision the antialias parameter was introduced, and whether it is compatible with the current TorchSharp's native dependencies?

@hiyuh hiyuh requested a review from ozanMSFT March 31, 2025 23:54
Masaru Kimura added 6 commits April 9, 2025 15:19
torchvision.transforms.Resize forced nearest interpolation and no antialias,
but shouln't.
Based on my understanding, original torchvision.transforms.Resize calls like;
- torchvision.transforms.Resize
  - torchvision.transforms.functional.resize
    - torchvision.transforms._functional_pil.resize
      - PIL.Image.Image.resize
    - torchvision.transforms._functional_tensor.resize
      - torch.nn.functional.interpolate
Note, this PR still keeps nearest interpolation and no antialias by default
for torchvision.transforms.Resize to maximize compatibility for existing
code using TorchSharp and make it being incompatible to original
torchvision.transforms.Resize default, however, it would be up to
the upstream decision.
See also;
* https://pytorch.org/vision/main/generated/torchvision.transforms.Resize.html
* https://pytorch.org/vision/main/generated/torchvision.transforms.functional.resize.html
* https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html
@hiyuh hiyuh force-pushed the add-Resize-interpolation-antialias branch from 91212e7 to 5d0ab74 Compare April 9, 2025 06:22
@hiyuh
Copy link
Contributor Author

hiyuh commented Apr 9, 2025

@ozanMSFT

  • rebased onto main, to resolve RELEASENOTES.md conflict as usual.

@ozanMSFT
Copy link
Contributor

ozanMSFT commented Apr 9, 2025

@hiyuh , thanks for addressing the all comments. Great contribution!

Currently, I'm observing some build errors but I'm not sure if it is relevant to your PR or there is another error. I'm investigating the issue.

Copy link
Contributor

@ozanMSFT ozanMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

Note for future: We can improve the tests if they fail due to float precision but for now they are working fine.

@ozanMSFT ozanMSFT merged commit 8c88fd0 into dotnet:main Apr 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants