0

Imagine that my network made in Sequential mode in Keras currently has 3 hidden layers, with [3,5,4] nodes, and I trained it for a given dataset. If now I want to create another network for the same dataset, but with an extra hidden layer in the end with e.g 6 nodes, so that the final network results in [3,5,4,6]; can I reuse the same weights for the first three layers? How?

Edit: Save and load weights in keras explains just how to save them but in my case I want to include them in a new network and add later a new hidden layer right before the output, which in that post I believe is a different case.

Andres C
  • 13
  • 4
  • Possible duplicate of [Save and load weights in keras](https://stackoverflow.com/questions/47266383/save-and-load-weights-in-keras) – Siddharth Das Jun 19 '19 at 10:43
  • 1
    Take a look at [this question](https://stackoverflow.com/questions/53314152/copying-weights-of-a-specific-layer-keras) – CaptainTrunky Jun 19 '19 at 11:20
  • @CaptainTrunky I am interested in reducing training time (I am building a lot of Neural Nets sequentially, incrementing on each run some parameters, one of them the number of layers, so that to me it made sense to reuse the weights of a previous model that was exactly the same but with an extra added layer now) – Andres C Jun 19 '19 at 11:59
  • @AndresC So you could build your network with additional layers, copy weights from pre-trained one to yours layer-by-layer and then train – CaptainTrunky Jun 19 '19 at 12:02
  • @AndresC After loading the pretrained weight as mentioned by @CaptainTrunly you can freeze the trained layers by setting `layer.trainable = False`. In this way you can save the training time. – meowongac Jun 19 '19 at 16:19
  • Got it! Thank you guys!! – Andres C Jun 19 '19 at 16:26

0 Answers0