Skip to content

Commit d64bd3d

Browse files
committed
modify the evaluate function in train.py along with the modification of the model inference output
1 parent 3d8adc8 commit d64bd3d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

train.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,18 +487,21 @@ def evaluate(model, data_loader, cfg, device, logger=None, **kwargs):
487487
# outputs = [{k: v.to(cpu_device) for k, v in t.items()} for t in outputs]
488488
model_time = time.time() - model_time
489489

490-
outputs = outputs.cpu().detach().numpy()
490+
# outputs = outputs.cpu().detach().numpy()
491491
res = {}
492-
for img, target, output in zip(images, targets, outputs):
492+
# for img, target, output in zip(images, targets, outputs):
493+
for img, target, (boxes, confs) in zip(images, targets, outputs):
493494
img_height, img_width = img.shape[:2]
494-
boxes = output[...,:4].copy() # output boxes in yolo format
495+
# boxes = output[...,:4].copy() # output boxes in yolo format
496+
boxes = boxes.cpu().detach().numpy()
495497
boxes[...,:2] = boxes[...,:2] - boxes[...,2:]/2 # to coco format
496498
boxes[...,0] = boxes[...,0]*img_width
497499
boxes[...,1] = boxes[...,1]*img_height
498500
boxes[...,2] = boxes[...,2]*img_width
499501
boxes[...,3] = boxes[...,3]*img_height
500502
boxes = torch.as_tensor(boxes, dtype=torch.float32)
501-
confs = output[...,4:].copy()
503+
# confs = output[...,4:].copy()
504+
confs = confs.cpu().detach().numpy()
502505
labels = np.argmax(confs, axis=1).flatten()
503506
labels = torch.as_tensor(labels, dtype=torch.int64)
504507
scores = np.max(confs, axis=1).flatten()

0 commit comments

Comments
 (0)