Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!