Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ONNX: export failure: Exporting the operator silu to ONNX opset version 12 is not supported. #7832

Closed
1 task done
gsx1378 opened this issue May 16, 2022 · 6 comments
Closed
1 task done
Labels
question Further information is requested

Comments

@gsx1378
Copy link

gsx1378 commented May 16, 2022

Search before asking

Question

when i run "python export.py --weights ./models/download/yolov5n.pt --include onnx", the result is as follows:
`export: data=data/coco128.yaml, weights=['./models/download/yolov5n.pt'], imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, train=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx']
YOLOv5 🚀 v6.1-190-g4d59f65 Python-3.8.8 torch-1.7.0 CPU

Fusing layers...
YOLOv5n summary: 213 layers, 1867405 parameters, 0 gradients, 4.5 GFLOPs

PyTorch: starting from models/download/yolov5n.pt with output shape (1, 25200, 85) (3.9 MB)

ONNX: starting export with onnx 1.9.0...
ONNX: export failure: Exporting the operator silu to ONNX opset version 12 is not supported. Please open a bug to request ONNX export support for the missing operator.`
How to solve this problem? Looking forward to your reply. ^_^

Additional

No response

@gsx1378 gsx1378 added the question Further information is requested label May 16, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 16, 2022

👋 Hello @gsx1378, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@Im-JimmyHu
Copy link

it looks like the the version of torch cause the error,may you can try to export with torch>=1.9,<=1.10.1,also compitable with the version onnx,wich i have successfullly convert the model to onnx.
if not solved,may you also try to replace the silu with this:

class SiLU(Module):
 
    __constants__ = ['inplace']
    inplace: bool
 
    def __init__(self, inplace: bool = False):
        super(SiLU, self).__init__()
        self.inplace = inplace
 
    def forward(self, input: Tensor) -> Tensor:
    
        return input * torch.sigmoid(input)
 

@glenn-jocher
Copy link
Member

glenn-jocher commented May 16, 2022

@gsx1378 it appears you may have environment problems. Your ONNX and PyTorch versions are both a bit old.

Please ensure you meet all dependency requirements if you are attempting to run YOLOv5 locally. If in doubt, create a new virtual Python 3.9 environment, clone the latest repo (code changes daily), and pip install requirements.txt again from scratch.

💡 ProTip! Try one of our verified environments below if you are having trouble with your local environment.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Models and datasets download automatically from the latest YOLOv5 release when first requested.

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@ZCzzzzzz
Copy link

it looks like the the version of torch cause the error,may you can try to export with torch>=1.9,<=1.10.1,also compitable with the version onnx,wich i have successfullly convert the model to onnx. if not solved,may you also try to replace the silu with this:

class SiLU(Module):
 
    __constants__ = ['inplace']
    inplace: bool
 
    def __init__(self, inplace: bool = False):
        super(SiLU, self).__init__()
        self.inplace = inplace
 
    def forward(self, input: Tensor) -> Tensor:
    
        return input * torch.sigmoid(input)
 

Can you tell me where this code should be placed?

@gsx1378
Copy link
Author

gsx1378 commented May 11, 2023

it looks like the the version of torch cause the error,may you can try to export with torch>=1.9,<=1.10.1,also compitable with the version onnx,wich i have successfullly convert the model to onnx. if not solved,may you also try to replace the silu with this:

class SiLU(Module):
 
    __constants__ = ['inplace']
    inplace: bool
 
    def __init__(self, inplace: bool = False):
        super(SiLU, self).__init__()
        self.inplace = inplace
 
    def forward(self, input: Tensor) -> Tensor:
    
        return input * torch.sigmoid(input)
 

Can you tell me where this code should be placed?

"./utils/activations.py", You can search for it with this command: grep -rni "SiLU(" ./ --binary-files=without-match

@glenn-jocher
Copy link
Member

@gsx1378 thank you for your question! Regarding the suggested code change, you can find the Silu function located in the ./models/common.py file. As for the additional code provided, this SiLU implementation can be found in ./utils/activations.py. You could find it by running this command: grep -rni "SiLU(" ./ --binary-files=without-match from the command line.

Please give this a try, and feel free to reach out if you need further assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants