【问题标题】:Error : You are trying to load a weight file containing 436 layers into a model with 437 layers错误:您正在尝试将包含 436 层的权重文件加载到具有 437 层的模型中
【发布时间】:2021-03-07 05:15:56
【问题描述】:

我正在尝试在 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()

【问题讨论】:

    标签: python deep-learning conv-neural-network efficientnet


    【解决方案1】:

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

    如果您想要迁移学习,请使用此

    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)

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 2019-06-12
      • 1970-01-01
      • 2022-07-23
      • 2019-01-03
      • 1970-01-01
      • 2018-11-27
      • 2020-01-25
      • 2020-06-24
      相关资源
      最近更新 更多