I want to convert a pre-trained caffe model to keras, then i need to initialize the layers , layer by layer. I saved the weights and biases in a mat file and I loaded them to python workspace. I know "weights" parameter get the numpy array but not how? Thanks
You can get more information about how to set the weight of a model in the Keras Layers Documentation. Basically you use :
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
).
Or you can directly initialize them when you create the layer. Every layer has a parameter weights
that you can set with a numpy array. Read each layer's documentation to feed the right weights format. For example, Dense()
layers accept this format for the parameter weights
:
List of Numpy arrays to set as initial weights. The list should have 2 elements, of shape (input_dim, output_dim) and (output_dim,) for weights and biases respectively. source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With