gpt4 book ai didi

javascript - 使用 node.js 加载 tensorflow.js 时出错

转载 作者:搜寻专家 更新时间:2023-11-01 00:16:12 26 4
gpt4 key购买 nike

我是 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 安装@tensorflow/tfjs-node-gpu

但是我得到了错误:

module.js:549
throw err;
Error: Cannot find module '@tensorflow/tfjs-node'

我不确定是什么导致了这个错误。

最佳答案

你需要:

npm install @tensorflow/tfjs-node

关于javascript - 使用 node.js 加载 tensorflow.js 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51331927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com