gpt4 book ai didi

pytorch - 尝试将双线性层转换为 onnx 时,上采样 ONNX 给出 INVALID_GRAPH

转载 作者:行者123 更新时间:2023-12-02 03:14:05 24 4
gpt4 key购买 nike

当我将在 Pytorch 上训练的双线性层网络转换为 ONNX 时,出现以下错误

RuntimeError: [ONNXRuntimeError] : 10 : INVALID_GRAPH : Load model from test.onnx failed:Type Error: Type 'tensor(int64)' of input parameter (11) of operator (Floor) in node () is invalid.

我不确定为什么会出现此错误,我尝试从源代码构建 ONNX,但问题似乎仍然没有解决。

关于可能导致此错误的原因有什么想法吗?或者如何解决这个问题?

繁殖方式-

from torch import nn

import torch
import torch.nn.functional as F
import onnxruntime as rt

class Upsample(torch.nn.Module):
def forward(self, x):
#l = nn.Conv2d(3, 3, kernel_size=1, stride=1, padding=1, bias=True)
return F.interpolate(x, scale_factor=2, mode="bilinear", align_corners=False)

m = Upsample()
v = torch.randn(1,3,128,128, dtype=torch.float32, requires_grad=False)

torch.onnx.export(m, v, "test.onnx")
sess = rt.InferenceSession("test.onnx")

最佳答案

此错误已在 https://github.com/pytorch/pytorch/pull/21434 中修复(修复程序位于 function.py 中),因此如果您安装 pytorch 的夜间构建,您应该能够获得它。

但是,在同一个 PR 中,双线性模式下转换 Upsample 已被禁用;原因是 Pytorch 的双线性模式与 ONNX 的双线性模式不一致,而最近模式是目前唯一支持的模式。

ONNX 中的上采样(现在称为调整大小)在 opset 11 中进行了更新,以支持与 https://github.com/onnx/onnx/pull/2057 中的 Pytorch 一致的双线性模式,但这还没有推送。

关于pytorch - 尝试将双线性层转换为 onnx 时,上采样 ONNX 给出 INVALID_GRAPH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56682815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com