当前位置: 首页 > news >正文

onnx: step = 1 is currently not supported

1. 在yolov5s的pytorch模型转换onnx模型时报如下错误:

RuntimeError: step!=1 is currently not supported
原因主要是低版本的opset不支持切片操作导致的;

把模型转换的代码改成如下所示即可,即使用版本11以上的opset:

torch.onnx.export(model, img, "xxx.onnx", verbose=True,opset_version=11,export_params=True)

我这个onnx不支持这个参数;

解决方法是:

class OnnxExportApiArgs:
    """
    configuration for torch onnx export api invocation
    """

    def __init__(self, opset_version: int = 11, input_names: List[str] = ['inpout'], output_names: List[str] =  ['output']):
        """
        Refer torch documentation https://pytorch.org/docs/1.7.1/onnx.html?highlight=onnx%20export#torch.onnx.export
        :param opset_version: onnx opset version to use to export the model
        :param input_names:  names to assign to the input nodes of the onnx graph, in order
        :param output_names: names to assign to the output nodes of the graph, in order
        """
        self.opset_version = opset_version
        self.input_names = input_names
        self.output_names = output_names

    @property
    def kwargs(self):
        """
        formats all override options into kwarg format to appended to onnx export call
        """
        return {'opset_version': self.opset_version,
                'input_names': self.input_names,
                'output_names': self.output_names}

调用:

if onnx_export_args is None:
    onnx_export_args = OnnxExportApiArgs()

torch.onnx.export(model, dummy_input, temp_file, enable_onnx_checker=False,**onnx_export_args.kwargs)


2. 解决该问题后可能会继续出现如下错误:

RuntimeError: Exporting the operator silu to ONNX opset version 11 is not supported. Please open a bug to request ONNX export support for the missing operator.
这是因为onnx与pytorch一些方法不兼容导致的,onnx不支持silu,把激活函数换一种写法即可。

解决方法如下:

pytorch的激活函数源码位置:X:\anaconda3\envs\python3.7\Lib\sitepackages\torch\nn\modules\activation.py(此处结合自己的anaconda实际安装位置来更改)。

修改成如下:

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


————————————————
版权声明:本文为CSDN博主「小码乔」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_37889356/article/details/121671974

相关文章:

  • webpack原理篇(六十五):实战开发一个压缩构建资源为zip包的插件
  • 数学建模学习(97):花授粉算法(FPA)寻优
  • 鲈鱼的面试题库+答案
  • CREO:CREO软件之零件【工具(调查/模型意图/实用工具)】、【视图(可见性/方向/模型显示/显示/窗口)】的简介及其使用方法(图文教程)之详细攻略
  • 【单细胞高级绘图】09.细胞通讯_两组比较_连线图
  • Tensorflow笔记——基于Mnist数据集图片分类的神经网络
  • 情侣积分微信小程序零基础开发教程(附代码及开发指南)
  • 为什么重写equals方法必须也要重写hashCode方法
  • 只要十分钟!带你了解Redis Cluster
  • CREO:CREO软件之零件【造型】样式栏之操作、平面、曲线、曲面、分析、优先选项的简介及其使用方法(图文教程)之详细攻略
  • app毕业设计开题报告基于Uniapp实现的美食餐厅订单点餐APP
  • 基于51单片机十字路口交通灯_5s黄灯闪烁
  • Java并发 | 13.[设计模式] 两阶段终止线程
  • 一次服务器被入侵的处理过程分享
  • Java并发 | 11.[方法] join( )和join( long m )等待线程执行完毕
  • AngularJS指令开发(1)——参数详解
  • CAP 一致性协议及应用解析
  • Druid 在有赞的实践
  • Java 11 发布计划来了,已确定 3个 新特性!!
  • JS实现简单的MVC模式开发小游戏
  • js正则,这点儿就够用了
  • OpenStack安装流程(juno版)- 添加网络服务(neutron)- controller节点
  • Python - 闭包Closure
  • Python打包系统简单入门
  • Sass 快速入门教程
  • 从零开始在ubuntu上搭建node开发环境
  • 对话 CTO〡听神策数据 CTO 曹犟描绘数据分析行业的无限可能
  • 构建工具 - 收藏集 - 掘金
  • 批量截取pdf文件
  • 吴恩达Deep Learning课程练习题参考答案——R语言版
  • ​软考-高级-系统架构设计师教程(清华第2版)【第20章 系统架构设计师论文写作要点(P717~728)-思维导图】​
  • (1)SpringCloud 整合Python
  • (11)工业界推荐系统-小红书推荐场景及内部实践【粗排三塔模型】
  • (MonoGame从入门到放弃-1) MonoGame环境搭建
  • (Python第六天)文件处理
  • (Redis使用系列) Springboot 使用redis实现接口幂等性拦截 十一
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (免费领源码)Java#Springboot#mysql农产品销售管理系统47627-计算机毕业设计项目选题推荐
  • (七)理解angular中的module和injector,即依赖注入
  • (转)Android学习系列(31)--App自动化之使用Ant编译项目多渠道打包
  • (转)程序员技术练级攻略
  • (转)清华学霸演讲稿:永远不要说你已经尽力了
  • (转载)Linux网络编程入门
  • (转载)OpenStack Hacker养成指南
  • *** 2003
  • .CSS-hover 的解释
  • .net通用权限框架B/S (三)--MODEL层(2)
  • /dev下添加设备节点的方法步骤(通过device_create)
  • [ Linux ] Linux信号概述 信号的产生
  • []T 还是 []*T, 这是一个问题
  • [20190401]关于semtimedop函数调用.txt
  • [④ADRV902x]: Digital Filter Configuration(发射端)
  • [AIGC codze] Kafka 的 rebalance 机制
  • [Android]RecyclerView添加HeaderView出现宽度问题