Getting weights from tensorflow.js neural network

旧街凉风 提交于 2019-12-06 05:52:26
Dhruv Guliani

It seems like there is probably a simpler and cleaner way to do what you want, but regardless:

Calling this.model.getWeights() will give you an array of Variables that correspond to layer weights and biases. Calling data() on any of these array elements will return a promise that you can resolve to get the weights.

I haven't tried manually setting the weights, but there is a this.model.setWeights() method.

Goodluck.

Here is a simple way to print off all the weights:

for (let i = 0; i < model.getWeights().length; i++) {
    console.log(model.getWeights()[i].dataSync());
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!