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.
cd
into theweb-worker-001
folder.npm install
and thennpm start
in 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.