How to load only specific weights on Keras

前端 未结 2 1145
忘了有多久
忘了有多久 2020-12-13 09:28

I have a trained model that I\'ve exported the weights and want to partially load into another model. My model is built in Keras using TensorFlow as backend.

Right n

2条回答
  •  萌比男神i
    2020-12-13 10:13

    If your first 9 layers are consistently named between your original trained model and the new model, then you can use model.load_weights() with by_name=True. This will update weights only in the layers of your new model that have an identically named layer found in the original trained model.

    The name of the layer can be specified with the name keyword, for example:

    model.add(Dense(8, activation='relu',name='dens_1'))
    

提交回复
热议问题