Skip to content

Commit 4b7cb3f

Browse files
tensorflow
1 parent bf9e69a commit 4b7cb3f

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<html>
22

33
<head>
4+
<!-- 使用Script Tag -->
5+
46
<!-- Load TensorFlow.js -->
57
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]">
68
</script>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* $ yarn add @tensorflow/tfjs
3+
* $ npm install @tensorflow/tfjs
4+
*/
5+
6+
import * as tf from '@tensorflow/tfjs';
7+
8+
// Define a model for linear regression. 定义模型:线性回归模型
9+
const model = tf.sequential();
10+
model.add(tf.layers.dense({ units: 1, inputShape: [1] }));
11+
12+
// Prepare the model for training: Specify the loss and the optimizer. 定义模型损失函数和梯度下降算法
13+
model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' });
14+
15+
// Generate some synthetic data for training. 准备学习数据
16+
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
17+
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
18+
19+
// Train the model using the data. 模型学习
20+
model.fit(xs, ys).then(() => {
21+
// Use the model to do inference on a data point the model hasn't seen before: 使用训练完成的模型进行预测
22+
model.predict(tf.tensor2d([5], [1, 1])).print();
23+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"@tensorflow/tfjs": "^0.10.3"
4+
}
5+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@tensorflow/[email protected]":
6+
version "0.8.4"
7+
resolved "http://registry.npm.taobao.org/@tensorflow/tfjs-core/download/@tensorflow/tfjs-core-0.8.4.tgz#20c5bf017cb57486ca77cc01a92d6df85c2e38ff"
8+
dependencies:
9+
seedrandom "~2.4.3"
10+
11+
"@tensorflow/[email protected]":
12+
version "0.5.3"
13+
resolved "http://registry.npm.taobao.org/@tensorflow/tfjs-layers/download/@tensorflow/tfjs-layers-0.5.3.tgz#0b45624ba8bcbd8e904f68344f16cf6358c695af"
14+
15+
"@tensorflow/tfjs@^0.10.3":
16+
version "0.10.3"
17+
resolved "http://registry.npm.taobao.org/@tensorflow/tfjs/download/@tensorflow/tfjs-0.10.3.tgz#29d44e57d53492532829c768958151fb8893b2ab"
18+
dependencies:
19+
"@tensorflow/tfjs-core" "0.8.4"
20+
"@tensorflow/tfjs-layers" "0.5.3"
21+
22+
seedrandom@~2.4.3:
23+
version "2.4.3"
24+
resolved "http://registry.npm.taobao.org/seedrandom/download/seedrandom-2.4.3.tgz#2438504dad33917314bff18ac4d794f16d6aaecc"

17-tensorflow.js/[email protected]

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)