From 473cd2fcaa9d02885fc765435f51c8d38d626696 Mon Sep 17 00:00:00 2001 From: Jing Qiu <61612323+Laughing-q@users.noreply.github.com> Date: Wed, 24 Sep 2025 17:49:41 +0800 Subject: [PATCH] YOLOE: Cleanup duplicate `preprocess_batch` (#22206) Co-authored-by: UltralyticsAssistant --- ultralytics/models/yolo/world/train.py | 1 - ultralytics/models/yolo/yoloe/train.py | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/ultralytics/models/yolo/world/train.py b/ultralytics/models/yolo/world/train.py index be690ad0..bb6d2f7d 100644 --- a/ultralytics/models/yolo/world/train.py +++ b/ultralytics/models/yolo/world/train.py @@ -175,6 +175,5 @@ class WorldTrainer(DetectionTrainer): txt_feats = torch.stack([self.text_embeddings[text] for text in texts]).to( self.device, non_blocking=self.device.type == "cuda" ) - txt_feats = txt_feats / txt_feats.norm(p=2, dim=-1, keepdim=True) batch["txt_feats"] = txt_feats.reshape(len(batch["texts"]), -1, txt_feats.shape[-1]) return batch diff --git a/ultralytics/models/yolo/yoloe/train.py b/ultralytics/models/yolo/yoloe/train.py index f6fda436..58a3a1ff 100644 --- a/ultralytics/models/yolo/yoloe/train.py +++ b/ultralytics/models/yolo/yoloe/train.py @@ -2,7 +2,6 @@ from __future__ import annotations -import itertools from copy import copy, deepcopy from pathlib import Path @@ -169,7 +168,6 @@ class YOLOETrainerFromScratch(YOLOETrainer, WorldTrainerFromScratch): Methods: build_dataset: Build datasets for training with grounding support. - preprocess_batch: Process batches with text features. generate_text_embeddings: Generate and cache text embeddings for training. """ @@ -190,16 +188,6 @@ class YOLOETrainerFromScratch(YOLOETrainer, WorldTrainerFromScratch): """ return WorldTrainerFromScratch.build_dataset(self, img_path, mode, batch) - def preprocess_batch(self, batch): - """Process batch for training, moving text features to the appropriate device.""" - batch = DetectionTrainer.preprocess_batch(self, batch) - - texts = list(itertools.chain(*batch["texts"])) - txt_feats = torch.stack([self.text_embeddings[text] for text in texts]).to(self.device, non_blocking=True) - txt_feats = txt_feats.reshape(len(batch["texts"]), -1, txt_feats.shape[-1]) - batch["txt_feats"] = txt_feats - return batch - def generate_text_embeddings(self, texts: list[str], batch: int, cache_dir: Path): """ Generate text embeddings for a list of text samples. @@ -280,7 +268,6 @@ class YOLOEVPTrainer(YOLOETrainerFromScratch): Methods: build_dataset: Build dataset with visual prompt loading transforms. - preprocess_batch: Preprocess batches with visual prompts. """ def build_dataset(self, img_path: list[str] | str, mode: str = "train", batch: int | None = None):