tháng 6 07, 2018 —
                                          
Posted by Laurence Moroney
With TensorFlow.js, you can not only run machine-learned models in the browser to perform inference, you can also train them. In this super-simple tutorial, I’ll show you a basic ‘Hello World’ example that will teach you the scaffolding to get you up and running.
Let’s start with the simplest Web Page imaginable:
<html>
<head></head>
<body></bo…

<html>
<head></head>
<body></body>
</html><html>
<head>
 <!-- Load TensorFlow.js -->
 <!-- Get latest version at https://github.com/tensorflow/tfjs -->
 <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.2"> </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, 0, 1, 2, 3, 4], [6, 1]);
const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]);await model.fit(xs, ys, {epochs: 500});document.getElementById('output_field').innerText =
   model.predict(tf.tensor2d([10], [1, 1]));
<html>
 <head>
 <!-- Load TensorFlow.js -->
 <!-- Get latest version at https://github.com/tensorflow/tfjs -->
 <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.2">   
 </script>
 </head>
 <body>
   <div id="output_field"></div>
 </body>
 <script>
 async function learnLinear(){
  const model = tf.sequential();
  model.add(tf.layers.dense({units: 1, inputShape: [1]}));
  model.compile({
   loss: 'meanSquaredError',
   optimizer: 'sgd'
  });
  
  const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]);
  const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]);
  
  await model.fit(xs, ys, {epochs: 500});
  
  document.getElementById('output_field').innerText =
   model.predict(tf.tensor2d([10], [1, 1]));
 }
 learnLinear();
 </script>
<html> 
tháng 6 07, 2018
 —
                                  
Posted by Laurence Moroney
With TensorFlow.js, you can not only run machine-learned models in the browser to perform inference, you can also train them. In this super-simple tutorial, I’ll show you a basic ‘Hello World’ example that will teach you the scaffolding to get you up and running.
Let’s start with the simplest Web Page imaginable:
<html>
<head></head>
<body></bo…