Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit b9b5b19

Browse files
Add trainer to yolov8 validator when calling w/o recipe (#1599)
* Add trainer to validator when calling w/o recipe * Re-work comment message to better describe what was done --------- Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com>
1 parent 4c201db commit b9b5b19

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/sparseml/yolov8/trainers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import warnings
2121
from copy import copy, deepcopy
2222
from datetime import datetime, timedelta
23+
from functools import partial
2324
from pathlib import Path
2425
from typing import List, Optional
2526

@@ -488,6 +489,12 @@ def save_model(self):
488489
def final_eval(self):
489490
# skip final eval if we are using a recipe
490491
if self.manager is None and self.checkpoint_manager is None:
492+
# patch the validator, so it always has access to the
493+
# trainer object, which is needed to circumvent original ultralytics
494+
# call that ignores the trainer object
495+
# https://github.com/ultralytics/ultralytics/blob/
496+
# 6c65934b555e64bf26edd699865754b5ff651d0c/ultralytics/yolo/engine/trainer.py#L551
497+
self.validator = partial(self.validator, trainer=self)
491498
return super().final_eval()
492499

493500
def callback_teardown(self):

0 commit comments

Comments
 (0)