I am new to Keras and I am trying to get the weights in Keras. I know how to do it in Tensorflow in Python.
Code:
data = np.array(attributes, \'int64\')
You can access and set the weights or parameters of the model's layers using get_weights
and set_weights
methods. From Keras documentation:
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 ofget_weights
).
Each Keras model has a layers
attribute which is the list of all the layers in the model. For example, in the sample model you provided, you can get the weights of the first Dense
layer by running:
model.layers[1].get_weights()
It would return a list of two numpy arrays: the first one is the kernel parameters of the Dense layer the second array is the bias parameters.