是否可以将 tenserflow.js 与 react native 一起使用?

编程入门 行业动态 更新时间:2024-10-28 06:36:25
本文介绍了是否可以将 tenserflow.js 与 react native 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

谢谢!!!

解决方案

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

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

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

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

  • Polyfill 缺少的所有内容:
    • 这可能是可能的,但它可能不会像您期望的那样工作,因为它利用了 WebGL.我不熟悉 TensorFlow.js,但我相信使用 WebGL 是因为它允许访问 GPU 加速,从而使工作负载在浏览器中可行.您需要做一些类似的事情才能使其良好在移动设备上运行.
  • 利用 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:

  • 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.
  • 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 一起使用?

    本文发布于:2023-11-24 19:28:13,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1626514.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:js   tenserflow   native   react

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!