mirror of
https://github.com/ultralytics/yolov5.git
synced 2025-06-03 14:49:29 +08:00
--save-txt bug fix (#763)
This commit is contained in:
parent
ebafd1ead5
commit
da35727c68
8
test.py
8
test.py
@ -128,11 +128,11 @@ def test(data,
|
|||||||
# Append to text file
|
# Append to text file
|
||||||
if save_txt:
|
if save_txt:
|
||||||
gn = torch.tensor(shapes[si][0])[[1, 0, 1, 0]] # normalization gain whwh
|
gn = torch.tensor(shapes[si][0])[[1, 0, 1, 0]] # normalization gain whwh
|
||||||
txt_path = str(out / Path(paths[si]).stem)
|
x = pred.clone()
|
||||||
pred[:, :4] = scale_coords(img[si].shape[1:], pred[:, :4], shapes[si][0], shapes[si][1]) # to original
|
x[:, :4] = scale_coords(img[si].shape[1:], x[:, :4], shapes[si][0], shapes[si][1]) # to original
|
||||||
for *xyxy, conf, cls in pred:
|
for *xyxy, conf, cls in x:
|
||||||
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
||||||
with open(txt_path + '.txt', 'a') as f:
|
with open(str(out / Path(paths[si]).stem) + '.txt', 'a') as f:
|
||||||
f.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format
|
f.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format
|
||||||
|
|
||||||
# Clip boxes to image bounds
|
# Clip boxes to image bounds
|
||||||
|
Loading…
x
Reference in New Issue
Block a user