Replies: 1 comment · 9 replies
-
|
👋 Hello @pzae, thank you for your interest in Ultralytics 🚀! This is an automated response — an Ultralytics engineer will also assist you here shortly. We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered. If this is a custom training ❓ Question, please provide as much information as possible, including:
Join the Ultralytics community where it suits you best. For real-time chat, head to Discord 🎧. Prefer in-depth discussions? Check out Discourse. Or dive into threads on our Subreddit to share knowledge with the community. UpgradeUpgrade to the latest pip install -U ultralyticsEnvironmentsYOLO may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLO Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit. |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Great detail, thanks. The class-name mismatch is from re-instantiating with import os, glob, torch
from ultralytics import YOLO
def on_fit_epoch_end(trainer):
# Prefer EMA; already has correct `names` from training
m = trainer.ema.ema or trainer.model
img = sorted(glob.glob(os.path.join(trainer.data['val'], '*')))[0]
m.eval()
with torch.inference_mode():
y = YOLO(m) # no disk I/O, keeps custom classes
r = y.predict(source=img, imgsz=trainer.args.imgsz, save=False, verbose=False)
r[0].show()
# Alternative (uses disk, but also correct classes each epoch):
# y = YOLO(trainer.last); y.predict(source=img, imgsz=trainer.args.imgsz, save=False, verbose=False)During training we set
|
Beta Was this translation helpful? Give feedback.
All reactions
-
|
The error still persists :( Here is the (pl_env) E:\python_learning>yolo checks OS Windows-10-10.0.26100-SP0 numpy 2.1.1>=1.23.0 And the... ...error textFileNotFoundError Traceback (most recent call last) Cell In[4], line 19 17 model = YOLO("yolo11n.pt") 18 model.add_callback("on_fit_epoch_end", on_fit_epoch_end) ---> 19 model.train(data=DATA_YAML, epochs=3)File E:\python_learning\pl_env\lib\site-packages\ultralytics\engine\model.py:800, in Model.train(self, trainer, **kwargs) File E:\python_learning\pl_env\lib\site-packages\ultralytics\engine\trainer.py:235, in BaseTrainer.train(self) File E:\python_learning\pl_env\lib\site-packages\ultralytics\engine\trainer.py:498, in BaseTrainer._do_train(self) File E:\python_learning\pl_env\lib\site-packages\ultralytics\engine\trainer.py:208, in BaseTrainer.run_callbacks(self, event) Cell In[4], line 13, in on_fit_epoch_end(trainer) File E:\python_learning\pl_env\lib\site-packages\ultralytics\models\yolo\model.py:83, in YOLO.init(self, model, task, verbose) File E:\python_learning\pl_env\lib\site-packages\ultralytics\engine\model.py:153, in Model.init(self, model, task, verbose) File E:\python_learning\pl_env\lib\site-packages\ultralytics\engine\model.py:302, in Model._load(self, weights, task) File E:\python_learning\pl_env\lib\site-packages\ultralytics\utils\checks.py:578, in check_file(file, suffix, download, download_dir, hard) FileNotFoundError: 'DetectionModel( |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Thanks for the thorough trace — the failure is from calling import torch
from ultralytics import YOLO
def on_fit_epoch_end(trainer):
imgs = getattr(trainer.validator.dataloader.dataset, "im_files", [])[:1]
if not imgs:
return
y = YOLO(trainer.last) # or `trainer.best`
with torch.inference_mode():
results = y.predict(source=imgs, imgsz=trainer.args.imgsz, save=False, verbose=False)
results[0].show()
|
Beta Was this translation helpful? Give feedback.
All reactions
-
|
It worked, this is exactly what I needed! Thank you so much for your attention and the time you spent helping me. I really appreciate your assistance and detailed explanations. |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Great to hear it’s working—credit goes to the YOLO community and the Ultralytics team. If you want those epoch visuals auto-logged without extra code, enable a logger like W&B or ClearML; their callbacks capture validation images/metrics each epoch—see the W&B callback reference and examples in the ClearML callback reference: W&B callbacks, ClearML callbacks. |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, thank you very much for this excellent library!
I would like to evaluate the model after each training epoch: I want to plot a custom metric versus the number of epochs for both the training and validation sets, and also display visualizations of predictions for a few validation examples to see how the model is learning. I managed to implement this using callbacks, but the code turned out to be rather complex — it includes saving and loading the model as well as obtaining predictions.
My question is: are there any methods in the trainer or validator that already contain the model’s predictions on the training and validation sets, to help simplify my task?
Beta Was this translation helpful? Give feedback.
All reactions