Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
Why there is an accuracy drop on the test dataset (around 7% drop) after loading the saved model?

I am building a model for classifying whether the person in the image is wearing a mask or not. I used EfficientNetB0 model with custom data augmentation (sequential) layer all stacked with the help of Functional layer. After I saved the model (in h5 format) and loaded the saved model, the accuracy on the test dataset was different.

The accuracy on the test dataset originally was around 98% After loading the saved model, the accuracy on the test dataset plummeted to 91%

I used image_dataset_from_directory to load the images for train, test and validation sets.

train_data = keras.preprocessing.image_dataset_from_directory(
    train_dir, image_size=(224, 224),
    color_mode="rgb", batch_size=64, label_mode="categorical"
)

Then created a prefetch dataset

train_dataset = train_data.shuffle(buffer_size=1000).prefetch(buffer_size=tf.data.AUTOTUNE)

This is the custom data augmentation layer:

data_aug = keras.Sequential([
    keras.layers.RandomRotation(0.3),
    keras.layers.RandomContrast(0.3)
])

The model

inputs = keras.layers.Input(shape=(224, 224, 3))
x = data_aug(inputs)
x = eff_model(x, training=False)
x = keras.layers.GlobalAveragePooling2D()(x)
x = keras.layers.Dense(3, activation="softmax")(x)

model = keras.Model(inputs=inputs, outputs=x)

model.compile(loss=keras.losses.CategoricalCrossentropy(), metrics=["accuracy"], 
              optimizer=keras.optimizers.Adam(0.001))

history = model.fit(train_dataset, steps_per_epoch=len(train_dataset), epochs=20,
                    validation_data=val_dataset, validation_steps=len(val_dataset))

This is the accuracy my model achieved originally on the test dataset.

enter image description here

Saving the model and reloading the saved model:

model.save("face_Detect.h5")
load_model = keras.models.load_model("/content/face_Detect.h5")

This is the accuracy achieved on the loaded model:

enter image description here

I have no idea because the accuracy on the test dataset for the original model and loaded model should be similar but this is a huge difference. Is this a bug in Tensorflow 2.7.0 or am I making some horrendous mistake ?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda