I am using colab as environment, I am quite new to fastai, I train the model(vgg13_bn) with one cycle policy then export and test it again on the same validation set, I get the same results of the validation but when I close the session and start a new one I get even better results by an increase of 2%.
I search about safe export of model all I found was to change this
learn.export()
to be
learn = learn.to_fp32()
learn.export()
and yet it does not work either
I test it multiple times but still get improvement and this improvement is fixed not random
I will always get 0.9899 from the original 0.9649 validation accuracy after the first time the exported model results change, I tried to repeat the train again and again but it changes always to get better results than the saved results on the validation set.
I save exported models in the driver as storage of colab but before i export model, i use a callback to load best result in all epochs :
class SaveBestModel(Recorder):
names="best_model"
def __init__(self, learn,name='best_model'):
super().__init__(learn)
self.name = SaveBestModel.names
self.best_loss = None
self.best_acc = None
self.save_method = self.save_when_acc
def save_when_acc(self, metrics):
loss, acc = metrics[0], metrics[2]
if self.best_acc == None or acc > self.best_acc:
self.best_acc = acc
self.best_loss = loss
self.learn.save(f'{self.name}')
print("Save the best accuracy {:.5f}".format(self.best_acc))
elif acc == self.best_acc and loss < self.best_loss:
self.best_loss = loss
self.learn.save(f'{self.name}')
print("Accuracy is eq,Save the lower loss {:.5f}".format(self.best_loss))
def on_epoch_end(self,last_metrics=MetricsList,**kwargs:Any):
self.save_method(last_metrics)
then
learn.load("best_model")
unfortunately, I could not test it because I do not have a test set so I do not know if this improvement is good or bad.
any ideas what the cause of improvement?