-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
109 lines (91 loc) · 3.38 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<html>
<head>
<!-- Load TensorFlow.js -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-vis"></script>
<!-- Place your code in the script tag below. You can also use an external .js file -->
<script>
// Notice there is no 'import' statement. 'tf' is available on the index-page
// because of the script tag above.
function doThing() {
console.log("a");
const visorInstance = tfvis.visor();
if (!visorInstance.isOpen()) {
visorInstance.toggle();
}
visorInstance.surface({
name: 'Data',
tab: 'Training Progress'
});
const metrics = ['loss'];
const container = {
name: 'Data',
tab: 'Training Progress',
styles: {
height: '1000px'
}
};
const myCallbacks = tfvis.show.fitCallbacks(container, metrics);
// Define a model for linear regression.
const model = tf.sequential();
model.add(tf.layers.dense({
units: 3,
inputShape: [4],
activation: "selu"
}));
model.add(tf.layers.dense({
units: 6
}))
// Prepare the model for training: Specify the loss and the optimizer.
model.compile({
loss: 'meanSquaredError',
optimizer: 'sgd'
});
const model2 = tf.sequential();
model2.add(tf.layers.dense({
units: 3,
inputShape: [4],
activation: "selu"
}));
model2.add(tf.layers.dense({
units: 6
}))
// Prepare the model for training: Specify the loss and the optimizer.
model2.compile({
loss: 'meanSquaredError',
optimizer: 'sgd'
});
model.layers.forEach(element => {
let KB = (element.getWeights());
console.log(KB[0].array());
});
// Generate some synthetic data for training.
const xs = tf.tensor2d([65, 472, 50, 0], [1, 4]);
const ys = tf.tensor2d([-10, 36.34, 33.05, -1.75, 24.8, -1.75], [1, 6]);
// Train the model using the data.
model.fit(xs, ys, {
epochs: 50,
callbacks: myCallbacks
}).then(() => {
// Use the model to do inference on a data point the model hasn't seen before:
// Open the browser devtools to see the output
model.predict(tf.tensor2d([
[65, 472, 50, 0],
[65, 472, 50, 0]
], [2, 4])).print();
model2.setWeights(model.getWeights());
model.layers.forEach(element => {
let KB = (element.getWeights());
console.log(KB[0].array());
});
model2.layers.forEach(element => {
let KB = (element.getWeights());
console.log(KB[0].array());
});
});
};
</script>
</head>
<body onload="doThing();">
</body>
</html>