'problem in testing accuracy after using saved trained model
I run code for training and testing dataset with many methods and it gives good and high accuracy for testing data, I saved the trained models with p=0 when I use the saved files of the trained models to run the testing data again with p=1 I got very bad accuracies there is a problem in saving the models I don't how and what is the problem and how to fix it. I need to save training models to get thier testing accuracies when I need without make training again
def model_fitting(model, model_name, p):
history_path = '../input/' + model_name+'/model_history.npy'
#history_path = model_name+'_history.npy'
#print(model_path)
print(history_path)
reduce_lr = ReduceLROnPlateau(monitor='val_accuracy',factor=0.09,patience=2)
if ((not os.path.exists(model_name+'.h5')) or (not os.path.exists(history_path))):
history = model.fit(train_data_generator, epochs=epoch_num, validation_data=validation_data_generator, callbacks=[reduce_lr])
history = history.history
model.save(model_name+'.h5')
np.save(history_path,history)
else:
#Enter '0' if you want to train a new model,
#'1' to use a pretrained model and
#'2' to train a pretraind model
if (p==0):
history = model.fit(train_data_generator, epochs=epoch_num, validation_data=validation_data_generator, callbacks=[reduce_lr])
history = history.history
np.save(history_path,history)
model.save(model_name+'.h5')
elif (p==1):
model = tensorflow.keras.models.load_model(model_name+'.h5')
history=np.load(history_path,allow_pickle='TRUE').item()
elif (p==2):
model = tensorflow.keras.models.load_model(model_name+'.h5')
history = model.fit(train_data_generator, epochs=epoch_num, validation_data=validation_data_generator, callbacks=[reduce_lr])
history = history.history
np.save(history_path,history)
model.save(model_name+'.h5')
return history
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
