0

我正在尝试在 kaggle 上运行具有 nosiy 学生权重的高效网络 B7 模型,但出现错误:

You are trying to load a weight file containing 436 layers into a model with 437 layers.

我的代码:

model_path = '../input/keras-efficientnet-noisy-students/efficientnet-b7_noisy-student_notop.h5'  
n_labels = labels.shape[1]
with strategy.scope():
    model = tf.keras.Sequential([
        efn.EfficientNetB7(
            input_shape=(size, size, 3),
            weights=model_path,
            include_top=False,
            drop_connect_rate=0.5),
        tf.keras.layers.GlobalAveragePooling2D(),
        tf.keras.layers.Dense(n_labels, activation='sigmoid')
    ])
    model.compile(
        optimizer='adam',
        loss='binary_crossentropy',
        metrics=[tf.keras.metrics.AUC(multi_label=True)])
    model.summary()
4

1 回答 1

0

在您的情况下,预训练模型层数和您创建的模型层数不匹配

如果你想要迁移学习然后使用这个

tf.keras.applications.EfficientNetB0(
    include_top=False,
    weights="model_path",
    input_shape=(size, size, 3),
    pooling=None,
    classes='Here how much classes present in your data    
)

如果您想扩展此模型功能,那么您也可以这样做,只需将此模型输出传递给您的新层,例如 (model_name.output)

于 2021-03-07T22:47:49.963 回答