-
Prepare environment
- install Node.js
- install expo
npm install -g expo-cli
- install yarn
npm install -g yarn
-
Setup empty project
cd <SOURCE_ROOT> expo init . -t expo-template-blank-typescript yarn
NOTE:
<SOURCE_ROOT>refers to the root folder of the source code, which is where thisREADME.mdfile sits.
-
Install onnxruntime-react-native
expo install onnxruntime-react-native@dev
-
Add your ONNX model to project
-
Put the file under
<SOURCE_ROOT>/assets.In this tutorial, we use the ORT format ONNX model of MNIST (
mnist.ort). -
add a new file
metro.config.jsunder<SOURCE_ROOT>and add the following lines to the file:const { getDefaultConfig } = require('@expo/metro-config'); const defaultConfig = getDefaultConfig(__dirname); defaultConfig.resolver.assetExts.push('ort'); module.exports = defaultConfig;
This step adds extension
ortto the bundler's asset extension list, which allows the bundler to include the model into assets.
NOTE:
- There are multiple ways to load model using ONNX Runtime for React Native. In this tutorial, model is built into the app as an asset. See also [other tutorial][TBD]
- It's required to use a ORT format model (ie. a model file with
.ortextension). See also [links to ORT format model][TBD]
-
-
Setup Android and iOS project.
In this step, we setup the generated Android/iOS project to consume ONNX Runtime. There are 2 ways to setup the project:
-
(recommended) using NPM package
onnxruntime-react-nativeas an expo plugin.- In
<SOURCE_ROOT>/app.json, add the following line to sectionexpo:"plugins": ["onnxruntime-react-native"], - Run the following command in
<SOURCE_ROOT>to generate Android and iOS project:expo prebuild
The generated project files will be updated automatically.
- In
-
setup manually.
-
Run the following command in
<SOURCE_ROOT>to generate Android and iOS project:expo prebuild
NOTE:
- Expo will ask the Android package name and iOS bundle identifier. In this tutorial we use
com.example.helloworldas package name and bundle identifier. - The package name (Android) and bundle ID (iOS) will be added in your
<SOURCE_ROOT>/app.jsonautomatically by expo.
- Expo will ask the Android package name and iOS bundle identifier. In this tutorial we use
-
Add
onnxruntime-react-nativeto gradle depencencies.In
<SOURCE_ROOT>/android/app/build.gradle, add the following line to sectiondependencies:implementation project(':onnxruntime-react-native') -
Add
onnxruntime-react-nativeto CocoaPods dependencies.In
<SOURCE_ROOT>/ios/Podfile, add the following line to sectiontarget 'OrtReactNativeHelloWorld':pod 'onnxruntime-react-native', :path => '../node_modules/onnxruntime-react-native'Run the following command in
<SOURCE_ROOT>/iosto install:pod install
-
-
-
Add code in
App.tsxto use onnxruntime-react-native.Please refer to the file content for details.
-
Run the following command to launch:
In
<SOURCE_ROOT>, run the following command to launch for Androidexpo run:android
In
<SOURCE_ROOT>, run the following command to launch for iOSexpo run:ios
-
Notifications
You must be signed in to change notification settings - Fork 7
fs-eire/ort-rn-hello-world
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published