Initializing inference session on worker thread for web applications using onnxruntime-web

Open
#12,589 0 comments 4 reactions 1 assignee View on GitHub

@fs-eire is already working on this.

Since Aug 15, 2022.

Assessment

This issue has not been assessed yet.

Description

platform:web
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).
image

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:

  1. Uncomment the line at https://github.com/jackylu0124/onnxruntime-web-worker-initialization-issue/blob/f64c0df784a1c0de0b0ac3199a7d405226ffa610/web-worker-001/src/workers/inferenceWorker.ts#L4.
  2. cd into the web-worker-001 folder.
  3. npm install and then npm start in the terminal.
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/onnxruntime

All issues in microsoft/onnxruntime

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.