From 54e63a8ff0fcb0a2f4c7975e7ef313bbb0112ffc Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Mon, 16 Jun 2025 18:34:25 +0500 Subject: [PATCH] Fix `plot_images` for `classify` training (#21072) Co-authored-by: UltralyticsAssistant Co-authored-by: Laughing-q <1185102784@qq.com> Co-authored-by: Laughing <61612323+Laughing-q@users.noreply.github.com> --- docs/mkdocs_github_authors.yaml | 3 +++ ultralytics/models/yolo/classify/train.py | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/mkdocs_github_authors.yaml b/docs/mkdocs_github_authors.yaml index 5bf58deb..5e0f4272 100644 --- a/docs/mkdocs_github_authors.yaml +++ b/docs/mkdocs_github_authors.yaml @@ -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 diff --git a/ultralytics/models/yolo/classify/train.py b/ultralytics/models/yolo/classify/train.py index 64a2e14b..f1d0dd8f 100644 --- a/ultralytics/models/yolo/classify/train.py +++ b/ultralytics/models/yolo/classify/train.py @@ -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, )