william007
william007

Reputation: 18545

Output trained parameters of Keras model

If I am training on a GRU model, is there a way I can output the learnt parameters so that when I train next time with more data, I can initialize with those learnt parameters as a starting point?

Upvotes: 1

Views: 8603

Answers (1)

Marcin Możejko
Marcin Możejko

Reputation: 40516

  1. In case of saving the whole model:

    weights = model.get_weights() # Getting params
    model.set_weights(weights) # Setting params
    
  2. In case of saving single layer: You need to find the index of a layer you want to save (let's say that it is i), then:

    weights = model.layers[i].get_weights() # Getting params
    model.layers[i].set_weights(weights) # Setting params
    

Upvotes: 5

Related Questions