【发布时间】:2018-07-13 19:46:13
【问题描述】:
我对javascript相当陌生。我正在通过tensorflow-js tutorial 使用 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'
我不确定是什么导致了这个错误。
【问题讨论】:
标签: javascript node.js tensorflow.js