javascript - 错误 : The Node. 无法在路径中找到 js native 插件模块 (tfjs_binding.node)

标签 javascript node.js tensorflow npm

我尝试运行 this 的示例应用:

enter image description here

通过这个脚本:

const tf = require('@tensorflow/tfjs-node');
const posenet = require('@tensorflow-models/posenet');
const {
    createCanvas, Image
} = require('canvas')
const imageScaleFactor = 0.5;
const outputStride = 16;
const flipHorizontal = false;

const tryModel = async() => {
    console.log('start');
    const net = await posenet.load(0.75);
    const img = new Image();
    img.src = './test.jpg';
    const canvas = createCanvas(img.width, img.height);
    const ctx = canvas.getContext('2d');
    ctx.drawImage(img, 0, 0);
    const input = tf.browser.fromPixels(canvas);
    const pose = await net.estimateSinglePose(input, imageScaleFactor, flipHorizontal, outputStride);
    // console.log(pose);
    for(const keypoint of pose.keypoints) {
        console.log(`${keypoint.part}: (${keypoint.position.x},${keypoint.position.y})`);
    }
    console.log('end');
}



tryModel();

但是当我尝试时:

Node 索引.js

我收到这个错误:

so@so-notebook:~/Desktop/trash/tensorflow$ node index.js
Overriding the gradient for 'Max'
Overriding the gradient for 'OneHot'
Overriding the gradient for 'PadV2'
Overriding the gradient for 'SpaceToBatchND'
Overriding the gradient for 'SplitV'
/home/so/node_modules/@tensorflow/tfjs-node/dist/index.js:49
    throw new Error("The Node.js native addon module (tfjs_binding.node) can not "
    ^

Error: The Node.js native addon module (tfjs_binding.node) can not be found at path: /home/so/node_modules/@tensorflow/tfjs-node/lib/napi-v6/tfjs_binding.node. 
Please run command 'npm rebuild @tensorflow/tfjs-node build-addon-from-source' to rebuild the native addon module. 
If you have problem with building the addon module, please check https://github.com/tensorflow/tfjs/blob/master/tfjs-node/WINDOWS_TROUBLESHOOTING.md or file an issue.
    at Object.<anonymous> (/home/so/node_modules/@tensorflow/tfjs-node/dist/index.js:49:11)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/so/Desktop/trash/tensorflow/index.js:1:12)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)

根据它的建议,我尝试这样做:

sudo npm rebuild @tensorflow/tfjs-node build-addon-from-source

但是得到这个错误:

so@so-notebook:~/Desktop/trash/tensorflow$ sudo npm rebuild @tensorflow/tfjs-node build-addon-from-source

> @tensorflow/tfjs-node@2.0.1 install /home/so/node_modules/@tensorflow/tfjs-node
> node scripts/install.js

CPU-linux-2.0.1.tar.gz
* Downloading libtensorflow
[==============================] 64333/bps 100% 0.0s
* Building TensorFlow Node.js bindings
node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp WARN Tried to download(403): https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v6/2.0.1/CPU-linux-2.0.1.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@2.0.1 and node@14.4.0 (node-v83 ABI, glibc) (falling back to source compile with node-gyp) 
In file included from ../binding/tfjs_backend.cc:18:0:
../binding/tfjs_backend.h:25:10: fatal error: tensorflow/c/c_api.h: No such file or directory
 #include "tensorflow/c/c_api.h"
          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Release/obj.target/tfjs_binding/binding/tfjs_backend.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Linux 5.6.9-050609-generic
gyp ERR! command "/home/so/node_modules/node/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/home/so/node_modules/@tensorflow/tfjs-node/lib/napi-v6/tfjs_binding.node" "--module_name=tfjs_binding" "--module_path=/home/so/node_modules/@tensorflow/tfjs-node/lib/napi-v6" "--napi_version=6" "--node_abi_napi=napi" "--napi_build_version=6" "--node_napi_label=napi-v6"
gyp ERR! cwd /home/so/node_modules/@tensorflow/tfjs-node
gyp ERR! node -v v14.4.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/home/so/node_modules/node/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/so/node_modules/@tensorflow/tfjs-node/lib/napi-v6/tfjs_binding.node --module_name=tfjs_binding --module_path=/home/so/node_modules/@tensorflow/tfjs-node/lib/napi-v6 --napi_version=6 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/so/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1051:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
node-pre-gyp ERR! System Linux 5.6.9-050609-generic
node-pre-gyp ERR! command "/home/so/node_modules/node/bin/node" "/home/so/node_modules/@tensorflow/tfjs-node/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/so/node_modules/@tensorflow/tfjs-node
node-pre-gyp ERR! node -v v14.4.0
node-pre-gyp ERR! node-pre-gyp -v v0.14.0
node-pre-gyp ERR! not ok 

@tensorflow/tfjs-node@2.0.1 /home/so/node_modules/@tensorflow/tfjs-node

纽约操作系统是:

so@so-notebook:~/Desktop/trash/tensorflow$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

谢谢。

最佳答案

在 Ubuntu 20.04 上我解决了这个问题:

  1. sudo apt install build-essential
  2. sudo npm i -g node-pre-gyp
  3. npm rebuild @tensorflow/tfjs-node build-addon-from-source

关于javascript - 错误 : The Node. 无法在路径中找到 js native 插件模块 (tfjs_binding.node),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62442449/

相关文章:

node.js - 在 Node.js 中,如何将 bluebird Promise 与 for 循环一起使用

node.js - 接收: 'Auth error:Error: read ECONNRESET' when connecting to google cloud platform behind a proxy

JavaScript slider 无法正常工作

javascript - 在javascript中对混合字母/数字数组进行排序

javascript - 如何在 If 内的 php 中提交

javascript - Node.Js API 等待 dynamodb 调用完成以发送到浏览器

Java 相当于 JavaScript 的 Canvas getImageData

neural-network - 在深度神经网络中使用卷积 1x1 的原因是什么?

python - Tensorflow——迁移学习实现(语义分割)

machine-learning - Keras——没有带有广播的 Dot 层?