【发布时间】:2020-10-12 15:40:46
【问题描述】:
我正在尝试将模型导出为 onnx 格式。架构很复杂,所以我不会在这里分享,但基本上,我在.pth 文件中有网络权重。我能够加载它们、创建网络并使用它进行推理。
需要注意的是,我已经调整了代码以便能够量化网络。我添加了 quantize 和 dequantize 运算符以及一些 torch.nn.quantized.FloatFunctional() 运算符。
但是,每当我尝试将其导出时
torch.onnx.export(torch_model, # model being run
input_example, # model input
model_name, # where to save the model
export_params=True, # store the trained parameter
opset_version=11, # the ONNX version to export
# the model to
do_constant_folding=True, # whether to execute constant
# folding for optimization
)
我得到Segmentation fault (core dumped)
我正在使用 Ubuntu 20,安装了以下软件包:
torch==1.6.0
torchvision==0.7.0
onnx==1.7.0
onnxruntime==1.4.0
请注意,根据我留在代码中的一些prints,导出的推理部分完成。分段错误发生在之后。
有人知道为什么会发生这种情况吗?
[编辑]:当我的网络不适合量化操作时,我可以导出它。所以问题不是安装坏了,更多的是一些量化算子节省onnx的问题。
【问题讨论】:
标签: python segmentation-fault pytorch onnx