Skip to content

Instantly share code, notes, and snippets.

@NeuroWhAI
Created April 1, 2018 04:07
Show Gist options
  • Save NeuroWhAI/d87fd9cfc863eccec7ffa4e22c3de1c0 to your computer and use it in GitHub Desktop.
Save NeuroWhAI/d87fd9cfc863eccec7ffa4e22c3de1c0 to your computer and use it in GitHub Desktop.
TensorFlow.js test
<!doctype html>
<html>
<head>
<title>TF.js Test</title>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.6.1"></script>
<script type="text/javascript">
// 선형회귀 모델 생성
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