无法将 EfficientNet 与迁移学习一起使用

问题描述

我想在 Eurosat-rgb 数据集中使用 EfficientNet 和迁移学习。我的问题是它似乎没有学习。

首先,我使用 MobileNet 的迁移学习从以下模型开始,它运行良好 (1)

model_base = tf.keras.applications.MobileNet(weights='imagenet',include_top=False,input_shape=input_shape=(224,224,3))
model_base.trainable=False
model = tf.keras.Sequential([
  model_base,tf.keras.layers.GlobalAveragePooling2D(name="avg_pool"),tf.keras.layers.Dense(10,activation="softmax",name="predictions")
])

然后,我从 MobileNet 更改为 EfficientNetB1,突然它什么也学不到 (2)。 然后,如果我尝试使用 model_base.trainable=True,训练准确度会提高,但验证准确度不会(3)

我做错了什么?

如果我在没有转移学习的情况下使用 EfficientNet,我也会得到很好的结果 (4),但显然需要很多时间。 我也试过将优化器从 sgd 更改为 adam,但它也不起作用。

解决方法

我认为发生的事情是 Mobilenet 的预处理功能将图像缩放到 -1 到 +1 之间。但是对于 EfficientNetB1,位于 here 的文档说明

Note: each Keras Application expects a specific kind of input preprocessing.
For EfficientNet,input preprocessing is included as part of the model 
(as a Rescaling layer),and thus tf.keras.applications.efficientnet.preprocess_input
is actually a pass-through function.
EfficientNet models expect their inputs to be float tensors of pixels with values
in the [0-255] range.

因此,当您从 Mobilenet 更改为 Efficientnet 时,请务必删除像素值的任何重新缩放