tfjs-node - 无法为 Tensorflow 加载 Node 后端(TypeError:无法读取未定义的属性“nonMaxSuppressionV3Impl”)
问题描述
我正在尝试使用 face-api.js 面部识别功能,如果安装了 Node 后端,它会运行得更快。我已经使用 npm 安装了后端,如下所示:
$ node -v
v14.1.0
$ npm list @tensorflow/tfjs-node
appname@0.1.0 /Users/akoi/Dev/bwr
└── @tensorflow/tfjs-node@2.3.0
$ npm list @tensorflow/tfjs
appname@0.1.0 /Users/akoi/Dev/bwr
├── @tensorflow/tfjs@2.3.0
├─┬ @tensorflow/tfjs-node@2.3.0
│ └── @tensorflow/tfjs@2.3.0 deduped
└─┬ @tensorflow/tfjs-node-gpu@2.3.0
└── @tensorflow/tfjs@2.3.0 deduped
face-api.js 函数都可以正常工作,只是因为后端没有加载而很慢。
当我尝试根据说明加载后端时,使用:
require('@tensorflow/tfjs-node');
这是我在运行时遇到的错误:
TypeError: Cannot read property 'nonMaxSuppressionV3Impl' of undefined
at Object.<anonymous> (/Users/akoi/Dev/bwr/node_modules/@tensorflow/tfjs-backend-cpu/dist/tf-backend-cpu.node.js:268:47)
at Module._compile (internal/modules/cjs/loader.js:1176:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
at Module.load (internal/modules/cjs/loader.js:1040:32)
at Function.Module._load (internal/modules/cjs/loader.js:929:14)
at Module.require (internal/modules/cjs/loader.js:1080:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/akoi/Dev/bwr/node_modules/@tensorflow/tfjs/dist/tf.node.js:25:22)
at Module._compile (internal/modules/cjs/loader.js:1176:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
有任何想法吗?我看到上周提出了类似的问题,但没有回应。所有帮助和建议表示赞赏。非常感谢。
解决方案
全新安装时我有同样的错误。我发生了2个问题。
首先,Native Modules 安装失败。我注意到我的安装@tensorflow/tfjs-node
没有成功安装,即使 NPM 返回 0 退出代码。
node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build
由于我在安装时使用的是 MacOS,所以我最终不得不重新安装我的 XCode 工具以修复本机模块绑定。
sudo rm -rf $(xcode-select -print-path)
xcode-select --install
其次,对等依赖项没有与@tensorflow/tfjs-node
.
npm WARN @tensorflow/tfjs-backend-cpu@2.3.0 requires a peer of @tensorflow/tfjs-core@2.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @tensorflow/tfjs-backend-webgl@2.3.0 requires a peer of @tensorflow/tfjs-core@2.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @tensorflow/tfjs-layers@2.3.0 requires a peer of @tensorflow/tfjs-core@2.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @tensorflow/tfjs-data@2.3.0 requires a peer of @tensorflow/tfjs-core@2.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @tensorflow/tfjs-converter@2.3.0 requires a peer of @tensorflow/tfjs-core@2.3.0 but none is installed. You must install peer dependencies yourself.
安装对等依赖项后@tensorflow/tfjs-core@2.3.0
,我能够摆脱错误。
希望我的经验有帮助!干杯
推荐阅读
- r - RShiny:使用数据框列表中的值自动填充 selectInput?
- python - 如何在特定单词之前计算否定词或肯定词 - Python 中的情绪分析?
- sql - 从 Line 中提取 n 个坐标 - Bigquery
- reporting-services - SSRS 报告运行缓慢
- pandas - 如果熊猫中的NaN,如何将1添加到以前的数据
- reactjs - 模块解析失败:意外的令牌,您可能需要适当的加载器来处理此文件类型
- javascript - 如何在 JavaScript 中订阅两个 eventDispatcher
- blueprism - 如何删除集合中的空列
- html - 编辑 Shopify 的结帐
- php - 在 Woocommerce 订单总计表上显示自定义交付选项