shouldn't model.trainable=False freeze weights under the model?

后端 未结 3 2003
灰色年华
灰色年华 2020-12-10 15:58

I am trying to freeze the free trained VGG16\'s layers (\'conv_base\' below) and add new layers on top of them for feature extracting. I expect to get same prediction result

3条回答
  •  旧巷少年郎
    2020-12-10 16:53

    The top-rated answer does not work. As suggested by Keras official documentation (https://keras.io/getting-started/faq/), it should be performed per layer. Although there is a parameter "trainable" for a model, it is probably not implemented yet. The safest way is to do as follows:

    for layer in model.layers:
        layer.trainable = False
    model.compile()
    

提交回复
热议问题