onnx2pytorch icon indicating copy to clipboard operation
onnx2pytorch copied to clipboard

how to support layer

Open mmdzzh opened this issue 1 year ago • 1 comments

what should i do if i want to support some layer in this repo and recompile

mmdzzh avatar Mar 14 '24 08:03 mmdzzh

You should add a new elif condition here to convert the onnx node to pytorch function: https://github.com/Talmaj/onnx2pytorch/blob/v0.5.0/onnx2pytorch/convert/operations.py

Sometimes it's as easy to add a pure pytorch function, but sometimes they differ in implementation and default parameters. In those cases you have to create a new operation under: https://github.com/Talmaj/onnx2pytorch/tree/v0.5.0/onnx2pytorch/operations

You should also include a test for it, best to look at onnx's tests: https://github.com/onnx/onnx/tree/main/onnx/backend/test/case/node and example of how that was done for ReduceL2:

  • onnx: https://github.com/onnx/onnx/blob/main/onnx/backend/test/case/node/reducel2.py
  • onnx2pytorch: https://github.com/Talmaj/onnx2pytorch/blob/v0.5.0/tests/onnx2pytorch/operations/test_reducel2.py

Talmaj avatar Sep 18 '24 21:09 Talmaj