使用 node.js 加载 tensorflow.js 时出错
2018-07-13
2240
我对 javascript 还很陌生。我正在按照 tensorflow-js 教程 操作,了解如何将 tensorflow-js 与 node.js 结合使用,但是当我运行示例代码时:
const tf = require('@tensorflow/tfjs');
// Load the binding:
require('@tensorflow/tfjs-node'); // Use '@tensorflow/tfjs-node-gpu' if running with GPU.
// Train a simple model:
const model = tf.sequential();
model.add(tf.layers.dense({units: 100, activation: 'relu', inputShape: [10]}));
model.add(tf.layers.dense({units: 1, activation: 'linear'}));
model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});
const xs = tf.randomNormal([100, 10]);
const ys = tf.randomNormal([100, 1]);
model.fit(xs, ys, {
epochs: 100,
callbacks: {
onEpochEnd: async (epoch, log) => {
console.log(`Epoch ${epoch}: loss = ${log.loss}`);
}
}
});
我已经安装了 tensorflowjs 包: npm install @tensorflow/tfjs-node-gpu
但是我收到错误:
module.js:549
throw err;
Error: Cannot find module '@tensorflow/tfjs-node'
我不确定是什么导致了此错误。
1个回答
您需要:
npm install @tensorflow/tfjs-node
Geuis
2018-07-13