Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weights transfer from one model to another model with different layer architecture

I have a CNN network with three layers and after fitting the model, weights are saved on disk. The second time I load the weights, but this time model is increased with a layer. So it is now 4 layer network. Is it possible to transfer model weights with the different architecture? If yes then how? I am using keras for development.

For me it shows error: 'You are trying to load a weight file containing 3 layers into a model with 4 layers'.

Thanks in advance!

like image 845
dumb_coder Avatar asked Oct 29 '22 16:10

dumb_coder


1 Answers

I have not tried this, but it should be possible by using the layer.get_weights() and layer.set_weights(weights) methods.

weights = old_model_layer.get_weights()
new_model_layer.set_weights(weights)

See https://keras.io/layers/about-keras-layers/ for more info.

like image 116
Manto Avatar answered Nov 05 '22 14:11

Manto