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

x33g5p2x  于2022-06-20 转载在 其他  
字(0.7k)|赞(0)|评价(0)|浏览(427)

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实现:

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

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

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

相关文章