6

I am aware tensor-flow.js is a web focused lib, but out of curiosity i tried it on react-native as well, it sort of works. It only works on debug-mode, and throws an error when debug-mood is turn off, the error says window.location.search is not an object. after some research i found that the window object is created in debug mode, but when out of debug mode it do not exist.

my understanding of this if somehow we can work around it, tfjs can also work on react-native, kind of like d3, the math part of the library works well with react but not the dom/svg manipulation part. for tfjs all we need is the math part for it to run on our mobile device, correct me if i am wrong.

https://github.com/tangtai/tensorflowJs-rn here is the repo of the project i created, it predicts a linear model and predict with with hardcoded value.

img of the application runs

img of error

I think there will be lots of possibilities if tfjs can run on react-native

tai C
  • 131
  • 1
  • 8

2 Answers2

3

The tensorflow-js team released an offical package for react-native

https://www.npmjs.com/package/@tensorflow/tfjs-react-native

if you want to run tensorflow on rn you should check it out.

tai C
  • 131
  • 1
  • 8
  • The TensorFlow.js React Native package now moved out of alpha and is generally available. Installation is tricky due to many dependencies, but you can generate a new React Native project with TensorFlow.js support using this template: [react-native-template-tfjs](https://github.com/Polarisation/react-native-template-tfjs) – Justin Emery Feb 28 '20 at 00:46
0

Is it possible to use tenserflow.js with react native?

The link above might be the answer for you.

I'm still curious on this subject anyway, because I also think this is possible technically.

Sangwon Choi
  • 218
  • 2
  • 11
  • 1
    i have post the question on git-hub and got replied by the tf-js team and they got back to me, so you have to make some changes to the environment file to make it work. they made changes to tf-js core, but the buddled tfjs is not updated yet, follow this page for the solution: https://github.com/tensorflow/tfjs/issues/192#event-1597317802 – tai C May 03 '18 at 18:16
  • So i have try run tf-js on react native it works now for define and train and run your model locally, but I'm having issues to load pretrained model from local or remote url. – tai C May 04 '18 at 21:54
  • I have not tested yet, but there is converter. https://github.com/tensorflow/tfjs-converter – Sangwon Choi May 08 '18 at 02:04