Search code examples
pythonyololoss

How is the YOLOv8 best loss model selected by the trainer class?


From the YOLOv8 documentation, it is not clear to me which loss metric the YOLOv8 trainer class uses in determining the best loss model that is saved in a training run. Is it based on the validation or training loss?

Specifically, when I look at the outputs from a YOLOv8 training run, I do not see any metadata indicating which epoch resulted in the best loss model saved at runs/train/weights/best.pt


Solution

  • In the save_model function you can see that it uses the maximum fitness to save the best model. The fitness is defined as the weighted combination of 4 metrics [P, R, [email protected], [email protected]:0.95]. P and R are disregarded for some reason. [email protected], [email protected]:0.95 are weighted 0.1 and 0.9 respectively.

    If fitness cannot be found, loss is used instead