1

我正在尝试使用 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)

有任何想法吗?我看到上周提出了类似的问题,但没有回应。所有帮助和建议表示赞赏。非常感谢。

4

1 回答 1

0

全新安装时我有同样的错误。我发生了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,我能够摆脱错误。

希望我的经验有帮助!干杯

于 2020-08-21T09:04:28.357 回答