Skip to content

Commit 678087d

Browse files
tensorflow
1 parent 3b0e603 commit 678087d

File tree

19 files changed

+276
-97
lines changed

19 files changed

+276
-97
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.0/dist/tf.min.js"></script>
2+
<script>
3+
const a = tf.tensor([1, 2]);
4+
a.print();
5+
</script>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="script.js"></script>

20-tensorflow.js/01-setup/node.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const tf = require('@tensorflow/tfjs-node');
2+
3+
const a = tf.tensor([1, 2]);
4+
a.print();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as tf from '@tensorflow/tfjs';
2+
3+
const a = tf.tensor([1, 2]);
4+
a.print();

20-tensorflow.js/01-通过标签.html

Lines changed: 0 additions & 44 deletions
This file was deleted.

20-tensorflow.js/02-npm&yarn/demo.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

20-tensorflow.js/02-npm&yarn/package.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

20-tensorflow.js/02-npm&yarn/yarn.lock

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="script.js"></script>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* @Author: victorsun
3+
* @Date: 2019-12-04 20:15:29
4+
* @LastEditors: victorsun - csxiaoyao
5+
* @LastEditTime: 2020-03-21 08:51:39
6+
* @Description: sunjianfeng@csxiaoyao.com
7+
*/
8+
import * as tf from '@tensorflow/tfjs';
9+
10+
// tensor 张量
11+
// 存储神经元,使用 tensor
12+
13+
/**
14+
* 传统 for 循环方式
15+
*/
16+
// 输入,如五官、身材、家境等
17+
const input = [1, 2, 3, 4];
18+
// 神经元权重
19+
const w = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]];
20+
// 输出
21+
const output = [0, 0, 0, 0];
22+
// 循环神经元
23+
for (let i = 0; i < w.length; i++) {
24+
for (let j = 0; j < input.length; j++) {
25+
output[i] += input[j] * w[i][j];
26+
}
27+
}
28+
// 每个神经元等值
29+
console.log(output); // [30, 40, 50, 60]
30+
31+
/**
32+
* tensor方式
33+
* 语法简洁,GPU加速
34+
*/
35+
tf.tensor(w).dot(tf.tensor(input)).print();

0 commit comments

Comments
 (0)