带有 react-native 的 Tensorflow.js [英] Tensorflow.js with react-native

查看:90
本文介绍了带有 react-native 的 Tensorflow.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 tensor-flow.js 是一个专注于网络的库,但出于好奇我也在 react-native 上尝试了它,它有点工作.它仅适用于调试模式,并在调试情绪关闭时抛出错误,错误表示 window.location.search 不是对象.经过一番研究,我发现 window 对象是在调试模式下创建的,但是当退出调试模式时它不存在.

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.

我对此的理解是,如果我们能以某种方式解决它,tfjs 也可以在 react-native 上工作,有点像 d3,库的数学部分适用于 react,但不适用于 dom/svg 操作部分.对于 tfjs,我们需要的只是让它在我们的移动设备上运行的数学部分,如果我错了,请纠正我.

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这是我创建的项目的 repo,它预测线性模型并使用硬编码值进行预测.

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

错误图片

我认为如果 tfjs 可以在 react-native 上运行,将会有很多可能性

推荐答案

tensorflow-js 团队发布 react-native 官方包

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

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

如果你想在 rn 上运行 tensorflow,你应该检查一下.

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

这篇关于带有 react-native 的 Tensorflow.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆