python - 错误:您正在尝试将包含 436 层的权重文件加载到具有 437 层的模型中
问题描述
我正在尝试在 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()
解决方案
在您的情况下,预训练模型层数和您创建的模型层数不匹配
如果你想要迁移学习然后使用这个
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)
推荐阅读
- c - 计算数组中有多少个数满足特定条件的函数
- django - django-rest-framework get_schema_view:TypeError:“文档”类型的对象不是 JSON 可序列化的
- angular - 将 asp.net 核心 API 与主机中的 Angular 应用程序集成
- airflow - Apache Airflow AttributeError:“NoneType”对象没有属性“create_dagrun”
- javascript - 新日期没有给我正确的价值
- swiftui - 我无法让我的 LazyVGrid 显示超过两行
- python - User.query.filter_by(id=user_id).first() 和 User.query.get(user_id) 在 Flask Sql Alchemy 中返回 None
- c# - C#面临通过Base64加密和解密文本的问题
- css - iOS Safari - 使用 CSS 更改选择下拉选项字体大小?
- reactjs - 操作 React 渲染属性