Bogdan BivB
Denoβ€’3y agoβ€’
2 replies
Bogdan Biv

How to use recent Tensorflow.JS? TF from deno.land/x/tensorflow@v0.21 appears to work, but it's old

I've only tried the TF package from deno.land/x/tensorflow@v0.21 with the readme page example. I'm hoping there are better options - read it as more recent and maintained ports of TF.

Here's the output of my trial of using jsdelivr version in Deno:
> import * as tf from "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js"
undefined
> const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));

model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});

// Generate some synthetic data for training.
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);

// Train the model using the data.
model.fit(xs, ys, {epochs: 10}).then(() => {
    // Use the model to do inference on a data point the model hasn't seen before:
    model.predict(tf.tensor2d([5], [1, 1])).print();
    // Open the browser devtools to see the output
});
/*
Uncaught TypeError: Cannot read properties of undefined (reading 'isTypedArray')
    at isTypedArray (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:3075:23)
    at scalar (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:12493:11)
    at SGDOptimizer.setLearningRate (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:25134:23)
    at new SGDOptimizer (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:25105:14)
    at Function.sgd (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:27624:16)
    at Object.SGD (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:41336:28)
    at getOptimizer (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:41345:40)
    at LayersModel.compile (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:44020:31)
    at Sequential.compile (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.13.0/dist/tf.fesm.js:46129:20)
    at <anonymous>:8:7
*/


Would there be other options?
Was this page helpful?