efficientnet pytorch转onnx 时,执行其官方脚本:
https://github.com/lukemelas/EfficientNet-PyTorch#loading-pretrained-models
model = EfficientNet.from_name(model_name=‘efficientnet-b0’)
torch.onnx.export(model, torch.rand(10,3,240,240), “EfficientNet-B0.onnx”)
报错:
RuntimeError: ONNX export failed: Couldn’t export Python operator SwishImplementation
解决方法:
model = EfficientNet.from_name(model_name=‘efficientnet-b0’)
model.set_swish(memory_efficient=False)
torch.onnx.export(model, torch.rand(10,3,240,240), “EfficientNet-B0.onnx”
set_swish会把swish层转换为x*sigmoid(x),从而使pytorch模型成功转换为onnx模型。
引用:https://github.com/lukemelas/EfficientNet-PyTorch/issues/91