Search code examples
pythontensorflowtensorflow2.0bias-neuron

How to get bias tensorflow?


import tensorflow as tf

new_model = tf.keras.models.load_model('saved_model/my_model_KNOCK_2_RMS')
new_model.get_weights()

How can I retrieve the Bias matrix as I retrieve the weights? Or is there a different way to get the bias matrix?


Solution

  • model.get_weights() returns all the variables of your network, biases included.

    You can iterate over the variables attribute and filter on the name of the tf.Variable to get only the biases.

    biases = [var for var in new_model.variables if "bias" in var.name]