-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[Web] I can’t use onnruntime-web to load a onnx model in a react web #20846
Comments
It is related to deploying WebAssembly files. Please refer to #19831 (comment). BTW, before version 1.19.0-dev.20240521-068bb3d5ee, the version of WebAssembly file need to match the JS file. |
|
If you set this in the code, you also need to make sure the file is served by the server. I know that React has "dev" mode and "production" mode, and they may treat asset deployment differently. I am not an expert of React, so I cannot figure out the detail; but the whole idea is to make sure the URL of the .wasm file is actually valid ( which can be verified in your browser devtool, "Network" tab ) |
Thank you very much!!! |
You have 3 options:
|
This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details. |
Describe the issue
When I use onnxruntime-web to load a onnx model in react web,I found error.
a)The error is:
Uncaught (in promise) Error: no available backend found. ERR: [wasm] Error: Aborted(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -sASSERTIONS for more info., [cpu] Error: previous call to 'initWasm()' failed., [xnnpack] Error: previous call to 'initWasm()' failed.
b)This is my code:
async function Load_Model() {
console.log(window.location.origin + "/node_modules/onnxruntime-web/dist/ort-wasm-simd.wasm");
env.wasm.wasmPaths = window.location.origin + "/node_modules/onnxruntime-web/dist/";
env.wasm.proxy = true;
// ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.15.0/dist/";
const path =
${process.env.PUBLIC_URL}/model.onnx
;const session = await InferenceSession.create(path);
return session.inputNames[0]
};
Load_Model();
I don't know the detail about react.Does it need to config?
To reproduce
onnxruntime-web@1.17.0-dev.20240110-5f3113ecd6
Urgency
No response
ONNX Runtime Installation
Built from Source
ONNX Runtime Version or Commit ID
14.1
Execution Provider
'wasm'/'cpu' (WebAssembly CPU)
The text was updated successfully, but these errors were encountered: