从 tensorflow.js 神经网络获取权重 [英] Getting weights from tensorflow.js neural network
问题描述
我有这个顺序模型:
this.model = tf.sequential()
this.model.add(tf.layers.dense({units : 16, useBias : true, inputDim : 7})) // input
this.model.add(tf.layers.dense({units : 16, useBias : true, activation: 'sigmoid'})) // hidden
this.model.add(tf.layers.dense({units : 3, useBias : true, activation: 'sigmoid'})) // hidden 2
我检查了 tensorflow.js 的 API,但没有关于获取神经网络的权重(内核)的内容.那么,如何获得权重然后更改它们以应用新的权重?(用于无监督学习)
I checked API for tensorflow.js, but there's nothing about getting weights(kernels) of neural network. So, how can I get weights and then change them, to apply new weights?(for unsupervised learning)
推荐答案
似乎有一种更简单、更简洁的方式来做你想做的事,但无论如何:
It seems like there is probably a simpler and cleaner way to do what you want, but regardless:
调用 this.model.getWeights()
将为您提供一组与层权重和偏差相对应的变量.对这些数组元素中的任何一个调用 data()
将返回一个承诺,您可以解析该承诺以获取权重.
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.
我没有尝试过手动设置权重,但是有一个 this.model.setWeights()
方法.
I haven't tried manually setting the weights, but there is a this.model.setWeights()
method.
祝你好运.
这篇关于从 tensorflow.js 神经网络获取权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!