我使用的代码将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.
它是同一个模型,只有一个功能模型(整个模型作为一个层),另一个分为多个层。如何在它们之间传递重量。