Warn on save_hybrid=True (#14484)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Glenn Jocher 2024-07-17 17:26:00 +02:00 committed by GitHub
parent 23720db369
commit e866579830
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,6 +41,11 @@ class DetectionValidator(BaseValidator):
self.iouv = torch.linspace(0.5, 0.95, 10) # IoU vector for mAP@0.5:0.95 self.iouv = torch.linspace(0.5, 0.95, 10) # IoU vector for mAP@0.5:0.95
self.niou = self.iouv.numel() self.niou = self.iouv.numel()
self.lb = [] # for autolabelling self.lb = [] # for autolabelling
if self.args.save_hybrid:
LOGGER.warning(
"WARNING ⚠️ 'save_hybrid=True' will append ground truth to predictions for autolabelling.\n"
"WARNING ⚠️ 'save_hybrid=True' will cause incorrect mAP.\n"
)
def preprocess(self, batch): def preprocess(self, batch):
"""Preprocesses batch of images for YOLO training.""" """Preprocesses batch of images for YOLO training."""
@ -53,14 +58,10 @@ class DetectionValidator(BaseValidator):
height, width = batch["img"].shape[2:] height, width = batch["img"].shape[2:]
nb = len(batch["img"]) nb = len(batch["img"])
bboxes = batch["bboxes"] * torch.tensor((width, height, width, height), device=self.device) bboxes = batch["bboxes"] * torch.tensor((width, height, width, height), device=self.device)
self.lb = ( self.lb = [
[ torch.cat([batch["cls"][batch["batch_idx"] == i], bboxes[batch["batch_idx"] == i]], dim=-1)
torch.cat([batch["cls"][batch["batch_idx"] == i], bboxes[batch["batch_idx"] == i]], dim=-1) for i in range(nb)
for i in range(nb) ]
]
if self.args.save_hybrid
else []
) # for autolabelling
return batch return batch