Search code examples
python-3.xpytorch

Cant disable beta transforms warnings in PyTorch


Win x64, Spyder, Python 3.9, Pytorch 2.0.1+cu117

Reams of

C:\Users\sengnr3\.conda\envs\pytorch\Lib\site-packages\torchvision\transforms\v2\__init__.py:54: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. 
While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: 
https://github.com/pytorch/vision/issues/6753, and you can also check out https://github.com/pytorch/vision/issues/7319 to learn more about the APIs that we suspect might involve future changes. 
You can silence this warning by calling torchvision.disable_beta_transforms_warning().
      warnings.warn(_BETA_TRANSFORMS_WARNING)

So I try & silence using the advice in the warning Code,

import torchvision
torchvision.disable_beta_transforms_warning()

But still reams of the same warning.


Solution

  • It looks like to disable v2 warning you need to call disable_beta_transforms_warning() first then import the v2 transform.

    For example, this code won't disable the warning:

    from torchvision.transforms import v2
    import torchvision
    torchvision.disable_beta_transforms_warning()
    

    But this code does:

    import torchvision
    torchvision.disable_beta_transforms_warning()
    from torchvision.transforms import v2
    

    If you import v2 transform first, it will make a warning because python import the v2 transform first without disabling the warning.