ImportError: cannot import name 'ToImage' from 'torchvision.transforms.v2' (D:\Miniconda\lib\site-packages\torchvision\transforms\v2\__init__.py)

#5
by father123 - opened

calling torchvision.disable_beta_transforms_warning().
warnings.warn(BETA_TRANSFORMS_WARNING)
from torchvision.transforms.v2 import (
ImportError: cannot import name 'ToImage' from 'torchvision.transforms.v2' (D:\Miniconda\lib\site-packages\torchvision\transforms\v2_init
.py)

What version of torchvision do you have installed? (You can check by running "pip show torchvision")

What version of torchvision do you have installed? (You can check by running "pip show torchvision")

Name: torchvision
Version: 0.16.2

Hey, I'm running into the same issue. As I understand it, ToImage was introduced in torchvision 0.16 (I'm running 0.15.2 due to my CUDA version). I think it could be replaced with the functional F.to_image. I'll try to find time to test it.

Edit:
Fixed using torchvision 0.15.2 by changing the preprocessor in vision_encoder.py

        self.preprocess = Compose(
            [
                Resize(size=(378, 378), interpolation=InterpolationMode.BICUBIC, antialias=True),
                ToTensor(),
                ConvertImageDtype(torch.float32),
                Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
            ]

Sign up or log in to comment