I am trying to use EfficientNetB7 from keras implementation Image classification via fine-tuning with EfficientNet
but always the following code gives me error:
def build_model(num_classes):
inputs = layers.Input(shape=(IMG_SIZE, IMG_SIZE, 3))
x = img_augmentation(inputs)
model = EfficientNetB7(include_top=False, input_tensor=x, weights="imagenet")
# Freeze the pretrained weights
model.trainable = False
# Rebuild top
x = layers.GlobalAveragePooling2D(name="avg_pool")(model.output)
x = layers.BatchNormalization()(x)
top_dropout_rate = 0.2
x = layers.Dropout(top_dropout_rate, name="top_dropout")(x)
outputs = layers.Dense(NUM_CLASSES, activation="softmax", name="pred")(x)
# Compile
model = tf.keras.Model(inputs, outputs, name="EfficientNet")
optimizer = tf.keras.optimizers.Adam(learning_rate=1e-2)
model.compile(optimizer=optimizer, loss="categorical_crossentropy", metrics=["accuracy")
return model
and I call the function using:
with strategy.scope():
model = build_model(num_classes=NUM_CLASSE)
epochs = 10 # @param {type: "slider", min:8, max:80}
hist = model.fit(train_set, epochs=epochs, validation_data=test_set, verbose=2)
plot_hist(hist)
Error:
NameError: name 'layers' is not defined
can somebody help me?