Pytorch模型编译报错 UserWarning: (Resize(), RandomResizedCrop(), etc.)——解决办法

1、问题描述

  • 使用Pytorch训练模型时,编译报错: 
    • UserWarning: The default value of the antialias parameter of all the resizing transforms (Resize(), RandomResizedCrop(), etc.) will change from None to True in v0.17, in order to be consistent across the PIL and Tensor backends.
      To suppress this warning, directly pass antialias=True (recommended, future default), antialias=None (current default, which means False for Tensors and True for PIL), or antialias=False (only works on Tensors - PIL will still use antialiasing). 
      This also applies if you are using the inference transforms from the models weights: update the call to weights.transforms(antialias=True).
  • UserWarning:所有调整大小变换(Resize()、RandomResizedCrop()等)的抗锯齿参数的默认值将在v0.17中从无变为有,以便在PIL和张量后端保持一致。
  • 要取消此警告,请直接传递antialias=True(推荐,未来的默认值),antialias=None(当前默认值,对于张量为False,对于PIL为True),或antialias=False(仅适用于张量- PIL仍将使用抗锯齿)。
  • 如果您使用模型权重的推理转换,这也适用:更新对weights.transforms的调用(antialias=True)。 

2、解决办法

  • 这个警告信息是与缩放转换中的抗锯齿参数(antialias)默认值变更有关,将在v0.17版本中生效。
  • 简单来说就是需要给Resize()加上antialias参数。
  • 原来为
    • transforms.Resize(60)
  • 修改为
    • transforms.Resize(60, antialias=True)
  • 【注】 antialias=True表示启用抗锯齿功能。

猜你喜欢

转载自blog.csdn.net/weixin_45100742/article/details/134706299