Skip to content

Commit 81abcb9

Browse files
committed
model and training with dummy data
1 parent f0340c0 commit 81abcb9

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

index.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
11
console.log("Hello Autoencoder 🚂");
22

33
import * as tf from '@tensorflow/tfjs-node'
4+
5+
const autoencoder = tf.sequential();
6+
7+
const encoder = tf.layers.dense({
8+
units: 32,
9+
inputShape: [784],
10+
activation: 'relu'
11+
});
12+
const decoder = tf.layers.dense({
13+
units: 784,
14+
activation: 'sigmoid'
15+
// inputShape: [32]
16+
});
17+
18+
autoencoder.add(encoder);
19+
autoencoder.add(decoder);
20+
21+
autoencoder.compile({
22+
optimizer: 'adam',
23+
loss: 'binaryCrossentropy',
24+
metrics: ['accuracy'],
25+
});
26+
27+
28+
function generateImage() {
29+
const img = [];
30+
for (let i = 0; i < 784; i++) {
31+
img[i] = Math.random();
32+
}
33+
return img;
34+
}
35+
36+
const x_inputs = [];
37+
for (let i = 0; i < 1000; i++) {
38+
x_inputs[i] = generateImage();
39+
}
40+
41+
const x_train = tf.tensor2d(x_inputs);
42+
x_train.print();
43+
44+
trainModel();
45+
46+
async function trainModel() {
47+
await autoencoder.fit(x_train, x_train, {
48+
epochs: 50,
49+
batch_size: 256,
50+
shuffle: true,
51+
verbose: true
52+
});
53+
}
54+
55+
56+
57+
58+

0 commit comments

Comments
 (0)