zekaouinoureddine/COVID-19-Detection-From-X-Ray

Error during the Training Step of ResNet 50 -> tensorflow warning: can save best model only with val_acc available, skipping

Raghav2305 opened this issue · 2 comments

During the training step, I provided metric = "val_acc" and after completion of the first epoch, it gave the error: "tensorflow warning: can save the best model only with val_loss available, skipping". I tried changing the metric to "val_accuracy" as defined in the tensorflow documentation but still had the same warning. Because of this the model is training completely but no best_model.h5 file is being stored.

error

Hey, In Keras, val_acc and val_accuracy are equivalent metrics. To fix your issue, I recommend replacing the deprecated function fit_generator() with fit(), and omitting the arguments steps_per_epoch and validation_steps. These changes should help eliminate the warning message and restore the best_model.h5.

Before

history=model.fit_generator(train_datagen.flow(X_train, y_train, batch_size = bs),
                            steps_per_epoch = len(X_train)//bs,
                            validation_data = (X_valid, y_valid),
                            validation_steps = len(X_valid)//bs,
                            epochs =epochs,
                            callbacks= [checkpointer])

After

history=model.fit(train_datagen.flow(X_train, y_train, batch_size = bs),
                            # steps_per_epoch = len(X_train)//bs,
                            validation_data = (X_valid, y_valid),
                            # validation_steps = len(X_valid)//bs,
                            epochs =epochs,
                            callbacks= [checkpointer])

Hey, I tried this and it worked perfectly. By solving this issue #3 is also resolved. Thanks for the help. Closing both issues now. Thanks again!