YOLOE: Cleanup duplicate preprocess_batch (#22206)
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
5ac3f17e7d
commit
473cd2fcaa
@ -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
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user