-
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.md
file 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.js
under<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
ort
to 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
.ort
extension). 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-native
as 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.helloworld
as package name and bundle identifier. - The package name (Android) and bundle ID (iOS) will be added in your
<SOURCE_ROOT>/app.json
automatically by expo.
- Expo will ask the Android package name and iOS bundle identifier. In this tutorial we use
-
Add
onnxruntime-react-native
to gradle depencencies.In
<SOURCE_ROOT>/android/app/build.gradle
, add the following line to sectiondependencies
:implementation project(':onnxruntime-react-native')
-
Add
onnxruntime-react-native
to 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>/ios
to install:pod install
-
-
-
Add code in
App.tsx
to 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 5
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