尝试将双线性层转换为 onnx 时,上采样 ONNX 给出 INVALID_GRAPH
Upsample ONNX gives INVALID_GRAPH when trying to convert bilinear layer to onnx
当我将在 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 中修复(修复在 functional.py 中),因此如果您安装 pytorch 的夜间构建,您应该能够得到它。
但是,在同一个 PR 中,在双线性模式下转换 Upsample 已被禁用;原因是Pytorch的bilinear mode和ONNX的不对齐,Nearest mode是目前唯一支持的模式
ONNX 中的上采样(现在称为调整大小)正在 opset 11 中更新,以支持与 https://github.com/onnx/onnx/pull/2057 中的 Pytorch 对齐的双线性模式,但这尚未推出。
当我将在 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 中修复(修复在 functional.py 中),因此如果您安装 pytorch 的夜间构建,您应该能够得到它。
但是,在同一个 PR 中,在双线性模式下转换 Upsample 已被禁用;原因是Pytorch的bilinear mode和ONNX的不对齐,Nearest mode是目前唯一支持的模式
ONNX 中的上采样(现在称为调整大小)正在 opset 11 中更新,以支持与 https://github.com/onnx/onnx/pull/2057 中的 Pytorch 对齐的双线性模式,但这尚未推出。