A way to save the best model according to val loss?

1

Hi I’m trying to save the best model when the validation loss is minimum
this is not my code but I simplified the code for the convenience :slight_smile:

in this code I can’t understand the part where
if best_score > avg_val_loss:
torch.save(…)

since best_score value is np.inf
what does it mean by np.inf > avg_val_loss??

how can I save the model according to the validation loss?

any comment would help me!
thanks and have a nice day!

you could try:

best_score = 0
if best_score < avg_val_score:
    torch.save(model)
    best_score = avg_val_score

thanks bro!
but what does it mean by “save the model when avg_val_loss is less than np.inf?”

:slight_smile:
sorry, I also can not understand it.

I think best_score > avg_val_loss always holds.
1 Like