tensorflowkerasconv-neural-networkefficientnet

Unable to use EfficientNet with transfer learning


I want to use EfficientNet with transfer learning in the Eurosat-rgb dataset. The problem I have is that it doesn't seem to learn.

First, I start with the following model using transfer learning with MobileNet and it works fine (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")
])

Then, I change from MobileNet to EfficientNetB1, and suddenly it doesn't learn anything (2). And then, if I try with model_base.trainable=True, training accuracy improves but not validation accuracy (3).

What am I doing wrong?

If I use EfficientNet without tranfer learning I get good results too (4), but it takes a lot of time obviusly. I've also tried by changing the optimizer from sgd to adam, but it doesn't work neither.


Solution

  • I think what is happening is that for Mobilenet the preprocessing functtion scales the images between -1 to +1. However for EfficientNetB1, the the documentation located here states

    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.
    

    So when you change from Mobilenet to Efficientnet be sure to remove any rescaling of the pixel values