导入torchvision.transforms时出现'torch.onnx.symbolic_helper'无quantized_args属性错误
问题解决:导入torchvision transforms时的ONNX相关报错与警告
问题重现
执行from torchvision import transforms时,先弹出如下警告:
OnnxExporterWarning: Symbolic function 'aten::_shape_as_tensor' already registered for opset 9. Replacing the existing function with new function. This is unexpected. Please report it on https://github.com/pytorch/pytorch/issues. errors.OnnxExporterWarning,
随后触发错误:module 'torch.onnx.symbolic_helper' has no attribute 'quantized_args'
环境配置:torch1.13.0、torchvision0.14.0,搭载CUDA 11.8的GPU设备
可行解决方案
- 版本匹配调整:torchvision 0.14.0与torch 1.13.0的ONNX导出模块存在兼容性冲突,可通过以下两种方式修复:
- 升级版本:将torch升级到1.14.0+,同步升级torchvision到0.15.0+,执行命令:
pip install torch==1.14.0 torchvision==0.15.0 --index-url https://download.pytorch.org/whl/cu118 - 降级版本:将torchvision降级到与torch1.13.0严格匹配的0.13.1版本,执行命令:
pip install torchvision==0.13.1 --force-reinstall
- 升级版本:将torch升级到1.14.0+,同步升级torchvision到0.15.0+,执行命令:
- 临时屏蔽警告(仅处理警告):如果暂时无法调整版本,可在导入前添加代码屏蔽警告,但此方法无法解决
quantized_args缺失的报错:import warnings warnings.filterwarnings("ignore", category=torch.onnx.errors.OnnxExporterWarning) from torchvision import transforms - 验证CUDA适配:确认安装的torch、torchvision是针对CUDA11.8编译的版本,避免CPU版本与GPU环境不兼容。
内容的提问来源于stack exchange,提问作者DholuBholu
相关产品推荐
相关产品推荐

