gpt4 book ai didi

Exporting the operator hardsigmoid to ONNX opset version 11 is not supported

转载 作者:知者 更新时间:2024-03-12 23:14:54 25 4
gpt4 key购买 nike

yoloe导出onnx时报错:

RuntimeError: Exporting the operator hardsigmoid to ONNX opset version 11 is not supported. Please open a bug to request ONNX export support for the missing operator.

在onnx opset 12下转以下模型时因不支持hardswish激活函数而报错

GhostNet
MobileNetv3Small
EfficientNetLite0
PP-LCNet
解决方案是找到对应的nn.Hardswish层,将其替换为自己覆写的Hardswish实现:

class Hardswish(nn.Module):  # export-friendly version of nn.Hardswish()
    @staticmethod
    def forward(x):
        # return x * F.hardsigmoid(x)  # for torchscript and CoreML
        return x * F.hardtanh(x + 3, 0., 6.) / 6.  # for torchscript, CoreML and ONNX

以PP-LCNet为例,找到哪些层是Hardswish层,替换方法为

# 替换函数, 参考https://zhuanlan.zhihu.com/p/356273702
def _set_module(model, submodule_key, module):
    tokens = submodule_key.split('.')
    sub_tokens =

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