Commit
·
b8c2da4
1
Parent(s):
1ce686e
update test.py --save-txt
Browse files
test.py
CHANGED
@@ -18,7 +18,8 @@ def test(data,
|
|
18 |
model=None,
|
19 |
dataloader=None,
|
20 |
save_dir='',
|
21 |
-
merge=False
|
|
|
22 |
# Initialize/load model and set device
|
23 |
training = model is not None
|
24 |
if training: # called by train.py
|
@@ -105,8 +106,14 @@ def test(data,
|
|
105 |
continue
|
106 |
|
107 |
# Append to text file
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
# Clip boxes to image bounds
|
112 |
clip_coords(pred, (height, width))
|
@@ -235,6 +242,7 @@ if __name__ == '__main__':
|
|
235 |
parser.add_argument('--augment', action='store_true', help='augmented inference')
|
236 |
parser.add_argument('--merge', action='store_true', help='use Merge NMS')
|
237 |
parser.add_argument('--verbose', action='store_true', help='report mAP by class')
|
|
|
238 |
opt = parser.parse_args()
|
239 |
opt.save_json |= opt.data.endswith('coco.yaml')
|
240 |
opt.data = check_file(opt.data) # check file
|
|
|
18 |
model=None,
|
19 |
dataloader=None,
|
20 |
save_dir='',
|
21 |
+
merge=False,
|
22 |
+
save_txt=False):
|
23 |
# Initialize/load model and set device
|
24 |
training = model is not None
|
25 |
if training: # called by train.py
|
|
|
106 |
continue
|
107 |
|
108 |
# Append to text file
|
109 |
+
if save_txt:
|
110 |
+
gn = torch.tensor(shapes[si][0])[[1, 0, 1, 0]] # normalization gain whwh
|
111 |
+
txt_path = str(out / Path(paths[si]).stem)
|
112 |
+
pred[:, :4] = scale_coords(img[si].shape[1:], pred[:, :4], shapes[si][0], shapes[si][1]) # to original
|
113 |
+
for *xyxy, conf, cls in pred:
|
114 |
+
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
115 |
+
with open(txt_path + '.txt', 'a') as f:
|
116 |
+
f.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format
|
117 |
|
118 |
# Clip boxes to image bounds
|
119 |
clip_coords(pred, (height, width))
|
|
|
242 |
parser.add_argument('--augment', action='store_true', help='augmented inference')
|
243 |
parser.add_argument('--merge', action='store_true', help='use Merge NMS')
|
244 |
parser.add_argument('--verbose', action='store_true', help='report mAP by class')
|
245 |
+
parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
|
246 |
opt = parser.parse_args()
|
247 |
opt.save_json |= opt.data.endswith('coco.yaml')
|
248 |
opt.data = check_file(opt.data) # check file
|