-
Notifications
You must be signed in to change notification settings - Fork 0
/
rps-dataset.js
35 lines (33 loc) · 885 Bytes
/
rps-dataset.js
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
class RPSDataset {
constructor() {
this.labels = []
}
addExample(example, label) {
if (this.xs == null) {
this.xs = tf.keep(example);
this.labels.push(label);
} else {
const oldX = this.xs;
this.xs = tf.keep(oldX.concat(example, 0));
this.labels.push(label);
oldX.dispose();
}
}
encodeLabels(numClasses) {
for (var i = 0; i < this.labels.length; i++) {
if (this.ys == null) {
this.ys = tf.keep(tf.tidy(
() => {return tf.oneHot(
tf.tensor1d([this.labels[i]]).toInt(), numClasses)}));
} else {
const y = tf.tidy(
() => {return tf.oneHot(
tf.tensor1d([this.labels[i]]).toInt(), numClasses)});
const oldY = this.ys;
this.ys = tf.keep(oldY.concat(y, 0));
oldY.dispose();
y.dispose();
}
}
}
}