diff --git a/js/README.md b/js/README.md index 08b520eddb..d82055b99b 100644 --- a/js/README.md +++ b/js/README.md @@ -303,86 +303,86 @@ This project provides an ONNX Runtime React Native JavaScript library to run ONN - [CMake](https://cmake.org/download/) - [Python 3](https://www.python.org/downloads/mac-osx/) +### Models with ORT format + +By default, ONNX Runtime React Native leverages ONNX Runtime Mobile package with ORT format. Follow the [instruciton](https://www.onnxruntime.ai/docs/how-to/mobile/model-conversion.html#converting-onnx-models-to-ort-format) to covert ONNX model to ORT format. + ### Build 1. Install NPM packages for ONNX Runtime common JavaScript library and required React Native JavaScript libraries - 1. in `/js/`, run `npm ci`. - 2. in `/js/common/`, run `npm ci`. - 3. in `/js/react_native/`, run `yarn`. + - in `/js/`, run `npm ci`. + - in `/js/common/`, run `npm ci`. + - in `/js/react_native/`, run `yarn`. 2. Build Android ONNX Runtime package - 1. Set up an Android build environment referring to [instruction](https://www.onnxruntime.ai/docs/how-to/build.html#android) + 1. To use a published Android ONNX Runtime Mobile package from Maven, go to step 5. - 2. In ``, run this python script to build ONNX Runtime Android archive file. In windows, this requires admin account to build. If an app uses a fixed set of models, refer to [instruction](https://www.onnxruntime.ai/docs/how-to/build.html#android) and build a mobile version package + 2. Set up an Android build environment referring to [instruction](https://www.onnxruntime.ai/docs/how-to/build/android-ios.html#android) - ```python - python tools/ci_build/github/android/build_aar_package.py js/react_native/scripts/aar_build_settings.json --config MinSizeRel --android_sdk_path --android_ndk_path --build_dir - ``` + 3. In ``, run this python script to build ONNX Runtime Android archive file. In windows, this requires an admin account to build. To build a model specific package with reduced size, refer to [instruction](https://www.onnxruntime.ai/docs/how-to/build/reduced.html#build-ort-with-reduced-size). - 3. This generates `onnxruntime-mobile-.aar` in `/aar_out/MinSizeRel/com/microsoft/onnxruntime/onnxruntime-mobile/`. Copy `aar` file into `/js/react_native/android/libs` and rename it as `onnxruntime.aar` + ```sh + python tools/ci_build/github/android/build_aar_package.py tools/ci_build/github/android/default_mobile_aar_build_settings.json --config MinSizeRel --android_sdk_path --android_ndk_path --build_dir --include_ops_by_config tools/ci_build/github/android/mobile_package.required_operators.config + ``` - 4. To verify, open Android Emulator and run this command from `/js/react_native/android` + 4. Copy `/aar_out/MinSizeRel/com/microsoft/onnxruntime/onnxruntime-mobile//onnxruntime-mobile-.aar` into `/js/react_native/android/libs` directory. - ```sh - adb shell am instrument -w ai.onnxruntime.react_native.test/androidx.test.runner.AndroidJUnitRunner - ``` + 5. Modify `Onnxruntime_mobileVersion` property in `/js/react_native/android/build.properties` to consume a locally built package or a newly published package from Maven. + + 6. To verify, open Android Emulator and run this command from `/js/react_native/android` + + ```sh + adb shell am instrument -w ai.onnxruntime.react_native.test/androidx.test.runner.AndroidJUnitRunner + ``` 3. Build iOS ONNX Runtime package - 1. Set up iOS build environment referring to [instruction](https://www.onnxruntime.ai/docs/how-to/build.html#ios). + 1. To use a published c/c++ ONNX Runtime Mobile package from CocoaPods, skip all steps below. - 2. Build ONNX Runtime library for iOS from `` using this command, + 2. Set up iOS build environment referring to [instruction](https://www.onnxruntime.ai/docs/how-to/build/android-ios.html#ios). - ```sh - ./build.sh --config MinSizeRel --use_xcode --ios --ios_sysroot iphoneos --osx_arch arm64 --apple_deploy_target 11 - ``` + 3. Build a fat ONNX Runtime Mobile Framework for iOS and iOS simulator from `` using this command, - Copy `/build/iOS/MinSizeRel/MinSizeRel-iphoneos/libonnxruntime..dylib` file into `/js/react_native/ios/Libraries/onnxruntime/lib/iphoneos` + ```sh + python tools/ci_build/github/apple/build_ios_framework.py tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json --config MinSizeRel --include_ops_by_config tools/ci_build/github/android/mobile_package.required_operators.config + ``` - 3. Clean up the previous build and build ONNX Runtime library for iOS Simulator from `` + It creates `onnxruntime.framework` in `build/iOS_framework/framework_out` directory. Create an archive file of `onnxruntime.framework` directory as follows and copy to `/js/react_native/local_pods` directory. - ```sh - ./build.sh --config MinSizeRel --use_xcode --ios --ios_sysroot iphonesimulator --osx_arch x86_64 --apple_deploy_target 11 - ``` + ```sh + zip -r onnxruntime-mobile-c.zip onnxruntime.framework + ``` - Copy `/build/iOS/MinSizeRel/MinSizeRel-iphonesimulator/libonnxruntime..dylib` file into `/js/react_native/ios/Libraries/onnxruntime/lib/iphonesimulator` + 4. To verify, open iOS Simulator and run this command from `/js/react_native/ios`. Change a destination to specify a running iOS Simulator. - 4. Edit `onnxruntime-react-native.iphoneos.podspec` and `onnxruntime-react-native.iphonesimulator.podsepc` in `/js/react_native` to change a version of ONNX Runtime library. + ```sh + pod install + xcodebuild test -workspace OnnxruntimeModule.xcworkspace -scheme OnnxruntimeModuleTest -destination 'platform=iOS Simulator,name=iPhone 11,OS=14.5' + ``` - 5. Copy ONNX Runtime header files +4. Test an example for Android and iOS. In Windows, open Android Emulator first. From `/js/react_native` - ```sh - cp /include/onnxruntime/core/session/*.h /js/react_native/ios/Libraries/onnxruntime/include - ``` - - 6. To verify, open iOS Simulator and run this command from `/js/react_native/ios`. Change a destination to specify a running iOS Simulator. - ```sh - pod install - export ONNXRUNTIME_VERSION=; xcodebuild test -workspace OnnxruntimeModule.xcworkspace -scheme OnnxruntimeModuleTest -destination 'platform=iOS Simulator,name=iPhone 11,OS=14.5' - ``` - -4. Update a version in `package.json` to align with ONNX Runtime version. - -5. Test an example for Android and iOS. In Windows, open Android Emulator first. From `/js/react_native` - ```sh - yarn bootstrap - yarn example ios - yarn example android - ``` + ```sh + yarn bootstrap + yarn example ios + yarn example android + ``` ### NPM Packaging 1. Update a version using `npm verison ` from `/js/react_native` folder. If it's for a dev, use `npm version -dev.` -2. Run `yarn prepack` to change `onnxruntime-common` to point to a published npm package +2. Modify Onnxruntime_mobileVersion property in `/js/react_native/android/build.properties` to update ONNX Runtime Android package version. -3. Run `npm pack` and verify NPM package contents +3. Run `yarn prepack` to change `onnxruntime-common` to point to a published npm package -4. Run `npm publish --dry-run` to see how it's going to be published +4. Run `npm pack` and verify NPM package contents -5. Run `npm publish ` to publish to npmjs. If it's for a dev, add flag `--tag dev`. +5. Run `npm publish --dry-run` to see how it's going to be published + +6. Run `npm publish ` to publish to npmjs. If it's for a dev, add flag `--tag dev`. ### Distribution diff --git a/js/react_native/.gitignore b/js/react_native/.gitignore index 6f13cfe9c2..7bc424adb5 100644 --- a/js/react_native/.gitignore +++ b/js/react_native/.gitignore @@ -35,7 +35,8 @@ android.iml # Cocoapods # -example/ios/Pods +ios/Pods/ +example/ios/Pods/ # node.js # @@ -57,6 +58,4 @@ dist/ android/libs/*.aar # iOS -iOS/Libraries/onnxruntime/include/*.h -iOS/Libraries/onnxruntime/lib/iphoneos/*.dylib -iOS/Libraries/onnxruntime/lib/iphonesimulator/*.dylib +local_pods/ diff --git a/js/react_native/.npmignore b/js/react_native/.npmignore deleted file mode 100644 index 4b19f28fa9..0000000000 --- a/js/react_native/.npmignore +++ /dev/null @@ -1,8 +0,0 @@ -/.vscode/ -/scripts/ - -/dist/commonjs/*.js.map -/dist/module/*.js.map - -/tsconfig.json -/tsconfig.build.json diff --git a/js/react_native/README.md b/js/react_native/README.md index 65fb5d0a70..9fdc4a5fe9 100644 --- a/js/react_native/README.md +++ b/js/react_native/README.md @@ -2,13 +2,21 @@ ONNX Runtime React Native provides a JavaScript library for running ONNX models on React Native app. -## Installation +### Why ONNX models + +The [Open Neural Network Exchange](http://onnx.ai/) (ONNX) is an open standard for representing machine learning models. The biggest advantage of ONNX is that it allows interoperability across different open source AI frameworks, which itself offers more flexibility for AI frameworks adoption. + +### Why ONNX Runtime React Native + +With ONNX Runtime React Native, React Native developers can score pre-trained ONNX models directy on React Native apps by leveraging [ONNX Runtime Mobile](https://www.onnxruntime.ai/docs/reference/mobile/prebuilt-package/), so it provides a light-weight inference solution for Android and iOS. + +### Installation ```sh yarn add onnxruntime-react-native ``` -## Usage +### Usage ```js import { InferenceSession } from "onnxruntime-react-native"; @@ -19,11 +27,15 @@ const session: InferenceSession = await InferenceSession.create(modelPath); const result = session.run(input, ['num_detection:0', 'detection_classes:0']) ``` -Refer to [ONNX Runtime JavaScript examples](https://github.com/microsoft/onnxruntime-inference-examples/js) for samples and tutorials. Different from other JavaScript frameworks like node.js and web, React Native library doesn't support these features +Refer to [ONNX Runtime JavaScript examples](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js) for samples and tutorials. Different from other JavaScript frameworks like node.js and web, React Native library doesn't support these features. - Unsigned data type at Tensor - Model loading using ArrayBuffer -## License +### Operator and type support + +ONNX Runtime React Native currently supports most operators used by popular models. Refer to [ONNX Runtime Mobile Pacakge Operator and Type](https://www.onnxruntime.ai/docs/reference/mobile/prebuilt-package/1.8%20ORTMobilePackageOperatorTypeSupport). + +### License License information can be found [here](https://github.com/microsoft/onnxruntime/blob/master/README.md#license). diff --git a/js/react_native/android/build.gradle b/js/react_native/android/build.gradle index aefb867b3c..fde479d23f 100644 --- a/js/react_native/android/build.gradle +++ b/js/react_native/android/build.gradle @@ -121,16 +121,18 @@ repositories { } dependencies { + def onnxruntimeMobileVersion = project.properties['Onnxruntime_mobileVersion'] + // noinspection GradleDynamicVersion - api 'com.facebook.react:react-native:+' - api 'org.mockito:mockito-core:2.28.2' + api "com.facebook.react:react-native:+" + api "org.mockito:mockito-core:2.28.2" - androidTestImplementation 'androidx.test:runner:1.1.0' - androidTestImplementation 'androidx.test:rules:1.1.0' + androidTestImplementation "androidx.test:runner:1.1.0" + androidTestImplementation "androidx.test:rules:1.1.0" - implementation 'junit:junit:4.12' + implementation "junit:junit:4.12" - androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito-inline-extended:2.28.1' + androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito-inline-extended:2.28.1" - api(name:'onnxruntime', ext:'aar') + implementation "com.microsoft.onnxruntime:onnxruntime-mobile:$onnxruntimeMobileVersion@aar" } diff --git a/js/react_native/android/gradle.properties b/js/react_native/android/gradle.properties index 04f6e699f0..45c41813af 100644 --- a/js/react_native/android/gradle.properties +++ b/js/react_native/android/gradle.properties @@ -16,3 +16,4 @@ android.useAndroidX=true OnnxruntimeModule_buildToolsVersion=29.0.2 OnnxruntimeModule_compileSdkVersion=29 OnnxruntimeModule_targetSdkVersion=29 +Onnxruntime_mobileVersion=1.8.0 diff --git a/js/react_native/android/libs/.placeholder b/js/react_native/android/libs/.placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/js/react_native/android/src/androidTest/java/ai/onnxruntime/reactnative/OnnxruntimeModuleTest.java b/js/react_native/android/src/androidTest/java/ai/onnxruntime/reactnative/OnnxruntimeModuleTest.java index a6d8b49697..448ece3963 100644 --- a/js/react_native/android/src/androidTest/java/ai/onnxruntime/reactnative/OnnxruntimeModuleTest.java +++ b/js/react_native/android/src/androidTest/java/ai/onnxruntime/reactnative/OnnxruntimeModuleTest.java @@ -82,7 +82,7 @@ public class OnnxruntimeModuleTest { } inputTensorMap.putArray("dims", dimsArray); - inputTensorMap.putString("type", TensorHelper.TensorTypeFloat); + inputTensorMap.putString("type", TensorHelper.JsTensorTypeFloat); ByteBuffer buffer = ByteBuffer.allocate(5 * Float.BYTES).order(ByteOrder.nativeOrder()); FloatBuffer floatBuffer = buffer.asFloatBuffer(); @@ -109,7 +109,7 @@ public class OnnxruntimeModuleTest { for (int i = 0; i < 2; ++i) { Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeFloat); + Assert.assertEquals(outputMap.getString("type"), TensorHelper.JsTensorTypeFloat); String dataEncoded = outputMap.getString("data"); FloatBuffer buffer = ByteBuffer.wrap(Base64.decode(dataEncoded, Base64.DEFAULT)) .order(ByteOrder.nativeOrder()) diff --git a/js/react_native/android/src/androidTest/java/ai/onnxruntime/reactnative/TensorHelperTest.java b/js/react_native/android/src/androidTest/java/ai/onnxruntime/reactnative/TensorHelperTest.java index d0f8908e2c..fd3ea4494d 100644 --- a/js/react_native/android/src/androidTest/java/ai/onnxruntime/reactnative/TensorHelperTest.java +++ b/js/react_native/android/src/androidTest/java/ai/onnxruntime/reactnative/TensorHelperTest.java @@ -56,7 +56,7 @@ public class TensorHelperTest { dims.pushInt(3); inputTensorMap.putArray("dims", dims); - inputTensorMap.putString("type", TensorHelper.TensorTypeFloat); + inputTensorMap.putString("type", TensorHelper.JsTensorTypeFloat); ByteBuffer dataByteBuffer = ByteBuffer.allocate(3 * 4).order(ByteOrder.nativeOrder()); FloatBuffer dataFloatBuffer = dataByteBuffer.asFloatBuffer(); @@ -87,7 +87,7 @@ public class TensorHelperTest { dims.pushInt(3); inputTensorMap.putArray("dims", dims); - inputTensorMap.putString("type", TensorHelper.TensorTypeByte); + inputTensorMap.putString("type", TensorHelper.JsTensorTypeByte); ByteBuffer dataByteBuffer = ByteBuffer.allocate(3); dataByteBuffer.put(Byte.MIN_VALUE); @@ -107,38 +107,6 @@ public class TensorHelperTest { outputTensor.close(); } - @Test - public void createInputTensor_int16() throws Exception { - OnnxTensor outputTensor = - OnnxTensor.createTensor(ortEnvironment, new short[] {Short.MIN_VALUE, 2, Short.MAX_VALUE}); - - JavaOnlyMap inputTensorMap = new JavaOnlyMap(); - - JavaOnlyArray dims = new JavaOnlyArray(); - dims.pushInt(3); - inputTensorMap.putArray("dims", dims); - - inputTensorMap.putString("type", TensorHelper.TensorTypeShort); - - ByteBuffer dataByteBuffer = ByteBuffer.allocate(3 * 2).order(ByteOrder.nativeOrder()); - ShortBuffer dataShortBuffer = dataByteBuffer.asShortBuffer(); - dataShortBuffer.put(Short.MIN_VALUE); - dataShortBuffer.put((short)2); - dataShortBuffer.put(Short.MAX_VALUE); - String dataEncoded = Base64.encodeToString(dataByteBuffer.array(), Base64.DEFAULT); - inputTensorMap.putString("data", dataEncoded); - - OnnxTensor inputTensor = TensorHelper.createInputTensor(inputTensorMap, ortEnvironment); - - Assert.assertEquals(inputTensor.getInfo().onnxType, TensorInfo.OnnxTensorType.ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16); - Assert.assertEquals(outputTensor.getInfo().onnxType, TensorInfo.OnnxTensorType.ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16); - Assert.assertEquals(inputTensor.toString(), outputTensor.toString()); - Assert.assertArrayEquals(inputTensor.getShortBuffer().array(), outputTensor.getShortBuffer().array()); - - inputTensor.close(); - outputTensor.close(); - } - @Test public void createInputTensor_int32() throws Exception { OnnxTensor outputTensor = @@ -150,7 +118,7 @@ public class TensorHelperTest { dims.pushInt(3); inputTensorMap.putArray("dims", dims); - inputTensorMap.putString("type", TensorHelper.TensorTypeInt); + inputTensorMap.putString("type", TensorHelper.JsTensorTypeInt); ByteBuffer dataByteBuffer = ByteBuffer.allocate(3 * 4).order(ByteOrder.nativeOrder()); IntBuffer dataIntBuffer = dataByteBuffer.asIntBuffer(); @@ -182,7 +150,7 @@ public class TensorHelperTest { dims.pushInt(3); inputTensorMap.putArray("dims", dims); - inputTensorMap.putString("type", TensorHelper.TensorTypeLong); + inputTensorMap.putString("type", TensorHelper.JsTensorTypeLong); ByteBuffer dataByteBuffer = ByteBuffer.allocate(3 * 8).order(ByteOrder.nativeOrder()); LongBuffer dataLongBuffer = dataByteBuffer.asLongBuffer(); @@ -203,38 +171,6 @@ public class TensorHelperTest { outputTensor.close(); } - @Test - public void createInputTensor_string() throws Exception { - OnnxTensor outputTensor = OnnxTensor.createTensor(ortEnvironment, new String[] {"a", "b", "c"}, new long[] {3}); - - JavaOnlyMap inputTensorMap = new JavaOnlyMap(); - - JavaOnlyArray dims = new JavaOnlyArray(); - dims.pushInt(3); - inputTensorMap.putArray("dims", dims); - - inputTensorMap.putString("type", TensorHelper.TensorTypeString); - - JavaOnlyArray data = new JavaOnlyArray(); - data.pushString("a"); - data.pushString("b"); - data.pushString("c"); - inputTensorMap.putArray("data", data); - - OnnxTensor inputTensor = TensorHelper.createInputTensor(inputTensorMap, ortEnvironment); - - Assert.assertEquals(inputTensor.getInfo().onnxType, TensorInfo.OnnxTensorType.ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING); - Assert.assertEquals(outputTensor.getInfo().onnxType, - TensorInfo.OnnxTensorType.ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING); - Assert.assertEquals(inputTensor.toString(), outputTensor.toString()); - String[] inputData = (String[])inputTensor.getValue(); - String[] outputData = (String[])outputTensor.getValue(); - Assert.assertArrayEquals(inputData, outputData); - - inputTensor.close(); - outputTensor.close(); - } - @Test public void createInputTensor_double() throws Exception { OnnxTensor outputTensor = @@ -246,7 +182,7 @@ public class TensorHelperTest { dims.pushInt(3); inputTensorMap.putArray("dims", dims); - inputTensorMap.putString("type", TensorHelper.TensorTypeDouble); + inputTensorMap.putString("type", TensorHelper.JsTensorTypeDouble); ByteBuffer dataByteBuffer = ByteBuffer.allocate(3 * 8).order(ByteOrder.nativeOrder()); DoubleBuffer dataDoubleBuffer = dataByteBuffer.asDoubleBuffer(); @@ -295,7 +231,7 @@ public class TensorHelperTest { for (int i = 0; i < 2; ++i) { Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeBool); + Assert.assertEquals(outputMap.getString("type"), TensorHelper.JsTensorTypeBool); String dataEncoded = outputMap.getString("data"); ByteBuffer buffer = ByteBuffer.wrap(Base64.decode(dataEncoded, Base64.DEFAULT)); for (int i = 0; i < 5; ++i) { @@ -335,7 +271,7 @@ public class TensorHelperTest { for (int i = 0; i < 2; ++i) { Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeDouble); + Assert.assertEquals(outputMap.getString("type"), TensorHelper.JsTensorTypeDouble); String dataEncoded = outputMap.getString("data"); DoubleBuffer buffer = ByteBuffer.wrap(Base64.decode(dataEncoded, Base64.DEFAULT)).order(ByteOrder.nativeOrder()).asDoubleBuffer(); @@ -376,7 +312,7 @@ public class TensorHelperTest { for (int i = 0; i < 2; ++i) { Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeFloat); + Assert.assertEquals(outputMap.getString("type"), TensorHelper.JsTensorTypeFloat); String dataEncoded = outputMap.getString("data"); FloatBuffer buffer = ByteBuffer.wrap(Base64.decode(dataEncoded, Base64.DEFAULT)).order(ByteOrder.nativeOrder()).asFloatBuffer(); @@ -417,7 +353,7 @@ public class TensorHelperTest { for (int i = 0; i < 2; ++i) { Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeByte); + Assert.assertEquals(outputMap.getString("type"), TensorHelper.JsTensorTypeByte); String dataEncoded = outputMap.getString("data"); ByteBuffer buffer = ByteBuffer.wrap(Base64.decode(dataEncoded, Base64.DEFAULT)); for (int i = 0; i < 5; ++i) { @@ -430,47 +366,6 @@ public class TensorHelperTest { } } - @Test - public void createOutputTensor_int16() throws Exception { - MockitoSession mockSession = mockitoSession().mockStatic(Arguments.class).startMocking(); - try { - when(Arguments.createMap()).thenAnswer(i -> new JavaOnlyMap()); - when(Arguments.createArray()).thenAnswer(i -> new JavaOnlyArray()); - - OrtSession.SessionOptions options = new OrtSession.SessionOptions(); - byte[] modelData = readBytesFromResourceFile(ai.onnxruntime.reactnative.test.R.raw.test_types_int16); - OrtSession session = ortEnvironment.createSession(modelData, options); - - long[] dims = new long[] {1, 5}; - short[] inputData = new short[] {1, 2, -3, Short.MIN_VALUE, Short.MAX_VALUE}; - - String inputName = session.getInputNames().iterator().next(); - Map container = new HashMap<>(); - Object tensorInput = OrtUtil.reshape(inputData, dims); - OnnxTensor onnxTensor = OnnxTensor.createTensor(ortEnvironment, tensorInput); - container.put(inputName, onnxTensor); - - OrtSession.Result result = session.run(container); - - ReadableMap resultMap = TensorHelper.createOutputTensor(result); - ReadableMap outputMap = resultMap.getMap("output"); - for (int i = 0; i < 2; ++i) { - Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); - } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeShort); - String dataEncoded = outputMap.getString("data"); - ShortBuffer buffer = - ByteBuffer.wrap(Base64.decode(dataEncoded, Base64.DEFAULT)).order(ByteOrder.nativeOrder()).asShortBuffer(); - for (int i = 0; i < 5; ++i) { - Assert.assertEquals(buffer.get(i), inputData[i]); - } - - OnnxValue.close(container); - } finally { - mockSession.finishMocking(); - } - } - @Test public void createOutputTensor_int32() throws Exception { MockitoSession mockSession = mockitoSession().mockStatic(Arguments.class).startMocking(); @@ -498,7 +393,7 @@ public class TensorHelperTest { for (int i = 0; i < 2; ++i) { Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeInt); + Assert.assertEquals(outputMap.getString("type"), TensorHelper.JsTensorTypeInt); String dataEncoded = outputMap.getString("data"); IntBuffer buffer = ByteBuffer.wrap(Base64.decode(dataEncoded, Base64.DEFAULT)).order(ByteOrder.nativeOrder()).asIntBuffer(); @@ -539,7 +434,7 @@ public class TensorHelperTest { for (int i = 0; i < 2; ++i) { Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeLong); + Assert.assertEquals(outputMap.getString("type"), TensorHelper.JsTensorTypeLong); String dataEncoded = outputMap.getString("data"); LongBuffer buffer = ByteBuffer.wrap(Base64.decode(dataEncoded, Base64.DEFAULT)).order(ByteOrder.nativeOrder()).asLongBuffer(); @@ -553,44 +448,6 @@ public class TensorHelperTest { } } - @Test - public void createOutputTensor_string() throws Exception { - MockitoSession mockSession = mockitoSession().mockStatic(Arguments.class).startMocking(); - try { - when(Arguments.createMap()).thenAnswer(i -> new JavaOnlyMap()); - when(Arguments.createArray()).thenAnswer(i -> new JavaOnlyArray()); - - OrtSession.SessionOptions options = new OrtSession.SessionOptions(); - byte[] modelData = readBytesFromResourceFile(ai.onnxruntime.reactnative.test.R.raw.test_types_string); - OrtSession session = ortEnvironment.createSession(modelData, options); - - long[] dims = new long[] {1, 5}; - String[] inputData = new String[] {"a", "b", "c", "d", "e"}; - - String inputName = session.getInputNames().iterator().next(); - Map container = new HashMap<>(); - OnnxTensor onnxTensor = OnnxTensor.createTensor(ortEnvironment, inputData, dims); - container.put(inputName, onnxTensor); - - OrtSession.Result result = session.run(container); - String[] outputData = (String[])((OnnxTensor)result.get(0)).getValue(); - - ReadableMap resultMap = TensorHelper.createOutputTensor(result); - ReadableMap outputMap = resultMap.getMap("output"); - for (int i = 0; i < 2; ++i) { - Assert.assertEquals(outputMap.getArray("dims").getInt(i), dims[i]); - } - Assert.assertEquals(outputMap.getString("type"), TensorHelper.TensorTypeString); - for (int i = 0; i < 5; ++i) { - Assert.assertEquals(outputMap.getArray("data").getString(i), inputData[i]); - } - - OnnxValue.close(container); - } finally { - mockSession.finishMocking(); - } - } - private byte[] readBytesFromResourceFile(int resourceId) throws Exception { Context context = InstrumentationRegistry.getInstrumentation().getContext(); InputStream inputStream = context.getResources().openRawResource(resourceId); diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_bool.ort b/js/react_native/android/src/androidTest/res/raw/test_types_bool.ort new file mode 100644 index 0000000000..9267bee5ab Binary files /dev/null and b/js/react_native/android/src/androidTest/res/raw/test_types_bool.ort differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_bool.pb b/js/react_native/android/src/androidTest/res/raw/test_types_bool.pb deleted file mode 100644 index 2c58b06d0a..0000000000 Binary files a/js/react_native/android/src/androidTest/res/raw/test_types_bool.pb and /dev/null differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_double.ort b/js/react_native/android/src/androidTest/res/raw/test_types_double.ort new file mode 100644 index 0000000000..9030eca3e4 Binary files /dev/null and b/js/react_native/android/src/androidTest/res/raw/test_types_double.ort differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_double.pb b/js/react_native/android/src/androidTest/res/raw/test_types_double.pb deleted file mode 100644 index 65ebf0f848..0000000000 Binary files a/js/react_native/android/src/androidTest/res/raw/test_types_double.pb and /dev/null differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_float.ort b/js/react_native/android/src/androidTest/res/raw/test_types_float.ort new file mode 100644 index 0000000000..01f489572b Binary files /dev/null and b/js/react_native/android/src/androidTest/res/raw/test_types_float.ort differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_float.pb b/js/react_native/android/src/androidTest/res/raw/test_types_float.pb deleted file mode 100644 index b4ad980783..0000000000 Binary files a/js/react_native/android/src/androidTest/res/raw/test_types_float.pb and /dev/null differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_int16.pb b/js/react_native/android/src/androidTest/res/raw/test_types_int16.pb deleted file mode 100644 index f297ec9c54..0000000000 Binary files a/js/react_native/android/src/androidTest/res/raw/test_types_int16.pb and /dev/null differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_int32.ort b/js/react_native/android/src/androidTest/res/raw/test_types_int32.ort new file mode 100644 index 0000000000..8aecad72cf Binary files /dev/null and b/js/react_native/android/src/androidTest/res/raw/test_types_int32.ort differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_int32.pb b/js/react_native/android/src/androidTest/res/raw/test_types_int32.pb deleted file mode 100644 index 73bb539cf4..0000000000 Binary files a/js/react_native/android/src/androidTest/res/raw/test_types_int32.pb and /dev/null differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_int64.ort b/js/react_native/android/src/androidTest/res/raw/test_types_int64.ort new file mode 100644 index 0000000000..b84dc2944b Binary files /dev/null and b/js/react_native/android/src/androidTest/res/raw/test_types_int64.ort differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_int64.pb b/js/react_native/android/src/androidTest/res/raw/test_types_int64.pb deleted file mode 100644 index ccf8df0033..0000000000 Binary files a/js/react_native/android/src/androidTest/res/raw/test_types_int64.pb and /dev/null differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_int8.ort b/js/react_native/android/src/androidTest/res/raw/test_types_int8.ort new file mode 100644 index 0000000000..d762f2c5eb Binary files /dev/null and b/js/react_native/android/src/androidTest/res/raw/test_types_int8.ort differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_int8.pb b/js/react_native/android/src/androidTest/res/raw/test_types_int8.pb deleted file mode 100644 index 72698a7795..0000000000 Binary files a/js/react_native/android/src/androidTest/res/raw/test_types_int8.pb and /dev/null differ diff --git a/js/react_native/android/src/androidTest/res/raw/test_types_string.pb b/js/react_native/android/src/androidTest/res/raw/test_types_string.pb deleted file mode 100644 index 7c8b3e7e2e..0000000000 Binary files a/js/react_native/android/src/androidTest/res/raw/test_types_string.pb and /dev/null differ diff --git a/js/react_native/example/android/app/src/main/assets/mnist.onnx b/js/react_native/example/android/app/src/main/assets/mnist.onnx deleted file mode 100644 index bb189a52ea..0000000000 Binary files a/js/react_native/example/android/app/src/main/assets/mnist.onnx and /dev/null differ diff --git a/js/react_native/example/android/app/src/main/assets/mnist.ort b/js/react_native/example/android/app/src/main/assets/mnist.ort new file mode 100644 index 0000000000..58dd9e664a Binary files /dev/null and b/js/react_native/example/android/app/src/main/assets/mnist.ort differ diff --git a/js/react_native/example/android/app/src/main/java/com/example/reactnativeonnxruntimemodule/MNISTDataHandler.java b/js/react_native/example/android/app/src/main/java/com/example/reactnativeonnxruntimemodule/MNISTDataHandler.java index f9733bc202..a6e80ca9b0 100644 --- a/js/react_native/example/android/app/src/main/java/com/example/reactnativeonnxruntimemodule/MNISTDataHandler.java +++ b/js/react_native/example/android/app/src/main/java/com/example/reactnativeonnxruntimemodule/MNISTDataHandler.java @@ -64,7 +64,7 @@ public class MNISTDataHandler extends ReactContextBaseJavaModule { @ReactMethod public void getLocalModelPath(Promise promise) { try { - String modelPath = copyFile(reactContext, "mnist.onnx"); + String modelPath = copyFile(reactContext, "mnist.ort"); promise.resolve(modelPath); } catch (Exception e) { promise.reject("Can't get a mdoel", e); @@ -111,7 +111,6 @@ public class MNISTDataHandler extends ReactContextBaseJavaModule { // returns cooked data formatted as input of a model by promise. private WritableMap preprocess(String uri) throws Exception { final int batchSize = 1; - final int channelSize = 1; final int imageHeight = 28; final int imageWidth = 28; @@ -127,8 +126,7 @@ public class MNISTDataHandler extends ReactContextBaseJavaModule { // Resize bitmap to 28x28 bitmap = Bitmap.createScaledBitmap(bitmap, imageWidth, imageHeight, false); - ByteBuffer imageByteBuffer = - ByteBuffer.allocate(imageHeight * imageWidth * channelSize * 4).order(ByteOrder.nativeOrder()); + ByteBuffer imageByteBuffer = ByteBuffer.allocate(imageHeight * imageWidth * 4).order(ByteOrder.nativeOrder()); FloatBuffer imageFloatBuffer = imageByteBuffer.asFloatBuffer(); for (int h = 0; h < imageHeight; ++h) { for (int w = 0; w < imageWidth; ++w) { @@ -145,7 +143,6 @@ public class MNISTDataHandler extends ReactContextBaseJavaModule { WritableArray dims = Arguments.createArray(); dims.pushInt(batchSize); - dims.pushInt(channelSize); dims.pushInt(imageHeight); dims.pushInt(imageWidth); inputTensorMap.putArray("dims", dims); @@ -158,7 +155,7 @@ public class MNISTDataHandler extends ReactContextBaseJavaModule { String data = Base64.encodeToString(imageByteBuffer.array(), Base64.DEFAULT); inputTensorMap.putString("data", data); - inputDataMap.putMap("Input3", inputTensorMap); + inputDataMap.putMap("flatten_2_input", inputTensorMap); return inputDataMap; } @@ -167,7 +164,7 @@ public class MNISTDataHandler extends ReactContextBaseJavaModule { private WritableMap postprocess(ReadableMap result) throws Exception { String detectionResult = ""; - ReadableMap outputTensor = result.getMap("Plus214_Output_0"); + ReadableMap outputTensor = result.getMap("Identity"); String outputData = outputTensor.getString("data"); FloatBuffer buffer = @@ -177,24 +174,16 @@ public class MNISTDataHandler extends ReactContextBaseJavaModule { dataArray.add((double)buffer.get()); } - final double max = Collections.max(dataArray); - double total = 0.0f; - for (int i = 0; i < dataArray.size(); ++i) { - dataArray.set(i, Math.exp((double)dataArray.get(i) - max)); - total += dataArray.get(i); - } - double[] softmax = new double[dataArray.size()]; int argmax = 0; double maxValue = 0; for (int i = 0; i < dataArray.size(); ++i) { - softmax[i] = dataArray.get(i) / total; - if (softmax[i] > maxValue) { - maxValue = softmax[i]; + if (dataArray.get(i) > maxValue) { + maxValue = dataArray.get(i); argmax = i; } } - if (max == 0) { + if (maxValue == 0) { detectionResult = "No match"; } else { detectionResult = "I guess, it's " + argmax; diff --git a/js/react_native/example/ios/MNISTDataHandler.mm b/js/react_native/example/ios/MNISTDataHandler.mm index 98d6c23c58..74477376c1 100644 --- a/js/react_native/example/ios/MNISTDataHandler.mm +++ b/js/react_native/example/ios/MNISTDataHandler.mm @@ -17,7 +17,7 @@ RCT_EXPORT_MODULE(MNISTDataHandler) // so that onnxruntime is able to load a model using a given path. RCT_EXPORT_METHOD(getLocalModelPath : (RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) { @try { - NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"mnist" ofType:@"onnx"]; + NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"mnist" ofType:@"ort"]; NSFileManager *fileManager = [NSFileManager defaultManager]; if ([fileManager fileExistsAtPath:modelPath]) { resolve(modelPath); @@ -97,8 +97,7 @@ RCT_EXPORT_METHOD(postprocess CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); CGContextRelease(context); - const NSInteger channelSize = 1; - const NSInteger dimSize = height * width * channelSize; + const NSInteger dimSize = height * width; const NSInteger byteBufferSize = dimSize * sizeof(float); unsigned char *byteBuffer = static_cast(malloc(byteBufferSize)); @@ -118,7 +117,7 @@ RCT_EXPORT_METHOD(postprocess // dims NSArray *dims = @[ - [NSNumber numberWithInt:1], [NSNumber numberWithInt:channelSize], [NSNumber numberWithInt:static_cast(height)], + [NSNumber numberWithInt:1], [NSNumber numberWithInt:static_cast(height)], [NSNumber numberWithInt:static_cast(width)] ]; inputTensorMap[@"dims"] = dims; @@ -130,7 +129,7 @@ RCT_EXPORT_METHOD(postprocess NSString *data = [byteBufferRef base64EncodedStringWithOptions:0]; inputTensorMap[@"data"] = data; - inputDataMap[@"Input3"] = inputTensorMap; + inputDataMap[@"flatten_2_input"] = inputTensorMap; return inputDataMap; } @@ -138,31 +137,18 @@ RCT_EXPORT_METHOD(postprocess - (NSDictionary *)postprocess:(NSDictionary *)result { NSMutableString *detectionResult = [NSMutableString string]; - NSDictionary *outputTensor = [result objectForKey:@"Plus214_Output_0"]; + NSDictionary *outputTensor = [result objectForKey:@"Identity"]; NSString *data = [outputTensor objectForKey:@"data"]; NSData *buffer = [[NSData alloc] initWithBase64EncodedString:data options:0]; float *values = (float *)[buffer bytes]; int count = (int)[buffer length] / 4; - double maxValue = 0.0f; + int argmax = 0; + float maxValue = 0.0f; for (int i = 0; i < count; ++i) { if (values[i] > maxValue) { maxValue = values[i]; - } - } - double total = 0.0f; - for (int i = 0; i < count; ++i) { - values[i] = exp(values[i] - maxValue); - total += values[i]; - } - std::vector softmax(count); - int argmax = 0; - maxValue = 0.0f; - for (int i = 0; i < count; ++i) { - softmax[i] = values[i] / total; - if (softmax[i] > maxValue) { - maxValue = softmax[i]; argmax = i; } } diff --git a/js/react_native/example/ios/OnnxruntimeModuleExample.xcodeproj/project.pbxproj b/js/react_native/example/ios/OnnxruntimeModuleExample.xcodeproj/project.pbxproj index 6294e84b32..a79a06abdf 100644 --- a/js/react_native/example/ios/OnnxruntimeModuleExample.xcodeproj/project.pbxproj +++ b/js/react_native/example/ios/OnnxruntimeModuleExample.xcodeproj/project.pbxproj @@ -10,11 +10,11 @@ 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; - 2B52F02C66A197669308C74D /* libPods-OnnxruntimeModuleExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6784A38AC4BD8C34E1D90B74 /* libPods-OnnxruntimeModuleExample.a */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; + A769E116237385B138BCB816 /* Pods_OnnxruntimeModuleExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0C2AC7C168BAB1163669C38C /* Pods_OnnxruntimeModuleExample.framework */; }; + DBA8BA87267293C4008CC55A /* mnist.ort in Resources */ = {isa = PBXBuildFile; fileRef = DBA8BA86267293C4008CC55A /* mnist.ort */; }; DBBF7412263B8C7100487C77 /* MNISTDataHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = DBBF7411263B8C7100487C77 /* MNISTDataHandler.mm */; }; DBBF7414263B8CCB00487C77 /* 3.jpg in Resources */ = {isa = PBXBuildFile; fileRef = DBBF7413263B8CCB00487C77 /* 3.jpg */; }; - DBBF7416263B8CD900487C77 /* mnist.onnx in Resources */ = {isa = PBXBuildFile; fileRef = DBBF7415263B8CD900487C77 /* mnist.onnx */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -32,6 +32,7 @@ /* Begin PBXFileReference section */ 008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = ""; }; + 0C2AC7C168BAB1163669C38C /* Pods_OnnxruntimeModuleExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OnnxruntimeModuleExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 13B07F961A680F5B00A75B9A /* OnnxruntimeModuleExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OnnxruntimeModuleExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = OnnxruntimeModuleExample/AppDelegate.h; sourceTree = ""; }; 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = OnnxruntimeModuleExample/AppDelegate.m; sourceTree = ""; }; @@ -39,12 +40,11 @@ 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = OnnxruntimeModuleExample/Info.plist; sourceTree = ""; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = OnnxruntimeModuleExample/main.m; sourceTree = ""; }; 47F7ED3B7971BE374F7B8635 /* Pods-OnnxruntimeModuleExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OnnxruntimeModuleExample.debug.xcconfig"; path = "Target Support Files/Pods-OnnxruntimeModuleExample/Pods-OnnxruntimeModuleExample.debug.xcconfig"; sourceTree = ""; }; - 6784A38AC4BD8C34E1D90B74 /* libPods-OnnxruntimeModuleExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OnnxruntimeModuleExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = OnnxruntimeModuleExample/LaunchScreen.storyboard; sourceTree = ""; }; + DBA8BA86267293C4008CC55A /* mnist.ort */ = {isa = PBXFileReference; lastKnownFileType = file; name = mnist.ort; path = ../src/mnist.ort; sourceTree = ""; }; DBBF7410263B8C5F00487C77 /* MNISTDataHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MNISTDataHandler.h; sourceTree = ""; }; DBBF7411263B8C7100487C77 /* MNISTDataHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MNISTDataHandler.mm; sourceTree = ""; }; DBBF7413263B8CCB00487C77 /* 3.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = 3.jpg; path = ../src/3.jpg; sourceTree = ""; }; - DBBF7415263B8CD900487C77 /* mnist.onnx */ = {isa = PBXFileReference; lastKnownFileType = file; name = mnist.onnx; path = ../src/mnist.onnx; sourceTree = ""; }; E00ACF0FDA8BF921659E2F9A /* Pods-OnnxruntimeModuleExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OnnxruntimeModuleExample.release.xcconfig"; path = "Target Support Files/Pods-OnnxruntimeModuleExample/Pods-OnnxruntimeModuleExample.release.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -54,7 +54,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 2B52F02C66A197669308C74D /* libPods-OnnxruntimeModuleExample.a in Frameworks */, + A769E116237385B138BCB816 /* Pods_OnnxruntimeModuleExample.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -81,7 +81,7 @@ isa = PBXGroup; children = ( ED297162215061F000B7C4FE /* JavaScriptCore.framework */, - 6784A38AC4BD8C34E1D90B74 /* libPods-OnnxruntimeModuleExample.a */, + 0C2AC7C168BAB1163669C38C /* Pods_OnnxruntimeModuleExample.framework */, ); name = Frameworks; sourceTree = ""; @@ -105,7 +105,7 @@ 83CBB9F61A601CBA00E9B192 = { isa = PBXGroup; children = ( - DBBF7415263B8CD900487C77 /* mnist.onnx */, + DBA8BA86267293C4008CC55A /* mnist.ort */, DBBF7413263B8CCB00487C77 /* 3.jpg */, 13B07FAE1A68108700A75B9A /* OnnxruntimeModuleExample */, 832341AE1AAA6A7D00B99B32 /* Libraries */, @@ -139,9 +139,8 @@ 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, - C1D60D28B925C94BD88E79D7 /* [CP] Copy Pods Resources */, DB8FCD9C25C3404B00C72F26 /* Embed Libraries */, - 3EBF64FAD8377366F1ED4D7E /* [CP] Embed Pods Frameworks */, + 16EFC8544779C8326869A95A /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -189,7 +188,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - DBBF7416263B8CD900487C77 /* mnist.onnx in Resources */, + DBA8BA87267293C4008CC55A /* mnist.ort in Resources */, DBBF7414263B8CCB00487C77 /* 3.jpg in Resources */, 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, @@ -213,18 +212,62 @@ shellPath = /bin/sh; shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; }; - 3EBF64FAD8377366F1ED4D7E /* [CP] Embed Pods Frameworks */ = { + 16EFC8544779C8326869A95A /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-OnnxruntimeModuleExample/Pods-OnnxruntimeModuleExample-frameworks.sh", - "${PODS_ROOT}/../../../ios/Libraries/onnxruntime/lib/iphonesimulator/libonnxruntime.1.7.0.dylib", + "${BUILT_PRODUCTS_DIR}/DoubleConversion/DoubleConversion.framework", + "${BUILT_PRODUCTS_DIR}/FBReactNativeSpec/FBReactNativeSpec.framework", + "${BUILT_PRODUCTS_DIR}/Folly/folly.framework", + "${BUILT_PRODUCTS_DIR}/RCTTypeSafety/RCTTypeSafety.framework", + "${BUILT_PRODUCTS_DIR}/React-Core/React.framework", + "${BUILT_PRODUCTS_DIR}/React-CoreModules/CoreModules.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTAnimation/RCTAnimation.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTBlob/RCTBlob.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTImage/RCTImage.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTLinking/RCTLinking.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTNetwork/RCTNetwork.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTSettings/RCTSettings.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTText/RCTText.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTVibration/RCTVibration.framework", + "${BUILT_PRODUCTS_DIR}/React-cxxreact/cxxreact.framework", + "${BUILT_PRODUCTS_DIR}/React-jsi/jsi.framework", + "${BUILT_PRODUCTS_DIR}/React-jsiexecutor/jsireact.framework", + "${BUILT_PRODUCTS_DIR}/React-jsinspector/jsinspector.framework", + "${BUILT_PRODUCTS_DIR}/ReactCommon/ReactCommon.framework", + "${BUILT_PRODUCTS_DIR}/Yoga/yoga.framework", + "${BUILT_PRODUCTS_DIR}/glog/glog.framework", + "${PODS_ROOT}/onnxruntime-mobile-c/onnxruntime.framework", + "${BUILT_PRODUCTS_DIR}/onnxruntime-react-native/onnxruntime_react_native.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libonnxruntime.1.7.0.dylib", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DoubleConversion.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBReactNativeSpec.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/folly.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTTypeSafety.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/React.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CoreModules.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTAnimation.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTBlob.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTImage.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTLinking.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTNetwork.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTSettings.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTText.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTVibration.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/cxxreact.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/jsi.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/jsireact.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/jsinspector.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ReactCommon.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/yoga.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/glog.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/onnxruntime.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/onnxruntime_react_native.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -253,24 +296,6 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - C1D60D28B925C94BD88E79D7 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-OnnxruntimeModuleExample/Pods-OnnxruntimeModuleExample-resources.sh", - "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-OnnxruntimeModuleExample/Pods-OnnxruntimeModuleExample-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; FD10A7F022414F080027D42C /* Start Packager */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/js/react_native/example/ios/Podfile b/js/react_native/example/ios/Podfile index 4b354fa7b3..86f4afd679 100644 --- a/js/react_native/example/ios/Podfile +++ b/js/react_native/example/ios/Podfile @@ -1,12 +1,16 @@ require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' -platform :ios, '10.0' +platform :ios, '13.0' target 'OnnxruntimeModuleExample' do config = use_native_modules! use_react_native!(:path => config["reactNativePath"]) - pod 'onnxruntime-react-native.iphonesimulator', :path => '../..' + use_frameworks! + pod 'onnxruntime-mobile-c', :podspec => '../../onnxruntime-mobile-c.podspec' + pod 'onnxruntime-react-native', :path => '../..' + + inherit! :search_paths end diff --git a/js/react_native/example/src/mnist.onnx b/js/react_native/example/src/mnist.onnx deleted file mode 100644 index bb189a52ea..0000000000 Binary files a/js/react_native/example/src/mnist.onnx and /dev/null differ diff --git a/js/react_native/example/src/mnist.ort b/js/react_native/example/src/mnist.ort new file mode 100644 index 0000000000..58dd9e664a Binary files /dev/null and b/js/react_native/example/src/mnist.ort differ diff --git a/js/react_native/ios/Libraries/onnxruntime/include/.placeholder b/js/react_native/ios/Libraries/onnxruntime/include/.placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/js/react_native/ios/Libraries/onnxruntime/lib/iphoneos/.placeholder b/js/react_native/ios/Libraries/onnxruntime/lib/iphoneos/.placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/js/react_native/ios/Libraries/onnxruntime/lib/iphonesimulator/.placeholder b/js/react_native/ios/Libraries/onnxruntime/lib/iphonesimulator/.placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/js/react_native/ios/OnnxruntimeModule.mm b/js/react_native/ios/OnnxruntimeModule.mm index 69dd8a1e1a..e22e3f3997 100644 --- a/js/react_native/ios/OnnxruntimeModule.mm +++ b/js/react_native/ios/OnnxruntimeModule.mm @@ -3,9 +3,10 @@ #import "OnnxruntimeModule.h" #import "TensorHelper.h" -#import "onnxruntime_cxx_api.h" + #import #import +#import @implementation OnnxruntimeModule diff --git a/js/react_native/ios/OnnxruntimeModule.xcodeproj/project.pbxproj b/js/react_native/ios/OnnxruntimeModule.xcodeproj/project.pbxproj index e676fef382..3792eece99 100644 --- a/js/react_native/ios/OnnxruntimeModule.xcodeproj/project.pbxproj +++ b/js/react_native/ios/OnnxruntimeModule.xcodeproj/project.pbxproj @@ -7,16 +7,14 @@ objects = { /* Begin PBXBuildFile section */ - D1D81F804850BCAF0F66320B /* libPods-OnnxruntimeModuleTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4ED4282B152369F0F6753107 /* libPods-OnnxruntimeModuleTest.a */; }; + 094C43D4312FB83139FA4E3B /* Pods_OnnxruntimeModule.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83B4C5FACE5CEC3A22F50945 /* Pods_OnnxruntimeModule.framework */; }; + 9B52917A0F2BDC354D087A67 /* Pods_OnnxruntimeModuleTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 69B56D4AAAA9C6D8C15652DC /* Pods_OnnxruntimeModuleTest.framework */; }; DB8FC9B525C2867800C72F26 /* OnnxruntimeModule.mm in Sources */ = {isa = PBXBuildFile; fileRef = DB8FC9B425C2867800C72F26 /* OnnxruntimeModule.mm */; }; DB8FC9B825C2868700C72F26 /* TensorHelper.mm in Sources */ = {isa = PBXBuildFile; fileRef = DB8FC9B725C2868700C72F26 /* TensorHelper.mm */; }; - DBD3F06A263F7F9C00CD0373 /* libonnxruntime.${ONNXRUNTIME_VERSION}.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DBD3F069263F7F9C00CD0373 /* libonnxruntime.${ONNXRUNTIME_VERSION}.dylib */; }; - DBD3F06B263F803D00CD0373 /* libonnxruntime.${ONNXRUNTIME_VERSION}.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DBD3F069263F7F9C00CD0373 /* libonnxruntime.${ONNXRUNTIME_VERSION}.dylib */; }; DBDB57DA2603211A004F16BE /* TensorHelperTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = DBDB57D92603211A004F16BE /* TensorHelperTest.mm */; }; DBDB57DC2603211A004F16BE /* libOnnxruntimeModule.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 134814201AA4EA6300B7C361 /* libOnnxruntimeModule.a */; }; DBDB588B2609B18F004F16BE /* Resources in Resources */ = {isa = PBXBuildFile; fileRef = DBDB588A2609B18F004F16BE /* Resources */; }; DBDB58B0262A92D7004F16BE /* OnnxruntimeModuleTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = DBDB58AF262A92D6004F16BE /* OnnxruntimeModuleTest.mm */; }; - F92876D1F6656034AD2EC8D1 /* libPods-OnnxruntimeModule.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E96BE961E158CBAAD5BA677 /* libPods-OnnxruntimeModule.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -42,29 +40,20 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01C2D06548A9114EA7E75A55 /* Pods-OnnxruntimeModuleTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OnnxruntimeModuleTest.debug.xcconfig"; path = "Target Support Files/Pods-OnnxruntimeModuleTest/Pods-OnnxruntimeModuleTest.debug.xcconfig"; sourceTree = ""; }; 134814201AA4EA6300B7C361 /* libOnnxruntimeModule.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOnnxruntimeModule.a; sourceTree = BUILT_PRODUCTS_DIR; }; - 4ED4282B152369F0F6753107 /* libPods-OnnxruntimeModuleTest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OnnxruntimeModuleTest.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4EF73D38B9D8F90FB428108C /* Pods-OnnxruntimeModuleTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OnnxruntimeModuleTest.debug.xcconfig"; path = "Target Support Files/Pods-OnnxruntimeModuleTest/Pods-OnnxruntimeModuleTest.debug.xcconfig"; sourceTree = ""; }; 4FA772A32BE6D874419D9094 /* Pods-OnnxruntimeModule.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OnnxruntimeModule.debug.xcconfig"; path = "Target Support Files/Pods-OnnxruntimeModule/Pods-OnnxruntimeModule.debug.xcconfig"; sourceTree = ""; }; - 6E96BE961E158CBAAD5BA677 /* libPods-OnnxruntimeModule.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OnnxruntimeModule.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 69B56D4AAAA9C6D8C15652DC /* Pods_OnnxruntimeModuleTest.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OnnxruntimeModuleTest.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 83B4C5FACE5CEC3A22F50945 /* Pods_OnnxruntimeModule.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OnnxruntimeModule.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 94FB38C2CBF8DFA9F2AEAB37 /* Pods-OnnxruntimeModule.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OnnxruntimeModule.release.xcconfig"; path = "Target Support Files/Pods-OnnxruntimeModule/Pods-OnnxruntimeModule.release.xcconfig"; sourceTree = ""; }; - BD5F629FF761AD0F444C93B5 /* Pods-OnnxruntimeModuleTest.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OnnxruntimeModuleTest.release.xcconfig"; path = "Target Support Files/Pods-OnnxruntimeModuleTest/Pods-OnnxruntimeModuleTest.release.xcconfig"; sourceTree = ""; }; - DB8FC9A325C2850300C72F26 /* onnxruntime_session_options_config_keys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = onnxruntime_session_options_config_keys.h; sourceTree = ""; }; - DB8FC9A425C2850300C72F26 /* automl_data_containers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = automl_data_containers.h; sourceTree = ""; }; - DB8FC9A525C2850300C72F26 /* experimental_onnxruntime_cxx_inline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = experimental_onnxruntime_cxx_inline.h; sourceTree = ""; }; - DB8FC9A625C2850300C72F26 /* environment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = environment.h; sourceTree = ""; }; - DB8FC9A725C2850300C72F26 /* onnxruntime_cxx_inline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = onnxruntime_cxx_inline.h; sourceTree = ""; }; - DB8FC9A825C2850300C72F26 /* onnxruntime_cxx_api.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = onnxruntime_cxx_api.h; sourceTree = ""; }; - DB8FC9A925C2850300C72F26 /* onnxruntime_c_api.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = onnxruntime_c_api.h; sourceTree = ""; }; - DB8FC9AA25C2850300C72F26 /* experimental_onnxruntime_cxx_api.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = experimental_onnxruntime_cxx_api.h; sourceTree = ""; }; DB8FC9B425C2867800C72F26 /* OnnxruntimeModule.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OnnxruntimeModule.mm; sourceTree = SOURCE_ROOT; }; DB8FC9B725C2868700C72F26 /* TensorHelper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TensorHelper.mm; sourceTree = SOURCE_ROOT; }; - DBD3F069263F7F9C00CD0373 /* libonnxruntime.${ONNXRUNTIME_VERSION}.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libonnxruntime.${ONNXRUNTIME_VERSION}.dylib"; path = "Libraries/onnxruntime/lib/iphonesimulator/libonnxruntime.${ONNXRUNTIME_VERSION}.dylib"; sourceTree = ""; }; DBDB57D72603211A004F16BE /* OnnxruntimeModuleTest.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OnnxruntimeModuleTest.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; DBDB57D92603211A004F16BE /* TensorHelperTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TensorHelperTest.mm; sourceTree = ""; }; DBDB57DB2603211A004F16BE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DBDB588A2609B18F004F16BE /* Resources */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Resources; path = OnnxruntimeModuleTest/Resources; sourceTree = ""; }; DBDB58AF262A92D6004F16BE /* OnnxruntimeModuleTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = OnnxruntimeModuleTest.mm; sourceTree = ""; }; + FEC2B1289C2940FC626B52E2 /* Pods-OnnxruntimeModuleTest.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OnnxruntimeModuleTest.release.xcconfig"; path = "Target Support Files/Pods-OnnxruntimeModuleTest/Pods-OnnxruntimeModuleTest.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -72,8 +61,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - F92876D1F6656034AD2EC8D1 /* libPods-OnnxruntimeModule.a in Frameworks */, - DBD3F06A263F7F9C00CD0373 /* libonnxruntime.${ONNXRUNTIME_VERSION}.dylib in Frameworks */, + 094C43D4312FB83139FA4E3B /* Pods_OnnxruntimeModule.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -81,9 +69,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - DBD3F06B263F803D00CD0373 /* libonnxruntime.${ONNXRUNTIME_VERSION}.dylib in Frameworks */, DBDB57DC2603211A004F16BE /* libOnnxruntimeModule.a in Frameworks */, - D1D81F804850BCAF0F66320B /* libPods-OnnxruntimeModuleTest.a in Frameworks */, + 9B52917A0F2BDC354D087A67 /* Pods_OnnxruntimeModuleTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -103,7 +90,6 @@ children = ( DBDB588A2609B18F004F16BE /* Resources */, DB8FC9B325C2861300C72F26 /* OnnxruntimeModule */, - DB8FC9A125C284E700C72F26 /* Libraries */, DBDB57D82603211A004F16BE /* OnnxruntimeModuleTest */, 134814211AA4EA7D00B7C361 /* Products */, DB8FC99D25C284A200C72F26 /* Frameworks */, @@ -117,8 +103,8 @@ children = ( 4FA772A32BE6D874419D9094 /* Pods-OnnxruntimeModule.debug.xcconfig */, 94FB38C2CBF8DFA9F2AEAB37 /* Pods-OnnxruntimeModule.release.xcconfig */, - 01C2D06548A9114EA7E75A55 /* Pods-OnnxruntimeModuleTest.debug.xcconfig */, - BD5F629FF761AD0F444C93B5 /* Pods-OnnxruntimeModuleTest.release.xcconfig */, + 4EF73D38B9D8F90FB428108C /* Pods-OnnxruntimeModuleTest.debug.xcconfig */, + FEC2B1289C2940FC626B52E2 /* Pods-OnnxruntimeModuleTest.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -126,36 +112,12 @@ DB8FC99D25C284A200C72F26 /* Frameworks */ = { isa = PBXGroup; children = ( - DBD3F069263F7F9C00CD0373 /* libonnxruntime.${ONNXRUNTIME_VERSION}.dylib */, - 6E96BE961E158CBAAD5BA677 /* libPods-OnnxruntimeModule.a */, - 4ED4282B152369F0F6753107 /* libPods-OnnxruntimeModuleTest.a */, + 83B4C5FACE5CEC3A22F50945 /* Pods_OnnxruntimeModule.framework */, + 69B56D4AAAA9C6D8C15652DC /* Pods_OnnxruntimeModuleTest.framework */, ); name = Frameworks; sourceTree = ""; }; - DB8FC9A125C284E700C72F26 /* Libraries */ = { - isa = PBXGroup; - children = ( - DB8FC9A225C2850300C72F26 /* onnxruntime */, - ); - path = Libraries; - sourceTree = ""; - }; - DB8FC9A225C2850300C72F26 /* onnxruntime */ = { - isa = PBXGroup; - children = ( - DB8FC9A325C2850300C72F26 /* onnxruntime_session_options_config_keys.h */, - DB8FC9A425C2850300C72F26 /* automl_data_containers.h */, - DB8FC9A525C2850300C72F26 /* experimental_onnxruntime_cxx_inline.h */, - DB8FC9A625C2850300C72F26 /* environment.h */, - DB8FC9A725C2850300C72F26 /* onnxruntime_cxx_inline.h */, - DB8FC9A825C2850300C72F26 /* onnxruntime_cxx_api.h */, - DB8FC9A925C2850300C72F26 /* onnxruntime_c_api.h */, - DB8FC9AA25C2850300C72F26 /* experimental_onnxruntime_cxx_api.h */, - ); - path = onnxruntime; - sourceTree = SOURCE_ROOT; - }; DB8FC9B325C2861300C72F26 /* OnnxruntimeModule */ = { isa = PBXGroup; children = ( @@ -200,11 +162,11 @@ isa = PBXNativeTarget; buildConfigurationList = DBDB57E12603211A004F16BE /* Build configuration list for PBXNativeTarget "OnnxruntimeModuleTest" */; buildPhases = ( - 5B732845A8C64D3A3B502FEC /* [CP] Check Pods Manifest.lock */, + 4723405DB17478264B2CEA2A /* [CP] Check Pods Manifest.lock */, DBDB57D32603211A004F16BE /* Sources */, DBDB57D42603211A004F16BE /* Frameworks */, DBDB57D52603211A004F16BE /* Resources */, - 0E58273833B892727485824E /* [CP] Copy Pods Resources */, + 08C0DD8EAE25681EA57D04AB /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -266,22 +228,64 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 0E58273833B892727485824E /* [CP] Copy Pods Resources */ = { + 08C0DD8EAE25681EA57D04AB /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-OnnxruntimeModuleTest/Pods-OnnxruntimeModuleTest-resources.sh", - "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", + "${PODS_ROOT}/Target Support Files/Pods-OnnxruntimeModuleTest/Pods-OnnxruntimeModuleTest-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/DoubleConversion/DoubleConversion.framework", + "${BUILT_PRODUCTS_DIR}/FBReactNativeSpec/FBReactNativeSpec.framework", + "${BUILT_PRODUCTS_DIR}/Folly/folly.framework", + "${BUILT_PRODUCTS_DIR}/RCTTypeSafety/RCTTypeSafety.framework", + "${BUILT_PRODUCTS_DIR}/React-Core/React.framework", + "${BUILT_PRODUCTS_DIR}/React-CoreModules/CoreModules.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTAnimation/RCTAnimation.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTBlob/RCTBlob.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTImage/RCTImage.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTLinking/RCTLinking.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTNetwork/RCTNetwork.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTSettings/RCTSettings.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTText/RCTText.framework", + "${BUILT_PRODUCTS_DIR}/React-RCTVibration/RCTVibration.framework", + "${BUILT_PRODUCTS_DIR}/React-cxxreact/cxxreact.framework", + "${BUILT_PRODUCTS_DIR}/React-jsi/jsi.framework", + "${BUILT_PRODUCTS_DIR}/React-jsiexecutor/jsireact.framework", + "${BUILT_PRODUCTS_DIR}/React-jsinspector/jsinspector.framework", + "${BUILT_PRODUCTS_DIR}/ReactCommon/ReactCommon.framework", + "${BUILT_PRODUCTS_DIR}/Yoga/yoga.framework", + "${BUILT_PRODUCTS_DIR}/glog/glog.framework", + "${PODS_ROOT}/onnxruntime-mobile-c/onnxruntime.framework", ); - name = "[CP] Copy Pods Resources"; + name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DoubleConversion.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBReactNativeSpec.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/folly.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTTypeSafety.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/React.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CoreModules.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTAnimation.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTBlob.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTImage.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTLinking.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTNetwork.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTSettings.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTText.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTVibration.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/cxxreact.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/jsi.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/jsireact.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/jsinspector.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ReactCommon.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/yoga.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/glog.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/onnxruntime.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-OnnxruntimeModuleTest/Pods-OnnxruntimeModuleTest-resources.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-OnnxruntimeModuleTest/Pods-OnnxruntimeModuleTest-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; 148DE3680F0F3FE8BA6A82D1 /* [CP] Check Pods Manifest.lock */ = { @@ -306,7 +310,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 5B732845A8C64D3A3B502FEC /* [CP] Check Pods Manifest.lock */ = { + 4723405DB17478264B2CEA2A /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -403,9 +407,9 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - "HEADER_SEARCH_PATHS[arch=*]" = "$(PROJECT_DIR)/Libraries/onnxruntime/include"; + "HEADER_SEARCH_PATHS[arch=*]" = ""; IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/Libraries/onnxruntime/lib"; + LIBRARY_SEARCH_PATHS = ""; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -448,9 +452,9 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - "HEADER_SEARCH_PATHS[arch=*]" = "$(PROJECT_DIR)/Libraries/onnxruntime/include"; + "HEADER_SEARCH_PATHS[arch=*]" = ""; IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/Libraries/onnxruntime/lib"; + LIBRARY_SEARCH_PATHS = ""; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -467,11 +471,10 @@ "$(SRCROOT)/../../../React/**", "$(SRCROOT)/../../react-native/React/**", ); + "HEADER_SEARCH_PATHS[arch=*]" = "\"$(PODS_ROOT)/onnxruntime-mobile/onnxruntime.framework/Headers\""; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)", - "$(PROJECT_DIR)/Libraries/onnxruntime/lib", - "$(PROJECT_DIR)/Libraries/onnxruntime/lib/iphonesimulator", ); OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = OnnxruntimeModule; @@ -492,11 +495,10 @@ "$(SRCROOT)/../../../React/**", "$(SRCROOT)/../../react-native/React/**", ); + "HEADER_SEARCH_PATHS[arch=*]" = "\"$(PODS_ROOT)/onnxruntime-mobile/onnxruntime.framework/Headers\""; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)", - "$(PROJECT_DIR)/Libraries/onnxruntime/lib", - "$(PROJECT_DIR)/Libraries/onnxruntime/lib/iphonesimulator", ); OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = OnnxruntimeModule; @@ -508,7 +510,7 @@ }; DBDB57DF2603211A004F16BE /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 01C2D06548A9114EA7E75A55 /* Pods-OnnxruntimeModuleTest.debug.xcconfig */; + baseConfigurationReference = 4EF73D38B9D8F90FB428108C /* Pods-OnnxruntimeModuleTest.debug.xcconfig */; buildSettings = { CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -543,7 +545,7 @@ "\"${PODS_ROOT}/Headers/Public/Yoga\"", "\"${PODS_ROOT}/Headers/Public/glog\"", "\"$(PODS_ROOT)/Headers/Private/React-Core\"", - "$(PROJECT_DIR)/Libraries/onnxruntime/include", + "\"$(PODS_ROOT)/onnxruntime-mobile/onnxruntime.framework/Headers\"", "$(PROJECT_DIR)", ); "HEADER_SEARCH_PATHS[arch=*]" = ( @@ -565,17 +567,12 @@ "\"${PODS_ROOT}/Headers/Public/Yoga\"", "\"${PODS_ROOT}/Headers/Public/glog\"", "\"$(PODS_ROOT)/Headers/Private/React-Core\"", - "$(PROJECT_DIR)/Libraries/onnxruntime/include", "$(PROJECT_DIR)", ); INFOPLIST_FILE = OnnxruntimeModuleTest/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.4; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(PROJECT_DIR)/Libraries/onnxruntime/lib $(PROJECT_DIR)/Libraries/onnxruntime/lib/iphonesimulator"; - LIBRARY_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Libraries/onnxruntime/lib", - "$(PROJECT_DIR)/Libraries/onnxruntime/lib/iphonesimulator", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = "$(inherited)"; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = ai.onnxruntime.reactnative.OnnxruntimeModuleTest; @@ -586,7 +583,7 @@ }; DBDB57E02603211A004F16BE /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BD5F629FF761AD0F444C93B5 /* Pods-OnnxruntimeModuleTest.release.xcconfig */; + baseConfigurationReference = FEC2B1289C2940FC626B52E2 /* Pods-OnnxruntimeModuleTest.release.xcconfig */; buildSettings = { CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -622,7 +619,7 @@ "\"${PODS_ROOT}/Headers/Public/Yoga\"", "\"${PODS_ROOT}/Headers/Public/glog\"", "\"$(PODS_ROOT)/Headers/Private/React-Core\"", - "$(PROJECT_DIR)/Libraries/onnxruntime/include", + "\"$(PODS_ROOT)/onnxruntime-mobile/onnxruntime.framework/Headers\"", "$(PROJECT_DIR)", ); "HEADER_SEARCH_PATHS[arch=*]" = ( @@ -644,17 +641,12 @@ "\"${PODS_ROOT}/Headers/Public/Yoga\"", "\"${PODS_ROOT}/Headers/Public/glog\"", "\"$(PODS_ROOT)/Headers/Private/React-Core\"", - "$(PROJECT_DIR)/Libraries/onnxruntime/include", "$(PROJECT_DIR)", ); INFOPLIST_FILE = OnnxruntimeModuleTest/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.4; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(PROJECT_DIR)/Libraries/onnxruntime/lib $(PROJECT_DIR)/Libraries/onnxruntime/lib/iphonesimulator"; - LIBRARY_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Libraries/onnxruntime/lib", - "$(PROJECT_DIR)/Libraries/onnxruntime/lib/iphonesimulator", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = "$(inherited)"; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = ai.onnxruntime.reactnative.OnnxruntimeModuleTest; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/js/react_native/ios/OnnxruntimeModuleTest/OnnxruntimeModuleTest.mm b/js/react_native/ios/OnnxruntimeModuleTest/OnnxruntimeModuleTest.mm index 9f313c718f..ee08e50ab6 100644 --- a/js/react_native/ios/OnnxruntimeModuleTest/OnnxruntimeModuleTest.mm +++ b/js/react_native/ios/OnnxruntimeModuleTest/OnnxruntimeModuleTest.mm @@ -3,8 +3,9 @@ #import "OnnxruntimeModule.h" #import "TensorHelper.h" -#import "onnxruntime_cxx_api.h" + #import +#import @interface OnnxruntimeModuleTest : XCTestCase @@ -14,7 +15,7 @@ - (void)testOnnxruntimeModule { NSBundle *bundle = [NSBundle bundleForClass:[OnnxruntimeModuleTest class]]; - NSString *dataPath = [bundle pathForResource:@"test_types_FLOAT" ofType:@"pb"]; + NSString *dataPath = [bundle pathForResource:@"test_types_float" ofType:@"ort"]; OnnxruntimeModule *onnxruntimeModule = [OnnxruntimeModule new]; diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_BOOL.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_BOOL.pb deleted file mode 100644 index 2c58b06d0a..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_BOOL.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_DOUBLE.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_DOUBLE.pb deleted file mode 100644 index 65ebf0f848..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_DOUBLE.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_FLOAT.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_FLOAT.pb deleted file mode 100644 index b4ad980783..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_FLOAT.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT16.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT16.pb deleted file mode 100644 index f297ec9c54..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT16.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT32.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT32.pb deleted file mode 100644 index 73bb539cf4..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT32.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT64.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT64.pb deleted file mode 100644 index ccf8df0033..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT64.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT8.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT8.pb deleted file mode 100644 index 72698a7795..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_INT8.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_STRING.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_STRING.pb deleted file mode 100644 index 7c8b3e7e2e..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_STRING.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT16.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT16.pb deleted file mode 100644 index 0a9c6fe377..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT16.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT32.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT32.pb deleted file mode 100644 index 90efef3e7f..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT32.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT64.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT64.pb deleted file mode 100644 index 53214a1a2e..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT64.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT8.pb b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT8.pb deleted file mode 100644 index 8b6a9c4219..0000000000 Binary files a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_UINT8.pb and /dev/null differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_bool.ort b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_bool.ort new file mode 100644 index 0000000000..9267bee5ab Binary files /dev/null and b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_bool.ort differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_double.ort b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_double.ort new file mode 100644 index 0000000000..9030eca3e4 Binary files /dev/null and b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_double.ort differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_float.ort b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_float.ort new file mode 100644 index 0000000000..01f489572b Binary files /dev/null and b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_float.ort differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int32.ort b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int32.ort new file mode 100644 index 0000000000..8aecad72cf Binary files /dev/null and b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int32.ort differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int64.ort b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int64.ort new file mode 100644 index 0000000000..b84dc2944b Binary files /dev/null and b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int64.ort differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int8.ort b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int8.ort new file mode 100644 index 0000000000..d762f2c5eb Binary files /dev/null and b/js/react_native/ios/OnnxruntimeModuleTest/Resources/test_types_int8.ort differ diff --git a/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm b/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm index 1ea7f8dfda..08621360c7 100644 --- a/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm +++ b/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm @@ -2,8 +2,9 @@ // Licensed under the MIT License. #import "TensorHelper.h" -#import "onnxruntime_cxx_api.h" + #import +#import @interface TensorHelperTest : XCTestCase @@ -205,104 +206,38 @@ static void testCreateOutputTensorT(const std::array &outValues, std::func std::array outValues{std::numeric_limits::min(), 1.0f, 2.0f, 3.0f, std::numeric_limits::max()}; std::function convert = [](float_t value) { return [NSNumber numberWithFloat:value]; }; - testCreateOutputTensorT(outValues, convert, JsTensorTypeFloat, @"test_types_FLOAT", @"pb"); + testCreateOutputTensorT(outValues, convert, JsTensorTypeFloat, @"test_types_float", @"ort"); } - (void)testCreateOutputTensorDouble { std::array outValues{std::numeric_limits::min(), 1.0f, 2.0f, 3.0f, std::numeric_limits::max()}; std::function convert = [](double_t value) { return [NSNumber numberWithDouble:value]; }; - testCreateOutputTensorT(outValues, convert, JsTensorTypeDouble, @"test_types_DOUBLE", @"pb"); + testCreateOutputTensorT(outValues, convert, JsTensorTypeDouble, @"test_types_double", @"ort"); } - (void)testCreateOutputTensorBool { std::array outValues{false, true, true, false, true}; std::function convert = [](bool value) { return [NSNumber numberWithBool:value]; }; - testCreateOutputTensorT(outValues, convert, JsTensorTypeBool, @"test_types_BOOL", @"pb"); + testCreateOutputTensorT(outValues, convert, JsTensorTypeBool, @"test_types_bool", @"ort"); } - (void)testCreateOutputTensorInt8 { std::array outValues{std::numeric_limits::min(), 1, -2, 3, std::numeric_limits::max()}; std::function convert = [](int8_t value) { return [NSNumber numberWithChar:value]; }; - testCreateOutputTensorT(outValues, convert, JsTensorTypeByte, @"test_types_INT8", @"pb"); -} - -- (void)testCreateOutputTensorInt16 { - std::array outValues{std::numeric_limits::min(), 1, -2, 3, std::numeric_limits::max()}; - std::function convert = [](int16_t value) { return [NSNumber numberWithShort:value]; }; - testCreateOutputTensorT(outValues, convert, JsTensorTypeShort, @"test_types_INT16", @"pb"); + testCreateOutputTensorT(outValues, convert, JsTensorTypeByte, @"test_types_int8", @"ort"); } - (void)testCreateOutputTensorInt32 { std::array outValues{std::numeric_limits::min(), 1, -2, 3, std::numeric_limits::max()}; std::function convert = [](int32_t value) { return [NSNumber numberWithInt:value]; }; - testCreateOutputTensorT(outValues, convert, JsTensorTypeInt, @"test_types_INT32", @"pb"); + testCreateOutputTensorT(outValues, convert, JsTensorTypeInt, @"test_types_int32", @"ort"); } - (void)testCreateOutputTensorInt64 { std::array outValues{std::numeric_limits::min(), 1, -2, 3, std::numeric_limits::max()}; std::function convert = [](int64_t value) { return [NSNumber numberWithLongLong:value]; }; - testCreateOutputTensorT(outValues, convert, JsTensorTypeLong, @"test_types_INT64", @"pb"); -} - -- (void)testCreateOutputTensorString { - std::array outValues{"a", "b", "c", "d", "e"}; - - NSBundle *bundle = [NSBundle bundleForClass:[TensorHelperTest class]]; - NSString *dataPath = [bundle pathForResource:@"test_types_STRING" ofType:@"pb"]; - - std::unique_ptr ortEnv{new Ort::Env(ORT_LOGGING_LEVEL_INFO, "Default")}; - Ort::SessionOptions sessionOptions; - std::unique_ptr session{new Ort::Session(*ortEnv, [dataPath UTF8String], sessionOptions)}; - - Ort::AllocatorWithDefaultOptions ortAllocator; - std::vector allocations; - - std::vector inputNames; - inputNames.reserve(session->GetInputCount()); - for (size_t i = 0; i < session->GetInputCount(); ++i) { - auto inputName = session->GetInputName(i, ortAllocator); - allocations.emplace_back(ortAllocator, inputName, strlen(inputName) + 1); - inputNames.emplace_back(inputName); - } - - std::vector outputNames; - outputNames.reserve(session->GetOutputCount()); - for (size_t i = 0; i < session->GetOutputCount(); ++i) { - auto outputName = session->GetOutputName(i, ortAllocator); - allocations.emplace_back(ortAllocator, outputName, strlen(outputName) + 1); - outputNames.emplace_back(outputName); - } - - NSMutableDictionary *inputTensorMap = [NSMutableDictionary dictionary]; - - // dims - NSArray *dims = @[ [NSNumber numberWithLong:1], [NSNumber numberWithLong:outValues.size()] ]; - inputTensorMap[@"dims"] = dims; - - // type - inputTensorMap[@"type"] = JsTensorTypeString; - - // data - NSMutableArray *data = [NSMutableArray array]; - for (auto value : outValues) { - [data addObject:[NSString stringWithUTF8String:value.c_str()]]; - } - inputTensorMap[@"data"] = data; - - Ort::Value inputTensor = [TensorHelper createInputTensor:inputTensorMap - ortAllocator:ortAllocator - allocations:allocations]; - - std::vector feeds; - feeds.emplace_back(std::move(inputTensor)); - - Ort::RunOptions runOptions; - auto output = session->Run(runOptions, inputNames.data(), feeds.data(), inputNames.size(), outputNames.data(), - outputNames.size()); - - NSDictionary *resultMap = [TensorHelper createOutputTensor:outputNames values:output]; - XCTAssertTrue([[resultMap objectForKey:@"output"] isEqualToDictionary:inputTensorMap]); + testCreateOutputTensorT(outValues, convert, JsTensorTypeLong, @"test_types_int64", @"ort"); } @end diff --git a/js/react_native/ios/Podfile b/js/react_native/ios/Podfile index 8c6bd4b7c7..9a3e9d34d5 100644 --- a/js/react_native/ios/Podfile +++ b/js/react_native/ios/Podfile @@ -1,16 +1,25 @@ require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' -platform :ios, '10.0' +platform :ios, '13.0' -target 'OnnxruntimeModule' do +def shared config = use_native_modules! use_react_native!(:path => config["reactNativePath"]) + + # Comment the next line if you don't want to use dynamic frameworks + use_frameworks! + + pod 'onnxruntime-mobile-c', :podspec => '../onnxruntime-mobile-c.podspec' + + inherit! :search_paths +end + +target 'OnnxruntimeModule' do + shared end target 'OnnxruntimeModuleTest' do - config = use_native_modules! - - use_react_native!(:path => config["reactNativePath"]) + shared end diff --git a/js/react_native/ios/TensorHelper.h b/js/react_native/ios/TensorHelper.h index 7784208680..40203c0cf9 100644 --- a/js/react_native/ios/TensorHelper.h +++ b/js/react_native/ios/TensorHelper.h @@ -5,7 +5,7 @@ #define TensorHelper_h #import -#import "onnxruntime_cxx_api.h" +#import @interface TensorHelper : NSObject diff --git a/js/react_native/onnxruntime-mobile-c.podspec b/js/react_native/onnxruntime-mobile-c.podspec new file mode 100644 index 0000000000..22754a18cb --- /dev/null +++ b/js/react_native/onnxruntime-mobile-c.podspec @@ -0,0 +1,21 @@ +require "json" + +package = JSON.parse(File.read(File.join(__dir__, "package.json"))) + +Pod::Spec.new do |spec| + spec.name = "onnxruntime-mobile-c" + spec.version = package["version"] + spec.summary = "ONNX Runtime C/C++ Package" + spec.description = <<-DESC + ONNX Runtime C/C++ framework pod. + DESC + + spec.homepage = "https://github.com/microsoft/onnxruntime" + spec.license = { :type => 'MIT' } + spec.authors = { "ONNX Runtime" => "onnxruntime@microsoft.com" } + spec.platform = :ios, '13.0' + # if you are going to use a file as the spec.source, add 'file:' before your file path + spec.source = { :http => 'file:' + __dir__ + '/local_pods/onnxruntime-mobile-c.zip' } + spec.vendored_frameworks = 'onnxruntime.framework' + spec.source_files = 'onnxruntime.framework/Headers/*.h' +end diff --git a/js/react_native/onnxruntime-react-native.iphoneos.podspec b/js/react_native/onnxruntime-react-native.iphoneos.podspec deleted file mode 100644 index ec6820db9b..0000000000 --- a/js/react_native/onnxruntime-react-native.iphoneos.podspec +++ /dev/null @@ -1,27 +0,0 @@ -require "json" - -package = JSON.parse(File.read(File.join(__dir__, "package.json"))) - -Pod::Spec.new do |s| - s.name = "onnxruntime-react-native.iphoneos" - s.version = package["version"] - s.summary = package["description"] - s.homepage = package["homepage"] - s.license = package["license"] - s.authors = package["author"] - - s.platforms = { :ios => "10.0" } - s.source = { :git => "https://github.com/Microsoft/onnxruntime.git", :tag => "#{s.version}" } - - - s.source_files = "ios/*.{h,mm}", "ios/Libraries/**/*.h" - - s.dependency "React-Core" - - s.subspec 'Onnxruntime' do |onnxruntime| - onnxruntime.preserve_paths = 'ios/Libraries/onnxruntime/include/*.h' - onnxruntime.vendored_libraries = 'ios/Libraries/onnxruntime/lib/iphoneos/libonnxruntime.1.7.0.dylib' - onnxruntime.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/Libraries/onnxruntime/include/**", 'LIBRARY_SEARCH_PATHS' => "${PODS_ROOT)/#{s.name}/Libraries/onnxruntime/lib/iphoneos/**" } - end - -end diff --git a/js/react_native/onnxruntime-react-native.iphonesimulator.podspec b/js/react_native/onnxruntime-react-native.iphonesimulator.podspec deleted file mode 100644 index d4ca5fd143..0000000000 --- a/js/react_native/onnxruntime-react-native.iphonesimulator.podspec +++ /dev/null @@ -1,27 +0,0 @@ -require "json" - -package = JSON.parse(File.read(File.join(__dir__, "package.json"))) - -Pod::Spec.new do |s| - s.name = "onnxruntime-react-native.iphonesimulator" - s.version = package["version"] - s.summary = package["description"] - s.homepage = package["homepage"] - s.license = package["license"] - s.authors = package["author"] - - s.platforms = { :ios => "10.0" } - s.source = { :git => "https://github.com/Microsoft/onnxruntime.git", :tag => "#{s.version}" } - - - s.source_files = "ios/*.{h,mm}", "ios/Libraries/**/*.h" - - s.dependency "React-Core" - - s.subspec 'Onnxruntime' do |onnxruntime| - onnxruntime.preserve_paths = 'ios/Libraries/onnxruntime/include/*.h' - onnxruntime.vendored_libraries = 'ios/Libraries/onnxruntime/lib/iphonesimulator/libonnxruntime.1.7.0.dylib' - onnxruntime.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/Libraries/onnxruntime/include/**", 'LIBRARY_SEARCH_PATHS' => "${PODS_ROOT)/#{s.name}/Libraries/onnxruntime/lib/iphonesimulator/**" } - end - -end diff --git a/js/react_native/onnxruntime-react-native.podspec b/js/react_native/onnxruntime-react-native.podspec new file mode 100644 index 0000000000..27b56dd6dc --- /dev/null +++ b/js/react_native/onnxruntime-react-native.podspec @@ -0,0 +1,20 @@ +require "json" + +package = JSON.parse(File.read(File.join(__dir__, "package.json"))) + +Pod::Spec.new do |spec| + spec.name = "onnxruntime-react-native" + spec.version = package["version"] + spec.summary = package["description"] + spec.homepage = package["homepage"] + spec.license = package["license"] + spec.authors = package["author"] + + spec.platforms = { :ios => "13.0" } + spec.source = { :git => "https://github.com/Microsoft/onnxruntime.git", :tag => "rel-#{spec.version}" } + + spec.source_files = "ios/*.{h,mm}" + + spec.dependency "React-Core" + spec.dependency "onnxruntime-mobile-c" +end diff --git a/js/react_native/package.json b/js/react_native/package.json index c98618f3c5..a1c2e9efa7 100644 --- a/js/react_native/package.json +++ b/js/react_native/package.json @@ -11,17 +11,14 @@ "lib", "dist", "android", - "ios", - "onnxruntime-react-native.iphoneos.podspec", - "onnxruntime-react-native.iphonesimulator.podspec", - "!dist/typescript/example", - "!android/build", - "!ios/build", - "!**/__tests__", - "!**/__fixtures__", - "!**/__mocks__", - "!.gitignore", - "!.placeholder" + "ios/*.h", + "ios/*.mm", + "onnxruntime-react-native.podspec", + "!dist/commonjs/*.js.map", + "!dist/module/*.js.map", + "!android/.gitignore", + "!android/.idea", + "!android/build" ], "scripts": { "test": "jest", @@ -42,7 +39,7 @@ "ONNX Runtime" ], "repository": "https://github.com/Microsoft/onnxruntime.git", - "author": "hanbitmyths", + "author": "ONNX Runtime", "license": "MIT", "bugs": { "url": "https://github.com/Microsoft/onnxruntime/issues" diff --git a/js/react_native/scripts/aar_build_settings.json b/js/react_native/scripts/aar_build_settings.json deleted file mode 100644 index 720c901188..0000000000 --- a/js/react_native/scripts/aar_build_settings.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "build_abis": [ - "armeabi-v7a", - "arm64-v8a", - "x86", - "x86_64" - ], - "android_min_sdk_version": 24, - "android_target_sdk_version": 29, - "build_params": [ - "--android", - "--parallel", - "--cmake_generator=Ninja", - "--build_java", - "--build_shared_lib", - "--disable_rtti", - "--disable_ml_ops", - "--skip_tests" - ] -} diff --git a/onnxruntime/test/shared_lib/test_inference.cc b/onnxruntime/test/shared_lib/test_inference.cc index 4f04588d93..c356d10288 100644 --- a/onnxruntime/test/shared_lib/test_inference.cc +++ b/onnxruntime/test/shared_lib/test_inference.cc @@ -162,7 +162,9 @@ static void TestInference(Ort::Env& env, const std::basic_string& mod static constexpr PATH_TYPE MODEL_URI = TSTR("testdata/mul_1.onnx"); static constexpr PATH_TYPE MATMUL_MODEL_URI = TSTR("testdata/matmul_1.onnx"); +#ifndef ORT_NO_RTTI static constexpr PATH_TYPE SEQUENCE_MODEL_URI = TSTR("testdata/sequence_length.onnx"); +#endif static constexpr PATH_TYPE CUSTOM_OP_MODEL_URI = TSTR("testdata/foo_1.onnx"); static constexpr PATH_TYPE CUSTOM_OP_LIBRARY_TEST_MODEL_URI = TSTR("testdata/custom_op_library/custom_op_test.onnx"); static constexpr PATH_TYPE OVERRIDABLE_INITIALIZER_MODEL_URI = TSTR("testdata/overridable_initializer.onnx"); @@ -1494,4 +1496,4 @@ TEST(CApiTest, ConfigureCudaArenaAndDemonstrateMemoryArenaShrinkage) { // (Memory arena for the CPU should not have been disabled) // run_option.AddConfigEntry(kOrtRunOptionsConfigEnableMemoryArenaShrinkage, "cpu:0;gpu:0"); } -#endif \ No newline at end of file +#endif