热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

torch2onnx

问题一:torch模型中有条件支路ONNXexportfailure:ExportingtheoperatorsilutoONNXopsetversion12isn

问题一:torch模型中有条件支路

ONNX export failure: Exporting the operator silu to ONNX opset version 12 is not supported. Please open a bug to request ONNX export support for the missing operator.

参考link 修改silu实现

C:\Users\admin\.conda\envs\torch\Lib\site-packages\torch\nn\modules

class SiLU(Module):__constants__ = ['inplace']inplace: booldef __init__(self, inplace: bool = False):super(SiLU, self).__init__()self.inplace = inplacedef forward(self, input: Tensor) -> Tensor:# ------------------------------------- ## 把F.silu替换掉,修改后如下return input * torch.sigmoid(input)#原来的代码return F.silu(input, inplace=self.inplace)

2  trt

ERROR: builtin_op_importers.cpp:1602 In function importIf:
[8] Assertion failed: cond.is_weights() && cond.weights().count() == 1 && "If condition must be a initializer!"

vino

There is no registered "infer" function for node "If_156" with op = "If". Please implement this function in the extensions.

参考link

link

错误是发生在importIf,即if节点,可是我forward函数里没有写任何判断,研究了一下转onnx的输出,发现问题出自squeeze()函数,torch1.7版本在onnx里加了一个判断操作,判断要squeeze的维度是不是1:


推荐阅读
author-avatar
黑天天
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有