mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-01 03:45:06 +00:00
Fix react native load from Uint8Array buffer bug (#17739)
### Description <!-- Describe your changes. --> Use `.buffer` of Uint8Array to get ArrayBuffer. TODO: Add E2E React Native test case to cover JS level testing to avoid future breakage. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> #17732 Co-authored-by: rachguo <rachguo@rachguos-Mini.attlocal.net>
This commit is contained in:
parent
5a623dca01
commit
e106b1eb8f
1 changed files with 3 additions and 1 deletions
|
|
@ -66,12 +66,14 @@ class OnnxruntimeSessionHandler implements SessionHandler {
|
|||
let results: Binding.ModelLoadInfoType;
|
||||
// load a model
|
||||
if (typeof this.#pathOrBuffer === 'string') {
|
||||
// load model from model path
|
||||
results = await this.#inferenceSession.loadModel(normalizePath(this.#pathOrBuffer), options);
|
||||
} else {
|
||||
// load model from buffer
|
||||
if (!this.#inferenceSession.loadModelFromBlob) {
|
||||
throw new Error('Native module method "loadModelFromBlob" is not defined');
|
||||
}
|
||||
const modelBlob = jsiHelper.storeArrayBuffer(this.#pathOrBuffer);
|
||||
const modelBlob = jsiHelper.storeArrayBuffer(this.#pathOrBuffer.buffer);
|
||||
results = await this.#inferenceSession.loadModelFromBlob(modelBlob, options);
|
||||
}
|
||||
// resolve promise if onnxruntime session is successfully created
|
||||
|
|
|
|||
Loading…
Reference in a new issue