From 6abfb6b92805427d98dc16f13d04f18351acfbf7 Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 5 Apr 2024 20:55:03 +0800 Subject: [PATCH] [js/rn] Support load external data (#20090) Support load external data by passing local model path --- .../java/ai/onnxruntime/reactnative/OnnxruntimeModule.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/react_native/android/src/main/java/ai/onnxruntime/reactnative/OnnxruntimeModule.java b/js/react_native/android/src/main/java/ai/onnxruntime/reactnative/OnnxruntimeModule.java index fd085f9533801..707a356b949ab 100644 --- a/js/react_native/android/src/main/java/ai/onnxruntime/reactnative/OnnxruntimeModule.java +++ b/js/react_native/android/src/main/java/ai/onnxruntime/reactnative/OnnxruntimeModule.java @@ -199,6 +199,12 @@ private WritableMap loadModelImpl(String uri, byte[] modelData, ReadableMap opti if (modelData != null && modelData.length > 0) { // load model via model data array ortSession = ortEnvironment.createSession(modelData, sessionOptions); + } else if (uri.startsWith("file://") || uri.startsWith("/")) { + // load model from local + if (uri.startsWith("file://")) { + uri = uri.substring(7); + } + ortSession = ortEnvironment.createSession(uri, sessionOptions); } else { // load model via model path string uri InputStream modelStream =