pytorch导出onnx模型出错:RuntimeError: Cannot insert a Tensor that requires grad as a constant

参考:https://discuss.pytorch.org/t/runtimeerror-cannot-insert-a-tensor-that-requires-grad-as-a-constant/113767/4

pytorch导出onnx模型出错:RuntimeError: Cannot insert a Tensor that requires grad as a constant_第1张图片
pytorch导出onnx模型出错:RuntimeError: Cannot insert a Tensor that requires grad as a constant_第2张图片
我们在导出onnx模型的时候也要这样做,就可以正确导出了。看了很多资料,目前试过好用的就是这一种。

for para in model.parameters():
    para.requires_grad=False

pytorch导出onnx模型出错:RuntimeError: Cannot insert a Tensor that requires grad as a constant_第3张图片

你可能感兴趣的:(机器学习,pytorch,深度学习,python)