pytorch导出onnx模型代码:
onnx_name = "faceland_98.onnx"
data = torch.rand(1, 3, 112, 112)
torch.onnx.export(plfd_backbone,
data,
onnx_name,
export_params=True, # store the trained parameter weights inside the model file
opset_version=11, # the ONNX version to export the model to
do_constant_folding=True, # whether to execute constant folding for optimization
input_names=['input'],
output_names=['output'])
报错:
relu6 to ONNX opset version 11 is not supported.
换了参数,10,11,12,13都不行,
发现是torch版本问题,
报错的版本:
torch 1.9.1+cu111
解决办法,换个版本,比如:
pip install torch==1.12.0+cu113 torchvision==0.13.0+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
导出成功。