代码之家  ›  专栏  ›  技术社区  ›  user836026

将作为一个功能restnet训练的模型的负载权重加载到restnet模型中,但使用多层结构构建

  •  0
  • user836026  · 技术社区  · 4 年前

    我使用的代码将resnet模型训练为非功能层;

     base_model = tf.keras.applications.ResNet50(include_top=False, weights=None, input_shape=(224, 224, 3))
        base_model.trainable = True
        
        inputs = Input((224, 224, 3))
        h = base_model(inputs, training=True)
        model = Model(inputs, projection_3)
    

    当您调用summary时:

    Layer (type)                Output Shape              Param #   
    =================================================================
     input_image (InputLayer)    [(None, 256, 256, 3)]     0         
                                                                     
     resnet50 (Functional)       (None, 8, 8, 2048)        23587712  
                                                                     
    =================================================================
    

    现在,我需要将重量加载到多层结构的resnet中

    Resmodel  = tf.keras.applications.ResNet50(input_tensor=inputs, weights=None, include_top=False)
    

    然而,当装载重量时,我得到:

     model.load_weights(filename)
    
    ValueError: Layer count mismatch when loading weights from file. Model expected 106 layers, found 4 saved layers.
    

    它是同一个模型,只有一个功能模型(整个模型作为一个层),另一个分为多个层。如何在它们之间传递重量。

    0 回复  |  直到 4 年前
        1
  •  1
  •   keertika jain    4 年前

    再次尝试保存模型

    模型。层[1] 型号保存(“新型号h5”)