ultralytics 8.2.59 use Results.save_txt for validation (#14496)
Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
ebf7dcf5a8
commit
bfcd85323d
7 changed files with 83 additions and 32 deletions
|
|
@ -130,13 +130,19 @@ class OBBValidator(DetectionValidator):
|
|||
|
||||
def save_one_txt(self, predn, save_conf, shape, file):
|
||||
"""Save YOLO detections to a txt file in normalized coordinates in a specific format."""
|
||||
gn = torch.tensor(shape)[[1, 0]] # normalization gain whwh
|
||||
for *xywh, conf, cls, angle in predn.tolist():
|
||||
xywha = torch.tensor([*xywh, angle]).view(1, 5)
|
||||
xyxyxyxy = (ops.xywhr2xyxyxyxy(xywha) / gn).view(-1).tolist() # normalized xywh
|
||||
line = (cls, *xyxyxyxy, conf) if save_conf else (cls, *xyxyxyxy) # label format
|
||||
with open(file, "a") as f:
|
||||
f.write(("%g " * len(line)).rstrip() % line + "\n")
|
||||
import numpy as np
|
||||
|
||||
from ultralytics.engine.results import Results
|
||||
|
||||
rboxes = torch.cat([predn[:, :4], predn[:, -1:]], dim=-1)
|
||||
# xywh, r, conf, cls
|
||||
obb = torch.cat([rboxes, predn[:, 4:6]], dim=-1)
|
||||
Results(
|
||||
np.zeros((shape[0], shape[1]), dtype=np.uint8),
|
||||
path=None,
|
||||
names=self.names,
|
||||
obb=obb,
|
||||
).save_txt(file, save_conf=save_conf)
|
||||
|
||||
def eval_json(self, stats):
|
||||
"""Evaluates YOLO output in JSON format and returns performance statistics."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue