首页 > 解决方案 > Tensorflow js:您的应用程序包含足够小的操作,可以在 CPU 后端执行,但是找不到 CPU 后端

问题描述

我在使用带有 webgl 后端的 tfjs 的浏览器中使用 handpose tensorflow 模型进行手部检测。但是,我在控制台中看到警告 Your application contains ops that are small enough to be executed on the CPU backend, however the CPU backend cannot be found. Consider importing the CPU backend (@tensorflow/tfjs-backend-cpu) for better performance.

如果我尝试将它添加到我的项目中,我会看到很多关于该 CPU 后端已注册的警告。

有没有办法在 tfjs 中同时使用 CPU 和 GPU(webgl)?

标签: javascripttensorflowtensorflow.js

解决方案


默认情况下,Tensorflow JS 在 CPU 上进行一些推理(前向传播而不是反向传播),因为一些 CPU 具有加速矩阵乘法的向量算术单元。

您可以检查tf.ENV.flags变量以查看 tfjs 默认设置的各种状态变量。其中之一是WEBGL_CPU_FORWARD标志,您可以在控制台或 javascript 函数中将其设置为 true。

tf.ENV.set("WEBGL_CPU_FORWARD", true)

script这应该会激活 CPU 后端,而无需在标签中再次导入它。或者,您可以忽略警告,因为它们根本不会影响您的程序。


推荐阅读