microsoft / onnxjs

ONNX.js: run ONNX models using JavaScript
Other
1.75k stars 130 forks source link

cannot resolve operator 'Pow' with opsets: ai.onnx v9 #278

Open bayartsogt-ya opened 3 years ago

bayartsogt-ya commented 3 years ago

I tried to load mobilenet_v2 model (pretrained and exported on PyTorch) in ReactJS using script below:

import { Tensor, InferenceSession } from "onnxjs";
import modelPath from "./models/my_model.onnx";

function App() {
  const [loaded, setLoaded] = useState(false);
  const onnxSession = new InferenceSession({ backendHint: "cpu" });

  const loadModel = async (e) => {
    console.log("loading model");
    await onnxSession.loadModel(modelPath);
    setLoaded(true);
  };
}

and faced following error:

Uncaught (in promise) TypeError: cannot resolve operator 'Pow' with opsets: ai.onnx v9
    at Object.e.resolveOperator (onnx.min.js:1)
    at t.resolve (onnx.min.js:14)
    at e.initializeOps (onnx.min.js:14)
    at onnx.min.js:14
    at t.event (onnx.min.js:1)
    at e.initialize (onnx.min.js:14)
    at e.<anonymous> (onnx.min.js:14)
    at onnx.min.js:14
    at Object.next (onnx.min.js:14)
    at a (onnx.min.js:14)

Judging from Operator.md, Pow is supported.

Honestly, I have no idea even what this output message is about...

How can I approach to this problem?

remixer-dec commented 3 years ago

You're using export in version 9, but the README says

ONNX.js currently supports most operators in ai.onnx operator set v7 (opset v7)

Export your model with opset_version=7 and it'll work just fine.

Judging from Operator.md, Pow is supported.

As I understand, it was merged on 2 Sep 2020 and the latest stable version was released on 28 Aug 2020. So you can clone the repo and build it yourself... however looks like there are currently some emsdk compatibility issues with wasm runtime.