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

x33g5p2x  于10天前 转载在 其他  
字(0.7k)|赞(0)|评价(0)|浏览(10)

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 =

相关文章