是否可以将 tenserflow.js 与 react native 一起使用? [英] Is it possible to use tenserflow.js with react native?

查看:60
本文介绍了是否可以将 tenserflow.js 与 react native 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我在 React Native 上构建的基于 AI 的应用程序添加离线支持,该应用程序类似于

谢谢!!!

解决方案

简短的回答 没有,如在项目描述中.

<块引用>

WebGL 加速,基于浏览器的 JavaScript 库

您收到的错误表明它正在尝试使用 window,它是浏览器中 DOM API 的一部分.React Native 没有这样的 API,因为它不是浏览器.你可以看到他们在核心 API.

长答案可能,但超出了 StackOverflow 答案的范围,因为它类似于要求提供教程.详细地说,我可以看到两种可能使 TensorFlow.js 工作的方法:

  1. Polyfill 缺少的所有内容:
    • 这可能是可能的,但它可能不会像您期望的那样工作,因为它利用了 WebGL.我不熟悉 TensorFlow.js,但我相信使用 WebGL 是因为它允许访问 GPU 加速,从而使工作负载在浏览器中可行.您需要做一些类似的事情才能使其良好在移动设备上运行.
  2. 利用 WebView.但是,您可能会再次遇到 WebGL/性能问题如旧问题所示比如这个.

由于您没有发布任何代码,因此我无法为您提供有关此问题的其他指导.一个建议是查看可能的原生模块,例如 react-native-tensorflow 和人们围绕它进行的讨论.

I am trying to add offline support to an AI-based app I am building on React Native, The app is similar to Not Hotdog of Silicon Valley. I recently found out Tenserflow.js and tried to implement it with React native and even outputted my python model to the one that is supported by Tenserflow.js but when I try to import Tenserflow.js inside one of the React Native components using import * as tf from '@tensorflow/tfjs'; this syntax but React Native throws the error, the error screenshot is attached with the question.

Thank You !!!

解决方案

The short answer is no as stated in the description of the project.

A WebGL accelerated, browser based JavaScript library

The error you are getting shows that it's trying to use window which is part of the DOM API in browsers. React Native has no such API as it's not a browser. You can see that they use window in multiple places in their Core API.

The long answer is a maybe but is out of scope for a StackOverflow answer as it would be akin to asking for a tutorial. To elaborate, I can see two approaches to possibly getting TensorFlow.js to work:

  1. Polyfill everything that is missing:
    • This might be possible but it probably won't work as you'd expect because it leverages WebGL. I'm not familiar with TensorFlow.js, but I would believe that WebGL is used because it would allow access to GPU acceleration making the workload feasible in the browser. You would need to do something similar in order for it to work well on a mobile device.
  2. Leverage a WebView. However, you may again run into WebGL/performance issues as indicated in older questions such as this.

Since you didn't post any code whatsoever, there is no other guidance that I can give you on this question. One suggestion would be to look at maybe a native module such as react-native-tensorflow and the discussions people had around it.

这篇关于是否可以将 tenserflow.js 与 react native 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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