microsoft / microsoft/onnxruntime
[React Native Inference Session Initialization With Buffer Error] "Error: Uint8Array is not supported"
@fs-eire is already working on this.
Since Aug 9, 2022.
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 179
Description
Describe the bug
I tried to initialize an inference session with a Uint8Array representation of a very simple .ort model (see screenshot of the .ort file viewed in Netron below), but it gave me the [Error: Uint8Array is not supported] error. The Uint8Array from my original code is from my database, but for the purpose of easier reproduction and isolation of the issue, I have included a .txt file that contains the content of the .ort file in hex code (see https://github.com/jackylu0124/ort-react-native-buffer-issue/blob/main/onnx_hex_files/LinearBlend_v001.txt), and the string of the hex code content (see line 46 in App.tsx) is parsed into a Uint8Array buffer before it's being passed into ort.InferenceSession.create(). I have also tried passing in a raw ArrayBuffer rather than a Uint8Array buffer, but it didn't work either. According to the documentation (https://onnxruntime.ai/docs/api/js/interfaces/InferenceSessionFactory.html), both should work.
I am currently running the app on Android Studio's emulator on Windows.
P.S.
I have verified that the hex code content in the .txt file is correct by parsing it and converting it to bytes in Python and was able to use it to initialize an inference session successfully using ONNX Runtime's Python API (but the same doesn't work for ONNX Runtime's React Native API, and hence leading to this GitHub issue).
Urgency
High urgency, this is a blocking issue in my project.
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- ONNX Runtime version:
"onnxruntime-react-native": "^1.12.1"(in package.json)
To Reproduce
Link to repo with minimal code for error reproduction: https://github.com/jackylu0124/ort-react-native-buffer-issue
Please follow instructions on https://reactnative.dev/docs/environment-setup in order to set up and run the project with Android Studio's emulator.
Once the project is set up and running, you can click/press the "CREATE INFERENCE SESSION WITH BUFFER" button on the top of the screen, which will try to initialize an inference session with the Uint8Array buffer representing the ONNX model, and the error will be logged into the console. (see Gif below)
Expected behavior
The inference session should be initialized successfully with no error messages emitted since initializing inference session with Uint8Array buffer or raw ArrayBuffer is supported as stated in the documentation. (https://onnxruntime.ai/docs/api/js/interfaces/InferenceSessionFactory.html).
Screenshots
The .ort Model that I am using (it's a very simple model for linear-blending two inputs e.g. blend = (1 - alpha) * img1 + alpha * img2)

Error Message Gif

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.
Assessment
This issue has not been assessed yet.