Skip to content

Instantly share code, notes, and snippets.

@HungMingWu
Created April 30, 2018 07:01
Show Gist options
  • Save HungMingWu/2ec7b7e06272cd3077257a07aa5ce382 to your computer and use it in GitHub Desktop.
Save HungMingWu/2ec7b7e06272cd3077257a07aa5ce382 to your computer and use it in GitHub Desktop.
Minimal Tensorflow-JS Example
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script>
<script>
const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [1] }));
model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' });
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
model.fit(xs, ys).then(() => {
model.predict(tf.tensor2d([5], [1, 1])).print();
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment