作为一个功能性 resnet 和 resnet 模型训练但使用多层构建的模型的负载权重

Load weight of a model trained as one functional restnet into restnet model but built using multiple layer

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

 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)

当您调用摘要时:

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.

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

再次尝试保存模型

model_n = model.layers[1] model_n.save("new_model.h5")