piccolo
piccolo

Reputation: 2217

Error when loading tensorflow.js with node.js

I am fairly new to javascript. I am working through the tensorflow-js tutorial on using tensorflow-js with node.js however when I run the example code:

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}`);
    }
  }
});

I have already installed the tensorflowjs package: npm install @tensorflow/tfjs-node-gpu

However I get the error:

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

I am not sure what is causing this error.

Upvotes: 2

Views: 2342

Answers (1)

Geuis
Geuis

Reputation: 42267

You need to:

npm install @tensorflow/tfjs-node

Upvotes: 7

Related Questions