Fix plot_images for classify training (#21072)

Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
Co-authored-by: Laughing-q <1185102784@qq.com>
Co-authored-by: Laughing <61612323+Laughing-q@users.noreply.github.com>
This commit is contained in:
Muhammad Rizwan Munawar 2025-06-16 18:34:25 +05:00 committed by GitHub
parent c707bbdaf6
commit 54e63a8ff0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -181,6 +181,9 @@ makei05@outlook.de:
matthewnoyce@icloud.com:
avatar: https://avatars.githubusercontent.com/u/131261051?v=4
username: MatthewNoyce
muhammadravi251001@gmail.com:
avatar: https://avatars.githubusercontent.com/u/78993021?v=4
username: muhammadravi251001
muhammadrizwanmunawar123@gmail.com:
avatar: https://avatars.githubusercontent.com/u/62513924?v=4
username: RizwanMunawar

View File

@ -228,10 +228,9 @@ class ClassificationTrainer(BaseTrainer):
batch (Dict[str, torch.Tensor]): Batch containing images and class labels.
ni (int): Number of iterations.
"""
batch["batch_idx"] = torch.arange(len(batch["img"])) # add batch index for plotting
plot_images(
images=batch["img"],
batch_idx=torch.arange(len(batch["img"])),
cls=batch["cls"].view(-1), # warning: use .view(), not .squeeze() for Classify models
labels=batch,
fname=self.save_dir / f"train_batch{ni}.jpg",
on_plot=self.on_plot,
)