diff --git a/test.py b/test.py index e6c66ed8..6ac47f4d 100644 --- a/test.py +++ b/test.py @@ -108,10 +108,10 @@ def test( correct.append(0) # Compute Average Precision (AP) per class - AP, AP_class, R, P = ap_per_class(tp=correct, - conf=detections[:, 4], - pred_cls=detections[:, 6], - target_cls=target_cls) + AP, AP_class, R, P = ap_per_class(tp=np.array(correct), + conf=detections[:, 4].cpu().numpy(), + pred_cls=detections[:, 6].cpu().numpy(), + target_cls=target_cls.cpu().numpy()) # Accumulate AP per class AP_accum_count += np.bincount(AP_class, minlength=nC) diff --git a/utils/utils.py b/utils/utils.py index c1a1969a..37bfd8e9 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -92,7 +92,7 @@ def weights_init_normal(m): def xyxy2xywh(x): # Convert bounding box format from [x1, y1, x2, y2] to [x, y, w, h] - y = torch.zeros(x.shape) if x.dtype is torch.float32 else np.zeros(x.shape) + y = torch.zeros_like(x) if x.dtype is torch.float32 else np.zeros_like(x) y[:, 0] = (x[:, 0] + x[:, 2]) / 2 y[:, 1] = (x[:, 1] + x[:, 3]) / 2 y[:, 2] = x[:, 2] - x[:, 0] @@ -102,7 +102,7 @@ def xyxy2xywh(x): def xywh2xyxy(x): # Convert bounding box format from [x, y, w, h] to [x1, y1, x2, y2] - y = torch.zeros(x.shape) if x.dtype is torch.float32 else np.zeros(x.shape) + y = torch.zeros_like(x) if x.dtype is torch.float32 else np.zeros_like(x) y[:, 0] = (x[:, 0] - x[:, 2] / 2) y[:, 1] = (x[:, 1] - x[:, 3] / 2) y[:, 2] = (x[:, 0] + x[:, 2] / 2) @@ -134,9 +134,6 @@ def ap_per_class(tp, conf, pred_cls, target_cls): The average precision as computed in py-faster-rcnn. """ - # lists/pytorch to numpy - tp, conf, pred_cls, target_cls = np.array(tp), np.array(conf), np.array(pred_cls), np.array(target_cls) - # Sort by objectness i = np.argsort(-conf) tp, conf, pred_cls = tp[i], conf[i], pred_cls[i]