multi_gpu

This commit is contained in:
Glenn Jocher 2019-03-18 00:48:56 +02:00
parent f5247b397b
commit 7dba5d0171
2 changed files with 6 additions and 9 deletions

View File

@ -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)

View File

@ -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]