i was used torch==1.6.0, torchvision==0.7.0 to train the yolov5l model.
when i export to onnx, i was fail. my ONNX==1.7
use torch==1.5.1, torchvision==0.6.1. The following error occurs.
AttributeError: Can't get attribute 'Hardswish' on <module 'torch.nn.modules.activation' from '/usr/local/lib/python3.6/dist-packages/torch/nn/modules/activation.py'>
use torch==1.6, torchvision==0.7. The following error occurs.
ONNX export failure: Exporting the operator hardswish to ONNX opset version 12 is not supported
@colorful-ocean yes this is the case currently. Workaround is to replace nn.hardswish with a custom module, or to skip hardswish altogethor and train a model with nn.LeakyReLU(0.1) in it's place, which is much faster on CoreML.
@glenn-jocher Thanks, I am going to replace it with nn.LeakyReLU(0.1), and retrain the model.
@colorful-ocean that's not a bad option. If you want to eventually export your model I would highly recommend making the change here. This is the only place you need to make the change:
https://github.com/ultralytics/yolov5/blob/a8751e50de94b207c1323c3eda493952cced1d72/models/common.py#L20-L27
@colorful-ocean see https://github.com/ultralytics/yolov5/issues/831 for a recently implemented export fix. Full export functionality is now available for the most recent v3.0 YOLOv5 models, to all destinations (torchscript, onnx and coreml), along with new model fusion feature addition as well.
Please git pull and try again.
@glenn-jocher i retrain the model using nn.LeakyReLU(0.1) and export onnx suceessfully.
when i use this onnx model to infer(input_shape==(3,512,512)), there is three outputs((1, 3, 64, 64, 6), (1, 3, 32, 32, 6), (1, 3, 16, 16, 6)). What should I do with these three outputs to get the final result
@colorful-ocean
The three outputs are the input of the Detect Layer.
u need to implement detect layer urself.
@glenn-jocher so now we cannot export the detect layer? Is that true?
Most helpful comment
@colorful-ocean that's not a bad option. If you want to eventually export your model I would highly recommend making the change here. This is the only place you need to make the change:
https://github.com/ultralytics/yolov5/blob/a8751e50de94b207c1323c3eda493952cced1d72/models/common.py#L20-L27