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

后端 未结 3 2010
灰色年华
灰色年华 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:47

    You must freeze layers individually (before compilation):

    for l in conv_base.layers: 
        l.trainable=False
    

    And if this doesn't work, you should probably use the new sequential model to freeze the layers.

    If you have models in models you should do this recursively:

    def freezeLayer(layer):
        layer.trainable = False
        if hasattr(layer, 'layers'):
            for l in layer.layers:
                freezeLayer(l)
    
    freezeLayer(model)
    

提交回复
热议问题