Package Exports
- react-native-tensorflow
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-tensorflow) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-native-tensorflow
A TensorFlow inference library for react native. It follows the android inference api from TensorFlow: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/android
This library is currently only supporting android
Getting started
$ npm install react-native-tensorflow --save
Mostly automatic installation
$ react-native link react-native-tensorflow
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-tensorflow
and addRNTensorflow.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNTensorflow.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.rntensorflow.RNTensorFlowPackage;
to the imports at the top of the file - Add
new RNTensorFlowPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-tensorflow' project(':react-native-tensorflow').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-tensorflow/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-tensorflow')
Usage
First you need to put a model in the android/src/main/assets folder. Then you can create an instance providing the file name of the model. Next you will need to feed an image in the form of a number array. Then run the inference and lastly fetch the result.
import TensorFlowInference from 'react-native-tensorflow';
const tensorflowInference = new TensorFlowInference('tensorflow_inception_graph.pb')
tensorflowInference.feed('inputName', [1,2,3,4,...])
tensorflowInference.run('outputNames')
tensorflowInference.fetch('outputName', 10).then(output => console.log(output))
Check the android TensorFlow example for more information on the API: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/TensorFlowImageClassifier.java