tf js change weighs

Solutions on MaxInterview for tf js change weighs by the best coders in the world

showing results for - "tf js change weighs"
Maelia
22 Jan 2020
1(async() => {
2const model = tf.sequential({
3        layers: [tf.layers.dense({units: 1, inputShape: [10]})]
4    });
5    model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});
6    for (let i = 1; i < 5 ; ++i) {
7      const h = await model.fit(tf.ones([8, 10]), tf.ones([8, 1]), {
8          batchSize: 4,
9          epochs: 3
10      });
11      console.log("Loss after Epoch " + i + " : " + h.history.loss[0]);
12    }
13    
14    const p = await model.predict(tf.zeros([1, 10]))
15    p.print()
16    const layers = model.layers
17
18    layers[0].setWeights([tf.zeros([10, 1]), tf.zeros([1])])
19    
20    const q = await model.predict(tf.zeros([1, 10]))
21    q.print()
22
23
24})()