Initializing inference session on worker thread for web applications using onnxruntime-web
@fs-eire is already working on this.
Since Aug 15, 2022.
Assessment
This issue has not been assessed yet.
Description
Describe the bug
I am trying to create an inference session with the
create(uri: string, options?: SessionOptions: Promise<InferenceSessionInferenceSession)>
function in a worker (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) script, but the inference session creation function gave me the Uncaught (in promise) Error: Can't create a session error (see screenshot below).

For the time being, I am able to read in the .onnx file into an ArrayBuffer on the main thread and then transfer the ArrayBuffer representing the onnx model to the worker thread, and was able to create the inference session on the worker thread with the transferred ArrayBuffer and also run inference successfully. However, I am still interested in knowing if it's possible to create an inference session directly with a given file path on the worker thread.
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- ONNX Runtime version:
"onnxruntime-web": "^1.12.1"(in package.json)
Additional context
Note that is an onnxruntime-web issue, not an onnxruntime-react-native issue.
To Reproduce
Link to repo: https://github.com/jackylu0124/onnxruntime-web-worker-initialization-issue
I have commented out the line that emits the error message since my alternative way mentioned earlier can both create the inference session and also peform inference. To reproduce the error message, look for the comment starting with // NOTE: in inferenceWorker.ts and uncomment the line below that line of comment. For convenience, the link to that line is: https://github.com/jackylu0124/onnxruntime-web-worker-initialization-issue/blob/f64c0df784a1c0de0b0ac3199a7d405226ffa610/web-worker-001/src/workers/inferenceWorker.ts#L4
Steps to run the code:
- Uncomment the line at https://github.com/jackylu0124/onnxruntime-web-worker-initialization-issue/blob/f64c0df784a1c0de0b0ac3199a7d405226ffa610/web-worker-001/src/workers/inferenceWorker.ts#L4.
cdinto theweb-worker-001folder.npm installand thennpm startin the terminal.- Open DevTools in the browser and see the error message.
Expected behavior
The inference session should be able to be created with the file path argument on the worker thread.
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 179
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/onnxruntime
-
ep:MIGraphX
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
microsoft/onnxruntime#32352 · 1 comment ·
-
`optimization.disable_specified_optimizers` is documented as comma-separated but is parsed on `;` Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
microsoft/onnxruntime#32211 ·
-
stale
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
microsoft/onnxruntime#29750 · 3 comments ·
-
ep:WebGPU platform:web stale
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/onnxruntime#28976 · 3 comments ·
-
[Documentation] Python tutorial missing PyTorch export guidance and external data file handling Opendocumentation
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
microsoft/onnxruntime#28763 · 5 comments ·
All issues in microsoft/onnxruntime
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Sensor initialization takes very long when `--initial-sim-time` is set to current UNIX timestamp Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gazebosim/gz-sensors#662 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LadybirdBrowser/ladybird#12123 ·