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

Can we switch to torchvision v2 transforms? #1547

Open
cgebbe opened this issue May 21, 2024 · 2 comments
Open

Can we switch to torchvision v2 transforms? #1547

cgebbe opened this issue May 21, 2024 · 2 comments
Labels

Comments

@cgebbe
Copy link

cgebbe commented May 21, 2024

My understanding is that lightly uses the "old" v1 torchvision transforms, see e.g.

import torchvision.transforms as T

The v1 transforms have some drawbacks:

Would you accept a PR where we add the v2 versions? My understanding is that it's a drop-in replacement and that everything should stay the same, but I'd double check.

@IgorSusmelj
Copy link
Contributor

This is something we already thought about. We should check if would require us to update the minimal dependencies.
From https://github.com/lightly-ai/lightly/blob/master/requirements/minimal_requirements.txt

pytorch_lightning==1.7.1
torch==1.11.0
torchvision==0.12.0

I think torchvision introduced transforms v2 with 0.15.0 which would require us to bump both torch and torchvision.

@guarin
Copy link
Contributor

guarin commented May 22, 2024

Hi, adding support for v2 transforms sounds like a great idea. As @IgorSusmelj mentioned, lightly still supports older torchvision versions that do not yet support v2 transforms. I would suggest to add the following at the top of lightly.transforms.__init__:

try:
    # Use transforms v2 if available.
    import torchvision.transforms.v2 as torchvision_transforms
except ImportError:
    import torchvision.transforms as torchvision_transforms

And then replace code using the torchvision transforms in all files in lightly.transforms and lightly.collate:

# Replace this:
import torchvision.transforms as T
# With this:
import lightly.transforms.torchvision_transforms as T

This allows us to do the try/except check in a single place.

A PR would be very welcome (doesn't have to implement all the changes) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants