我正在开展一个项目,需要编辑个人权重和偏差。
是否有任何方法可以实际访问图层权重和偏差,以便我可以手动编辑它们?
来自tf.layers.dense()
到目前为止,我已经创建了自己的模型并将偏差存储在外部,如下所示:
for _ in range(population_size):
hidden_layer.append(tf.Variable(tf.truncated_normal([11, 20])))
output_layer.append(tf.Variable(tf.truncated_normal([20, 9])))
population.append([hidden_layer, output_layer])
然后我尝试使用 feed dict 将人口输入到模型中。事实证明这是一个真正的 hell ,因为我无法将它们输入模型,因为变量的形状不一样。
是否有任何 native 支持从致密层获取权重?
最佳答案
All Keras layers have a number of methods in common:
layer.get_weights(): returns the weights of the layer as a list of Numpy arrays. layer.set_weights(weights): sets the weights of the layer from a list of Numpy arrays (with the same shapes as the output of get_weights).
您可以使用 yourmodel.layers
轻松访问模型内的所有层。
关于python-3.x - 编辑图层中的各个权重和偏差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51380363/