Skip to content

Commit

Permalink
Remaining Transforms: Import version independent torchvision instead …
Browse files Browse the repository at this point in the history
…of defaulting to v1 (#1723)

* image grid transform: make v1 independent

* jigsaw: make v1 independent

* MAE: make v1 independent

* MSN: make v1 independent

* multicrop: make v1 independent

* multiview: make v1 independent

* PIRL: make v1 independent

* random crop/flip: make v1 independent

* random rotation: make v1 independent

* simclr transform: make v1 independent

* SimSiam transform: make v1 independent

* SMoG: make v1 independent

* SwaV: make v1 independent

* VICReg: make v1 independent

* VICRegL: make v1 independent

* WMSE: make v1 independent

* fix formatting
  • Loading branch information
liopeer authored Nov 7, 2024
1 parent 2e2d11a commit a1923e4
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 19 deletions.
3 changes: 2 additions & 1 deletion lightly/transforms/image_grid_transform.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import List, Sequence, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T


class ImageGridTransform:
"""Transforms an image into multiple views and grids.
Expand Down
3 changes: 2 additions & 1 deletion lightly/transforms/jigsaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from PIL import Image as Image
from PIL.Image import Image as PILImage
from torch import Tensor
from torchvision import transforms as T

from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T

if TYPE_CHECKING:
from numpy.typing import NDArray
Expand Down
2 changes: 1 addition & 1 deletion lightly/transforms/mae_transform.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Dict, List, Tuple, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
2 changes: 1 addition & 1 deletion lightly/transforms/msn_transform.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Dict, List, Optional, Tuple, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
3 changes: 1 addition & 2 deletions lightly/transforms/multi_crop_transform.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import Tuple

import torchvision.transforms as T

from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T


class MultiCropTranform(MultiViewTransform):
Expand Down
3 changes: 2 additions & 1 deletion lightly/transforms/multi_view_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from PIL.Image import Image
from torch import Tensor
from torchvision import transforms as T

from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T


class MultiViewTransform:
Expand Down
3 changes: 1 addition & 2 deletions lightly/transforms/pirl_transform.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Dict, List, Tuple, Union

import torchvision.transforms as T

from lightly.transforms.jigsaw import Jigsaw
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.rotation import random_rotation_transform
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
3 changes: 2 additions & 1 deletion lightly/transforms/random_crop_and_flip_with_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from typing import Tuple

import torch
import torchvision.transforms as T
import torchvision.transforms.functional as F
from PIL import Image
from torch import nn

from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T


@dataclass
class Location:
Expand Down
3 changes: 2 additions & 1 deletion lightly/transforms/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from typing import Callable, Tuple, Union

import numpy as np
import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor
from torchvision.transforms import functional as TF

from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T


class RandomRotate:
"""Implementation of random rotation.
Expand Down
2 changes: 1 addition & 1 deletion lightly/transforms/simclr_transform.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict, List, Optional, Tuple, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.rotation import random_rotation_transform
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
2 changes: 1 addition & 1 deletion lightly/transforms/simsiam_transform.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict, List, Optional, Tuple, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.rotation import random_rotation_transform
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
2 changes: 1 addition & 1 deletion lightly/transforms/smog_transform.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict, List, Optional, Tuple, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.solarize import RandomSolarization
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
2 changes: 1 addition & 1 deletion lightly/transforms/swav_transform.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict, List, Optional, Tuple, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_crop_transform import MultiCropTranform
from lightly.transforms.rotation import random_rotation_transform
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
2 changes: 1 addition & 1 deletion lightly/transforms/vicreg_transform.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Dict, List, Optional, Tuple, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.rotation import random_rotation_transform
from lightly.transforms.solarize import RandomSolarization
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
2 changes: 1 addition & 1 deletion lightly/transforms/vicregl_transform.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Dict, List, Optional, Tuple, Union

import torchvision.transforms as T
from PIL.Image import Image
from torch import Tensor

from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.image_grid_transform import ImageGridTransform
from lightly.transforms.random_crop_and_flip_with_grid import RandomResizedCropAndFlip
from lightly.transforms.solarize import RandomSolarization
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down
3 changes: 1 addition & 2 deletions lightly/transforms/wmse_transform.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Dict, List, Optional, Tuple

import torchvision.transforms as T

from lightly.transforms.gaussian_blur import GaussianBlur
from lightly.transforms.multi_view_transform import MultiViewTransform
from lightly.transforms.torchvision_v2_compatibility import torchvision_transforms as T
from lightly.transforms.utils import IMAGENET_NORMALIZE


Expand Down

0 comments on commit a1923e4

Please sign in to comment.