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

[Web] I can’t use onnruntime-web to load a onnx model in a react web #20846

Open
tanggang1997 opened this issue May 29, 2024 · 6 comments
Open
Labels
platform:web issues related to ONNX Runtime web; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot

Comments

@tanggang1997
Copy link

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)

@tanggang1997 tanggang1997 added the platform:web issues related to ONNX Runtime web; typically submitted using template label May 29, 2024
@fs-eire
Copy link
Contributor

fs-eire commented May 30, 2024

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.

@tanggang1997
Copy link
Author

tanggang1997 commented May 30, 2024

关于部署 WebAssembly 文件有关。请参考#19831 (评论)

顺便说一句,在 1.19.0-dev.20240521-068bb3d5ee 版本之前,WebAssembly 的版本需要与 JS 的版本相匹配。
First:
But i have setted :env.wasm.wasmPaths = window.location.origin + "/node_modules/onnxruntime-web/dist/";
I don't understand "The .wasm files are correctly deployed" ,can you tell me about the detail?
Second:
So I just upgarde the onnruntime-web version to 1.19.0-dev.20240521-068bb3d5ee?

@fs-eire
Copy link
Contributor

fs-eire commented May 30, 2024

env.wasm.wasmPaths = window.location.origin + "/node_modules/onnxruntime-web/dist/";

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 )

@tanggang1997
Copy link
Author

env.wasm.wasmPaths = window.location.origin + "/node_modules/onnxruntime-web/dist/";

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!!!
I have setted like this:ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.15.0/dist/"; but it also gives me error.
Now, I want to ensure that wheather i need to upgarde the onnxruntime-web

@fs-eire
Copy link
Contributor

fs-eire commented May 30, 2024

env.wasm.wasmPaths = window.location.origin + "/node_modules/onnxruntime-web/dist/";

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!!! I have setted like this:ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.15.0/dist/"; but it also gives me error. Now, I want to ensure that wheather i need to upgarde the onnxruntime-web

You have 3 options:

  • keep using env.wasm.wasmPaths = window.location.origin + "/node_modules/onnxruntime-web/dist/";, but you need to make sure the .wasm files are served correctly. For example, if your HTML is at http://localhost:8080/my/index.html, you need to make sure http://localhost:8080/my/node_modules/onnxruntime-web/dist/ort-wasm-simd.wasm can be accessed. This can be easily validated via browser. Usually the node_modules folder is excluded in dev server so you are unlikely to access that URL. A common way to deploy WASM is to copy the .wasm files into your public folder and set env.wasm.wasmPaths to there.
  • you can use env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/..." but as I mentioned above, please make sure the version is matched. If you are using version onnxruntime-web@1.17.0-dev.20240110-5f3113ecd6 you cannot use wasmPath pointing to version 1.15.0
  • You can also upgrade to onnruntime-web version to 1.19.0-dev.20240521-068bb3d5ee; but you still to choose either serve the .wasm yourself or point path to CDN.

Copy link
Contributor

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.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:web issues related to ONNX Runtime web; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

2 participants