How to initialize layers using a numpy array in keras

I want to convert a pre-prepared caffe model to keras, then I need to initialize the layers, behind the layer. I saved the weights and prejudices in a mat file, and I loaded them into the python workspace. I know that the "weights" parameter gets a numpy array, but isnโ€™t it? thanks

+5
source share
1 answer

You can get more information on how to set the model weight in the Keras Layers Documentation . You mainly use:

layer.set_weights(weights) : sets the weight of a layer from a list of Numpy arrays (with the same shapes as get_weights output).

Or you can directly initialize them when creating a layer. Each layer has a weights parameter that can be set using the numpy array. Read the documentation for each level to copy the format of the correct weights. For example, Dense() layers accept this format for the weights parameter:

List of Numpy arrays to set as starting weights. The list should contain 2 elements, forms (input_dim, output_dim) and (output_dim,) for weights and offsets, respectively. a source

+2
source

Source: https://habr.com/ru/post/1264838/


All Articles