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

Allow v1/v2 independent import of torchvision.transforms #1717

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lightly/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
TiCoView1Transform,
TiCoView2Transform,
)
from lightly.transforms.torchvision_transforms import torchvision_transforms
from lightly.transforms.vicreg_transform import VICRegTransform, VICRegViewTransform
from lightly.transforms.vicregl_transform import VICRegLTransform, VICRegLViewTransform
from lightly.transforms.wmse_transform import WMSETransform
22 changes: 22 additions & 0 deletions lightly/transforms/torchvision_transforms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) Lightly AG and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from typing import Union

import torch
from PIL.Image import Image
from torch import Tensor

try:
from torchvision.transforms import v2 as torchvision_transforms

_TRANSFORMS_V2 = True

except ImportError:
from torchvision import transforms as torchvision_transforms

Check warning on line 20 in lightly/transforms/torchvision_transforms.py

View check run for this annotation

Codecov / codecov/patch

lightly/transforms/torchvision_transforms.py#L19-L20

Added lines #L19 - L20 were not covered by tests

_TRANSFORMS_V2 = False

Check warning on line 22 in lightly/transforms/torchvision_transforms.py

View check run for this annotation

Codecov / codecov/patch

lightly/transforms/torchvision_transforms.py#L22

Added line #L22 was not covered by tests