Search code examples
pythonneural-networkkeraskeras-layer

Opposite of get_weights() in Keras?


The get_weights() function in Keras returns the weight matrix along with the biases of a layer in a neural network. Let's say a variable x = layer.get_weights(). I'll transfer the value of x to a different network. In the new network, I'd like to add a layer to a trained network, but with the weights and biases of this newly added layer being equivalent to x. In other words, I'd like to use the same layer of the old network in the new one. How can I do this?


Solution

  • Do you mean opposite as in set instead of get? You can assign weights in Keras using set_weights - see documentation here https://keras.io/layers/about-keras-layers/