Keras replacing input layer

前端 未结 6 2130
清酒与你
清酒与你 2020-11-30 07:29

The code that I have (that I can\'t change) uses the Resnet with my_input_tensor as the input_tensor.

model1 = keras.applications.resnet50.ResNe         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 08:17

    When you saved your model using:

    old_model.save('my_model.h5')
    

    it will save following:

    1. The architecture of the model, allowing to create the model.
    2. The weights of the model.
    3. The training configuration of the model (loss, optimizer).
    4. The state of the optimizer, allowing training to resume from where you left before.

    So then, when you load the model:

    res50_model = load_model('my_model.h5')
    

    you should get the same model back, you can verify the same using:

    res50_model.summary()
    res50_model.get_weights()
    

    Now you can, pop the input layer and add your own using:

    res50_model.layers.pop(0)
    res50_model.summary()
    

    add new input layer:

    newInput = Input(batch_shape=(0,299,299,3))    # let us say this new InputLayer
    newOutputs = res50_model(newInput)
    newModel = Model(newInput, newOutputs)
    
    newModel.summary()
    res50_model.summary()
    

提交回复
热议问题