YOLOE: Cleanup duplicate preprocess_batch (#22206)

Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Jing Qiu 2025-09-24 17:49:41 +08:00 committed by GitHub
parent 5ac3f17e7d
commit 473cd2fcaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 14 deletions

View File

@ -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

View File

@ -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):