📜  tf js 更改权重 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:20.737000             🧑  作者: Mango

代码示例1
(async() => {
const model = tf.sequential({
        layers: [tf.layers.dense({units: 1, inputShape: [10]})]
    });
    model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});
    for (let i = 1; i < 5 ; ++i) {
      const h = await model.fit(tf.ones([8, 10]), tf.ones([8, 1]), {
          batchSize: 4,
          epochs: 3
      });
      console.log("Loss after Epoch " + i + " : " + h.history.loss[0]);
    }
    
    const p = await model.predict(tf.zeros([1, 10]))
    p.print()
    const layers = model.layers

    layers[0].setWeights([tf.zeros([10, 1]), tf.zeros([1])])
    
    const q = await model.predict(tf.zeros([1, 10]))
    q.print()


})()